summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2012-01-09 21:22:48 +0000
committertruebrain <truebrain@openttd.org>2012-01-09 21:22:48 +0000
commit6c7c02eb14f31402021b7f5f33173a93e99f0ac3 (patch)
tree52be292b530f4fc17278a8d118fc130eb7c10f2c
parent64605a253ea8c7f4f248ab9f57eaae0b38652df2 (diff)
downloadopenttd-6c7c02eb14f31402021b7f5f33173a93e99f0ac3.tar.xz
(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()
-rw-r--r--src/lang/english.txt6
-rw-r--r--src/network/network.cpp7
-rw-r--r--src/network/network_client.cpp62
-rw-r--r--src/network/network_server.cpp4
-rw-r--r--src/network/network_type.h4
5 files changed, 46 insertions, 37 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 744ffdcbf..91acf2063 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -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
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 */