diff options
author | Patric Stout <truebrain@openttd.org> | 2021-08-17 13:35:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-17 13:35:29 +0200 |
commit | 6acf204d14343e67fdc01ae8c52044d0de20bbd2 (patch) | |
tree | 6fc2fec3880e18963033f1a2ea6adea30d996ef6 | |
parent | b531a0c1cfa454a7e019b7b679d46585bd75839b (diff) | |
download | openttd-6acf204d14343e67fdc01ae8c52044d0de20bbd2.tar.xz |
Fix: report reuse of invite-code and switch to local game-type (#9487)
This prevents two servers battling for the same invite-code. Now
the last one wins.
-rw-r--r-- | src/lang/english.txt | 1 | ||||
-rw-r--r-- | src/network/core/config.h | 2 | ||||
-rw-r--r-- | src/network/core/tcp_coordinator.h | 7 | ||||
-rw-r--r-- | src/network/network_coordinator.cpp | 10 |
4 files changed, 15 insertions, 5 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt index 551fd94cb..360f5637a 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2285,6 +2285,7 @@ STR_NETWORK_MESSAGE_SERVER_REBOOT :{WHITE}The serv STR_NETWORK_MESSAGE_KICKED :*** {RAW_STRING} was kicked. Reason: ({RAW_STRING}) STR_NETWORK_ERROR_COORDINATOR_REGISTRATION_FAILED :{WHITE}Server registration failed +STR_NETWORK_ERROR_COORDINATOR_REUSE_OF_INVITE_CODE :{WHITE}Another server with the same invite-code registered itself. Switching to "local" game-type. STR_NETWORK_ERROR_COORDINATOR_ISOLATED :{WHITE}Your server doesn't allow remote connections STR_NETWORK_ERROR_COORDINATOR_ISOLATED_DETAIL :{WHITE}Other players won't be able to connect to your server diff --git a/src/network/core/config.h b/src/network/core/config.h index 0a6eaa4f7..a7493e817 100644 --- a/src/network/core/config.h +++ b/src/network/core/config.h @@ -50,7 +50,7 @@ static const uint16 COMPAT_MTU = 1460; ///< Numbe static const byte NETWORK_GAME_ADMIN_VERSION = 1; ///< What version of the admin network do we use? static const byte NETWORK_GAME_INFO_VERSION = 6; ///< What version of game-info do we use? static const byte NETWORK_COMPANY_INFO_VERSION = 6; ///< What version of company info is this? -static const byte NETWORK_COORDINATOR_VERSION = 5; ///< What version of game-coordinator-protocol do we use? +static const byte NETWORK_COORDINATOR_VERSION = 6; ///< What version of game-coordinator-protocol do we use? static const uint NETWORK_NAME_LENGTH = 80; ///< The maximum length of the server name and map name, in bytes including '\0' static const uint NETWORK_COMPANY_NAME_LENGTH = 128; ///< The maximum length of the company name, in bytes including '\0' diff --git a/src/network/core/tcp_coordinator.h b/src/network/core/tcp_coordinator.h index dea61cdec..9f2731b7c 100644 --- a/src/network/core/tcp_coordinator.h +++ b/src/network/core/tcp_coordinator.h @@ -61,9 +61,10 @@ enum ConnectionType { * The type of error from the Game Coordinator. */ enum NetworkCoordinatorErrorType { - NETWORK_COORDINATOR_ERROR_UNKNOWN, ///< There was an unknown error. - NETWORK_COORDINATOR_ERROR_REGISTRATION_FAILED, ///< Your request for registration failed. - NETWORK_COORDINATOR_ERROR_INVALID_INVITE_CODE, ///< The invite code given is invalid. + NETWORK_COORDINATOR_ERROR_UNKNOWN, ///< There was an unknown error. + NETWORK_COORDINATOR_ERROR_REGISTRATION_FAILED, ///< Your request for registration failed. + NETWORK_COORDINATOR_ERROR_INVALID_INVITE_CODE, ///< The invite code given is invalid. + NETWORK_COORDINATOR_ERROR_REUSE_OF_INVITE_CODE, ///< The invite code is used by another (newer) server. }; /** Base socket handler for all Game Coordinator TCP sockets. */ diff --git a/src/network/network_coordinator.cpp b/src/network/network_coordinator.cpp index 6456ac9e8..006707c68 100644 --- a/src/network/network_coordinator.cpp +++ b/src/network/network_coordinator.cpp @@ -135,7 +135,6 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_ERROR(Packet *p) return false; case NETWORK_COORDINATOR_ERROR_REGISTRATION_FAILED: - SetDParamStr(0, detail); ShowErrorMessage(STR_NETWORK_ERROR_COORDINATOR_REGISTRATION_FAILED, STR_JUST_RAW_STRING, WL_ERROR); /* To prevent that we constantly try to reconnect, switch to local game. */ @@ -159,6 +158,15 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_ERROR(Packet *p) return true; } + case NETWORK_COORDINATOR_ERROR_REUSE_OF_INVITE_CODE: + ShowErrorMessage(STR_NETWORK_ERROR_COORDINATOR_REUSE_OF_INVITE_CODE, STR_JUST_RAW_STRING, WL_ERROR); + + /* To prevent that we constantly battle for the same invite-code, switch to local game. */ + _settings_client.network.server_game_type = SERVER_GAME_TYPE_LOCAL; + + this->CloseConnection(); + return false; + default: Debug(net, 0, "Invalid error type {} received from Game Coordinator", error); this->CloseConnection(); |