(svn r23780) -Fix [FS#4963] (r23764): also name the two new errors server-side. As extra, split up one of the errors in 3 errors, to be more specific what goes wrong. As cherry on top, make sure on all sides we can never again forget to add such entries on both sides, by introducing an assert_compile()

This commit is contained in:
truebrain 2012-01-09 21:22:48 +00:00
parent 64605a253e
commit 6c7c02eb14
5 changed files with 46 additions and 37 deletions

View File

@ -1801,6 +1801,8 @@ STR_NETWORK_ERROR_CHEATER :{WHITE}Cheating
STR_NETWORK_ERROR_TOO_MANY_COMMANDS :{WHITE}You were sending too many commands to the server
STR_NETWORK_ERROR_TIMEOUT_PASSWORD :{WHITE}You took too long to enter the password
STR_NETWORK_ERROR_TIMEOUT_COMPUTER :{WHITE}Your computer took too long to join
STR_NETWORK_ERROR_TIMEOUT_MAP :{WHITE}You took too long to download the map
STR_NETWORK_ERROR_TIMEOUT_JOIN :{WHITE}You took too long to join the server
############ Leave those lines in this order!!
STR_NETWORK_ERROR_CLIENT_GENERAL :general error
@ -1819,6 +1821,10 @@ STR_NETWORK_ERROR_CLIENT_KICKED :kicked by serve
STR_NETWORK_ERROR_CLIENT_CHEATER :was trying to use a cheat
STR_NETWORK_ERROR_CLIENT_SERVER_FULL :server full
STR_NETWORK_ERROR_CLIENT_TOO_MANY_COMMANDS :was sending too many commands
STR_NETWORK_ERROR_CLIENT_TIMEOUT_PASSWORD :received no password in time
STR_NETWORK_ERROR_CLIENT_TIMEOUT_COMPUTER :general timeout
STR_NETWORK_ERROR_CLIENT_TIMEOUT_MAP :downloading map took too long
STR_NETWORK_ERROR_CLIENT_TIMEOUT_JOIN :processing map took too long
############ End of leave-in-this-order
STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION_CAPTION :{WHITE}Possible connection loss

View File

@ -315,8 +315,13 @@ StringID GetNetworkErrorMsg(NetworkErrorCode err)
STR_NETWORK_ERROR_CLIENT_KICKED,
STR_NETWORK_ERROR_CLIENT_CHEATER,
STR_NETWORK_ERROR_CLIENT_SERVER_FULL,
STR_NETWORK_ERROR_CLIENT_TOO_MANY_COMMANDS
STR_NETWORK_ERROR_CLIENT_TOO_MANY_COMMANDS,
STR_NETWORK_ERROR_CLIENT_TIMEOUT_PASSWORD,
STR_NETWORK_ERROR_CLIENT_TIMEOUT_COMPUTER,
STR_NETWORK_ERROR_CLIENT_TIMEOUT_MAP,
STR_NETWORK_ERROR_CLIENT_TIMEOUT_JOIN,
};
assert_compile(lengthof(network_error_strings) == NETWORK_ERROR_END);
if (err >= (ptrdiff_t)lengthof(network_error_strings)) err = NETWORK_ERROR_GENERAL;

View File

@ -643,42 +643,36 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(Pac
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p)
{
static const StringID network_error_strings[] = {
STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_GENERAL
STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_DESYNC
STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_SAVEGAME_FAILED
STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_CONNECTION_LOST
STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_ILLEGAL_PACKET
STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_NEWGRF_MISMATCH
STR_NETWORK_ERROR_SERVER_ERROR, // NETWORK_ERROR_NOT_AUTHORIZED
STR_NETWORK_ERROR_SERVER_ERROR, // NETWORK_ERROR_NOT_EXPECTED
STR_NETWORK_ERROR_WRONG_REVISION, // NETWORK_ERROR_WRONG_REVISION
STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_NAME_IN_USE
STR_NETWORK_ERROR_WRONG_PASSWORD, // NETWORK_ERROR_WRONG_PASSWORD
STR_NETWORK_ERROR_SERVER_ERROR, // NETWORK_ERROR_COMPANY_MISMATCH
STR_NETWORK_ERROR_KICKED, // NETWORK_ERROR_KICKED
STR_NETWORK_ERROR_CHEATER, // NETWORK_ERROR_CHEATER
STR_NETWORK_ERROR_SERVER_FULL, // NETWORK_ERROR_FULL
STR_NETWORK_ERROR_TOO_MANY_COMMANDS, // NETWORK_ERROR_TOO_MANY_COMMANDS
STR_NETWORK_ERROR_TIMEOUT_PASSWORD, // NETWORK_ERROR_TIMEOUT_PASSWORD
STR_NETWORK_ERROR_TIMEOUT_COMPUTER, // NETWORK_ERROR_TIMEOUT_COMPUTER
STR_NETWORK_ERROR_TIMEOUT_MAP, // NETWORK_ERROR_TIMEOUT_MAP
STR_NETWORK_ERROR_TIMEOUT_JOIN, // NETWORK_ERROR_TIMEOUT_JOIN
};
assert_compile(lengthof(network_error_strings) == NETWORK_ERROR_END);
NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8();
switch (error) {
/* We made an error in the protocol, and our connection is closed.... */
case NETWORK_ERROR_NOT_AUTHORIZED:
case NETWORK_ERROR_NOT_EXPECTED:
case NETWORK_ERROR_COMPANY_MISMATCH:
ShowErrorMessage(STR_NETWORK_ERROR_SERVER_ERROR, INVALID_STRING_ID, WL_CRITICAL);
break;
case NETWORK_ERROR_FULL:
ShowErrorMessage(STR_NETWORK_ERROR_SERVER_FULL, INVALID_STRING_ID, WL_CRITICAL);
break;
case NETWORK_ERROR_WRONG_REVISION:
ShowErrorMessage(STR_NETWORK_ERROR_WRONG_REVISION, INVALID_STRING_ID, WL_CRITICAL);
break;
case NETWORK_ERROR_WRONG_PASSWORD:
ShowErrorMessage(STR_NETWORK_ERROR_WRONG_PASSWORD, INVALID_STRING_ID, WL_CRITICAL);
break;
case NETWORK_ERROR_KICKED:
ShowErrorMessage(STR_NETWORK_ERROR_KICKED, INVALID_STRING_ID, WL_CRITICAL);
break;
case NETWORK_ERROR_CHEATER:
ShowErrorMessage(STR_NETWORK_ERROR_CHEATER, INVALID_STRING_ID, WL_CRITICAL);
break;
case NETWORK_ERROR_TOO_MANY_COMMANDS:
ShowErrorMessage(STR_NETWORK_ERROR_TOO_MANY_COMMANDS, INVALID_STRING_ID, WL_CRITICAL);
break;
case NETWORK_ERROR_TIMEOUT_PASSWORD:
ShowErrorMessage(STR_NETWORK_ERROR_TIMEOUT_PASSWORD, INVALID_STRING_ID, WL_CRITICAL);
break;
case NETWORK_ERROR_TIMEOUT_COMPUTER:
ShowErrorMessage(STR_NETWORK_ERROR_TIMEOUT_COMPUTER, INVALID_STRING_ID, WL_CRITICAL);
break;
default:
ShowErrorMessage(STR_NETWORK_ERROR_LOSTCONNECTION, INVALID_STRING_ID, WL_CRITICAL);
}
StringID err = STR_NETWORK_ERROR_LOSTCONNECTION;
if (error < (ptrdiff_t)lengthof(network_error_strings)) err = network_error_strings[error];
ShowErrorMessage(err, INVALID_STRING_ID, WL_CRITICAL);
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);

View File

@ -1843,7 +1843,7 @@ void NetworkServer_Tick(bool send_frame)
/* Downloading the map... this is the amount of time since starting the saving. */
if (lag > _settings_client.network.max_download_time) {
IConsolePrintF(CC_ERROR, "Client #%d is dropped because it took longer than %d ticks to download the map", cs->client_id, _settings_client.network.max_download_time);
cs->SendError(NETWORK_ERROR_TIMEOUT_COMPUTER);
cs->SendError(NETWORK_ERROR_TIMEOUT_MAP);
continue;
}
break;
@ -1853,7 +1853,7 @@ void NetworkServer_Tick(bool send_frame)
/* The map has been sent, so this is for loading the map and syncing up. */
if (lag > _settings_client.network.max_join_time) {
IConsolePrintF(CC_ERROR, "Client #%d is dropped because it took longer than %d ticks to join", cs->client_id, _settings_client.network.max_join_time);
cs->SendError(NETWORK_ERROR_TIMEOUT_COMPUTER);
cs->SendError(NETWORK_ERROR_TIMEOUT_JOIN);
continue;
}
break;

View File

@ -124,6 +124,10 @@ enum NetworkErrorCode {
NETWORK_ERROR_TOO_MANY_COMMANDS,
NETWORK_ERROR_TIMEOUT_PASSWORD,
NETWORK_ERROR_TIMEOUT_COMPUTER,
NETWORK_ERROR_TIMEOUT_MAP,
NETWORK_ERROR_TIMEOUT_JOIN,
NETWORK_ERROR_END,
};
#endif /* ENABLE_NETWORK */