diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/network.cpp | 7 | ||||
-rw-r--r-- | src/network/network_client.cpp | 62 | ||||
-rw-r--r-- | src/network/network_server.cpp | 4 | ||||
-rw-r--r-- | src/network/network_type.h | 4 |
4 files changed, 40 insertions, 37 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp index 14453d70f..41af3d1df 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -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; diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 3a0f58b83..fd5ff79ec 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -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); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 72ad4bf3e..dbbe8fe28 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -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; diff --git a/src/network/network_type.h b/src/network/network_type.h index eff46a232..3c390c29b 100644 --- a/src/network/network_type.h +++ b/src/network/network_type.h @@ -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 */ |