mirror of https://github.com/OpenTTD/OpenTTD
Fix: [Network] show query errors in the server listing instead of error popup (#9506)
When you are query several servers at once, it is rather unclear for which server you got a popup. Instead, show any errors on the server itself. This is only true for the query-part. Joining a server still gives an error popup to tell you about any issue.pull/9514/head
parent
e31b5d3870
commit
dc5b7b996c
|
@ -2046,6 +2046,8 @@ STR_NETWORK_SERVER_LIST_GAMESCRIPT :{SILVER}Game Sc
|
||||||
STR_NETWORK_SERVER_LIST_PASSWORD :{SILVER}Password protected!
|
STR_NETWORK_SERVER_LIST_PASSWORD :{SILVER}Password protected!
|
||||||
STR_NETWORK_SERVER_LIST_SERVER_OFFLINE :{SILVER}SERVER OFFLINE
|
STR_NETWORK_SERVER_LIST_SERVER_OFFLINE :{SILVER}SERVER OFFLINE
|
||||||
STR_NETWORK_SERVER_LIST_SERVER_FULL :{SILVER}SERVER FULL
|
STR_NETWORK_SERVER_LIST_SERVER_FULL :{SILVER}SERVER FULL
|
||||||
|
STR_NETWORK_SERVER_LIST_SERVER_BANNED :{SILVER}SERVER BANNED YOU
|
||||||
|
STR_NETWORK_SERVER_LIST_SERVER_TOO_OLD :{SILVER}SERVER TOO OLD
|
||||||
STR_NETWORK_SERVER_LIST_VERSION_MISMATCH :{SILVER}VERSION MISMATCH
|
STR_NETWORK_SERVER_LIST_VERSION_MISMATCH :{SILVER}VERSION MISMATCH
|
||||||
STR_NETWORK_SERVER_LIST_GRF_MISMATCH :{SILVER}NEWGRF MISMATCH
|
STR_NETWORK_SERVER_LIST_GRF_MISMATCH :{SILVER}NEWGRF MISMATCH
|
||||||
|
|
||||||
|
@ -2226,7 +2228,6 @@ STR_NETWORK_ERROR_TIMEOUT_COMPUTER :{WHITE}Your com
|
||||||
STR_NETWORK_ERROR_TIMEOUT_MAP :{WHITE}Your computer took too long to download the map
|
STR_NETWORK_ERROR_TIMEOUT_MAP :{WHITE}Your computer took too long to download the map
|
||||||
STR_NETWORK_ERROR_TIMEOUT_JOIN :{WHITE}Your computer took too long to join the server
|
STR_NETWORK_ERROR_TIMEOUT_JOIN :{WHITE}Your computer took too long to join the server
|
||||||
STR_NETWORK_ERROR_INVALID_CLIENT_NAME :{WHITE}Your player name is not valid
|
STR_NETWORK_ERROR_INVALID_CLIENT_NAME :{WHITE}Your player name is not valid
|
||||||
STR_NETWORK_ERROR_SERVER_TOO_OLD :{WHITE}The queried server is too old for this client
|
|
||||||
|
|
||||||
############ Leave those lines in this order!!
|
############ Leave those lines in this order!!
|
||||||
STR_NETWORK_ERROR_CLIENT_GENERAL :general error
|
STR_NETWORK_ERROR_CLIENT_GENERAL :general error
|
||||||
|
|
|
@ -632,7 +632,7 @@ public:
|
||||||
void OnFailure() override
|
void OnFailure() override
|
||||||
{
|
{
|
||||||
NetworkGameList *item = NetworkGameListAddItem(connection_string);
|
NetworkGameList *item = NetworkGameListAddItem(connection_string);
|
||||||
item->online = false;
|
item->status = NGLS_OFFLINE;
|
||||||
|
|
||||||
UpdateNetworkGameWindow();
|
UpdateNetworkGameWindow();
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_ERROR(Packet *p)
|
||||||
|
|
||||||
/* Mark the server as offline. */
|
/* Mark the server as offline. */
|
||||||
NetworkGameList *item = NetworkGameListAddItem(detail);
|
NetworkGameList *item = NetworkGameListAddItem(detail);
|
||||||
item->online = false;
|
item->status = NGLS_OFFLINE;
|
||||||
|
|
||||||
UpdateNetworkGameWindow();
|
UpdateNetworkGameWindow();
|
||||||
return true;
|
return true;
|
||||||
|
@ -257,7 +257,7 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_LISTING(Packet *p)
|
||||||
/* Check for compatability with the client. */
|
/* Check for compatability with the client. */
|
||||||
CheckGameCompatibility(item->info);
|
CheckGameCompatibility(item->info);
|
||||||
/* Mark server as online. */
|
/* Mark server as online. */
|
||||||
item->online = true;
|
item->status = NGLS_ONLINE;
|
||||||
/* Mark the item as up-to-date. */
|
/* Mark the item as up-to-date. */
|
||||||
item->version = _network_game_list_version;
|
item->version = _network_game_list_version;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,17 +14,26 @@
|
||||||
#include "core/game_info.h"
|
#include "core/game_info.h"
|
||||||
#include "network_type.h"
|
#include "network_type.h"
|
||||||
|
|
||||||
|
/** The status a server can be in. */
|
||||||
|
enum NetworkGameListStatus {
|
||||||
|
NGLS_OFFLINE, ///< Server is offline (or cannot be queried).
|
||||||
|
NGLS_ONLINE, ///< Server is online.
|
||||||
|
NGLS_FULL, ///< Server is full and cannot be queried.
|
||||||
|
NGLS_BANNED, ///< You are banned from this server.
|
||||||
|
NGLS_TOO_OLD, ///< Server is too old to query.
|
||||||
|
};
|
||||||
|
|
||||||
/** Structure with information shown in the game list (GUI) */
|
/** Structure with information shown in the game list (GUI) */
|
||||||
struct NetworkGameList {
|
struct NetworkGameList {
|
||||||
NetworkGameList(const std::string &connection_string) : connection_string(connection_string) {}
|
NetworkGameList(const std::string &connection_string) : connection_string(connection_string) {}
|
||||||
|
|
||||||
NetworkGameInfo info = {}; ///< The game information of this server
|
NetworkGameInfo info = {}; ///< The game information of this server.
|
||||||
std::string connection_string; ///< Address of the server
|
std::string connection_string; ///< Address of the server.
|
||||||
bool online = false; ///< False if the server did not respond (default status)
|
NetworkGameListStatus status = NGLS_OFFLINE; ///< Stats of the server.
|
||||||
bool manually = false; ///< True if the server was added manually
|
bool manually = false; ///< True if the server was added manually.
|
||||||
uint8 retries = 0; ///< Number of retries (to stop requerying)
|
uint8 retries = 0; ///< Number of retries (to stop requerying).
|
||||||
int version = 0; ///< Used to see which servers are no longer available on the Game Coordinator and can be removed.
|
int version = 0; ///< Used to see which servers are no longer available on the Game Coordinator and can be removed.
|
||||||
NetworkGameList *next = nullptr; ///< Next pointer to make a linked game list
|
NetworkGameList *next = nullptr; ///< Next pointer to make a linked game list.
|
||||||
};
|
};
|
||||||
|
|
||||||
extern NetworkGameList *_network_game_list;
|
extern NetworkGameList *_network_game_list;
|
||||||
|
|
|
@ -407,7 +407,7 @@ protected:
|
||||||
DrawString(nwi_name->pos_x + WD_FRAMERECT_LEFT, nwi_name->pos_x + nwi_name->current_x - WD_FRAMERECT_RIGHT, y + text_y_offset, cur_item->info.server_name, TC_BLACK);
|
DrawString(nwi_name->pos_x + WD_FRAMERECT_LEFT, nwi_name->pos_x + nwi_name->current_x - WD_FRAMERECT_RIGHT, y + text_y_offset, cur_item->info.server_name, TC_BLACK);
|
||||||
|
|
||||||
/* only draw details if the server is online */
|
/* only draw details if the server is online */
|
||||||
if (cur_item->online) {
|
if (cur_item->status == NGLS_ONLINE) {
|
||||||
const NWidgetServerListHeader *nwi_header = this->GetWidget<NWidgetServerListHeader>(WID_NG_HEADER);
|
const NWidgetServerListHeader *nwi_header = this->GetWidget<NWidgetServerListHeader>(WID_NG_HEADER);
|
||||||
|
|
||||||
if (nwi_header->IsWidgetVisible(WID_NG_CLIENTS)) {
|
if (nwi_header->IsWidgetVisible(WID_NG_CLIENTS)) {
|
||||||
|
@ -609,13 +609,13 @@ public:
|
||||||
this->SetWidgetDisabledState(WID_NG_REFRESH, sel == nullptr);
|
this->SetWidgetDisabledState(WID_NG_REFRESH, sel == nullptr);
|
||||||
/* 'Join' button disabling conditions */
|
/* 'Join' button disabling conditions */
|
||||||
this->SetWidgetDisabledState(WID_NG_JOIN, sel == nullptr || // no Selected Server
|
this->SetWidgetDisabledState(WID_NG_JOIN, sel == nullptr || // no Selected Server
|
||||||
!sel->online || // Server offline
|
sel->status != NGLS_ONLINE || // Server offline
|
||||||
sel->info.clients_on >= sel->info.clients_max || // Server full
|
sel->info.clients_on >= sel->info.clients_max || // Server full
|
||||||
!sel->info.compatible); // Revision mismatch
|
!sel->info.compatible); // Revision mismatch
|
||||||
|
|
||||||
/* 'NewGRF Settings' button invisible if no NewGRF is used */
|
/* 'NewGRF Settings' button invisible if no NewGRF is used */
|
||||||
this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_SEL)->SetDisplayedPlane(sel == nullptr || !sel->online || sel->info.grfconfig == nullptr);
|
this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NGLS_ONLINE || sel->info.grfconfig == nullptr);
|
||||||
this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_MISSING_SEL)->SetDisplayedPlane(sel == nullptr || !sel->online || sel->info.grfconfig == nullptr || !sel->info.version_compatible || sel->info.compatible);
|
this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_MISSING_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NGLS_ONLINE || sel->info.grfconfig == nullptr || !sel->info.version_compatible || sel->info.compatible);
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
this->SetWidgetDisabledState(WID_NG_SEARCH_INTERNET, true);
|
this->SetWidgetDisabledState(WID_NG_SEARCH_INTERNET, true);
|
||||||
|
@ -637,10 +637,20 @@ public:
|
||||||
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.top + detail_height - 1, PC_DARK_BLUE);
|
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.top + detail_height - 1, PC_DARK_BLUE);
|
||||||
if (sel == nullptr) {
|
if (sel == nullptr) {
|
||||||
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, STR_NETWORK_SERVER_LIST_GAME_INFO, TC_FROMSTRING, SA_HOR_CENTER);
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, STR_NETWORK_SERVER_LIST_GAME_INFO, TC_FROMSTRING, SA_HOR_CENTER);
|
||||||
} else if (!sel->online) {
|
} else if (sel->status != NGLS_ONLINE) {
|
||||||
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, sel->info.server_name, TC_ORANGE, SA_HOR_CENTER); // game name
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, sel->info.server_name, TC_ORANGE, SA_HOR_CENTER); // game name
|
||||||
|
|
||||||
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + detail_height + 4, STR_NETWORK_SERVER_LIST_SERVER_OFFLINE, TC_FROMSTRING, SA_HOR_CENTER); // server offline
|
StringID message = INVALID_STRING_ID;
|
||||||
|
switch (sel->status) {
|
||||||
|
case NGLS_OFFLINE: message = STR_NETWORK_SERVER_LIST_SERVER_OFFLINE; break;
|
||||||
|
case NGLS_FULL: message = STR_NETWORK_SERVER_LIST_SERVER_FULL; break;
|
||||||
|
case NGLS_BANNED: message = STR_NETWORK_SERVER_LIST_SERVER_BANNED; break;
|
||||||
|
case NGLS_TOO_OLD: message = STR_NETWORK_SERVER_LIST_SERVER_TOO_OLD; break;
|
||||||
|
|
||||||
|
/* Handled by the if-case above. */
|
||||||
|
case NGLS_ONLINE: NOT_REACHED();
|
||||||
|
}
|
||||||
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + detail_height + 4, message, TC_FROMSTRING, SA_HOR_CENTER); // server offline
|
||||||
} else { // show game info
|
} else { // show game info
|
||||||
|
|
||||||
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6, STR_NETWORK_SERVER_LIST_GAME_INFO, TC_FROMSTRING, SA_HOR_CENTER);
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6, STR_NETWORK_SERVER_LIST_GAME_INFO, TC_FROMSTRING, SA_HOR_CENTER);
|
||||||
|
|
|
@ -77,16 +77,22 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::SendGameInfo()
|
||||||
|
|
||||||
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p)
|
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p)
|
||||||
{
|
{
|
||||||
/* We try to join a server which is full */
|
NetworkGameList *item = NetworkGameListAddItem(this->connection_string);
|
||||||
ShowErrorMessage(STR_NETWORK_ERROR_SERVER_FULL, INVALID_STRING_ID, WL_CRITICAL);
|
item->status = NGLS_FULL;
|
||||||
return NETWORK_RECV_STATUS_SERVER_FULL;
|
|
||||||
|
UpdateNetworkGameWindow();
|
||||||
|
|
||||||
|
return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *p)
|
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *p)
|
||||||
{
|
{
|
||||||
/* We try to join a server where we are banned */
|
NetworkGameList *item = NetworkGameListAddItem(this->connection_string);
|
||||||
ShowErrorMessage(STR_NETWORK_ERROR_SERVER_BANNED, INVALID_STRING_ID, WL_CRITICAL);
|
item->status = NGLS_BANNED;
|
||||||
return NETWORK_RECV_STATUS_SERVER_BANNED;
|
|
||||||
|
UpdateNetworkGameWindow();
|
||||||
|
|
||||||
|
return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet *p)
|
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet *p)
|
||||||
|
@ -100,7 +106,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet
|
||||||
/* Check for compatability with the client. */
|
/* Check for compatability with the client. */
|
||||||
CheckGameCompatibility(item->info);
|
CheckGameCompatibility(item->info);
|
||||||
/* Ensure we consider the server online. */
|
/* Ensure we consider the server online. */
|
||||||
item->online = true;
|
item->status = NGLS_ONLINE;
|
||||||
|
|
||||||
UpdateNetworkGameWindow();
|
UpdateNetworkGameWindow();
|
||||||
|
|
||||||
|
@ -111,17 +117,21 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p)
|
||||||
{
|
{
|
||||||
NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8();
|
NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8();
|
||||||
|
|
||||||
/* If we query a server that is 1.11.1 or older, we get an
|
NetworkGameList *item = NetworkGameListAddItem(this->connection_string);
|
||||||
* NETWORK_ERROR_NOT_EXPECTED on requesting the game info. Show a special
|
|
||||||
* error popup in that case.
|
|
||||||
*/
|
|
||||||
if (error == NETWORK_ERROR_NOT_EXPECTED) {
|
if (error == NETWORK_ERROR_NOT_EXPECTED) {
|
||||||
ShowErrorMessage(STR_NETWORK_ERROR_SERVER_TOO_OLD, INVALID_STRING_ID, WL_CRITICAL);
|
/* If we query a server that is 1.11.1 or older, we get an
|
||||||
return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
* NETWORK_ERROR_NOT_EXPECTED on requesting the game info. Show to the
|
||||||
|
* user this server is too old to query.
|
||||||
|
*/
|
||||||
|
item->status = NGLS_TOO_OLD;
|
||||||
|
} else {
|
||||||
|
item->status = NGLS_OFFLINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowErrorMessage(STR_NETWORK_ERROR_LOSTCONNECTION, INVALID_STRING_ID, WL_CRITICAL);
|
UpdateNetworkGameWindow();
|
||||||
return NETWORK_RECV_STATUS_SERVER_ERROR;
|
|
||||||
|
return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue