Changeset - r25900:32e1999c65c7
[Not reviewed]
master
0 4 0
Patric Stout - 3 years ago 2021-08-17 11:35:29
truebrain@openttd.org
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.
4 files changed with 15 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -2282,12 +2282,13 @@ STR_NETWORK_MESSAGE_NAME_CHANGE         
 
STR_NETWORK_MESSAGE_GIVE_MONEY                                  :*** {RAW_STRING} gave {2:CURRENCY_LONG} to {1:RAW_STRING}
 
STR_NETWORK_MESSAGE_SERVER_SHUTDOWN                             :{WHITE}The server closed the session
 
STR_NETWORK_MESSAGE_SERVER_REBOOT                               :{WHITE}The server is restarting...{}Please wait...
 
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
 

	
 
# Content downloading window
 
STR_CONTENT_TITLE                                               :{WHITE}Content downloading
 
STR_CONTENT_TYPE_CAPTION                                        :{BLACK}Type
src/network/core/config.h
Show inline comments
 
@@ -47,13 +47,13 @@ static const uint16 UDP_MTU             
 
static const uint16 TCP_MTU                         = 32767;          ///< Number of bytes we can pack in a single TCP packet
 
static const uint16 COMPAT_MTU                      = 1460;           ///< Number of bytes we can pack in a single packet for backward compatibility
 

	
 
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'
 
static const uint NETWORK_HOSTNAME_LENGTH           =   80;           ///< The maximum length of the host name, in bytes including '\0'
 
static const uint NETWORK_HOSTNAME_PORT_LENGTH      =   80 + 6;       ///< The maximum length of the host name + port, in bytes including '\0'. The extra six is ":" + port number (with a max of 65536)
 
static const uint NETWORK_SERVER_ID_LENGTH          =   33;           ///< The maximum length of the network id of the servers, in bytes including '\0'
src/network/core/tcp_coordinator.h
Show inline comments
 
@@ -58,15 +58,16 @@ 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. */
 
class NetworkCoordinatorSocketHandler : public NetworkTCPSocketHandler {
 
protected:
 
	bool ReceiveInvalidPacket(PacketCoordinatorType type);
src/network/network_coordinator.cpp
Show inline comments
 
@@ -132,13 +132,12 @@ bool ClientNetworkCoordinatorSocketHandl
 
	switch (error) {
 
		case NETWORK_COORDINATOR_ERROR_UNKNOWN:
 
			this->CloseConnection();
 
			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. */
 
			_settings_client.network.server_game_type = SERVER_GAME_TYPE_LOCAL;
 

	
 
			this->CloseConnection();
 
@@ -156,12 +155,21 @@ bool ClientNetworkCoordinatorSocketHandl
 
			item->online = false;
 

	
 
			UpdateNetworkGameWindow();
 
			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();
 
			return false;
 
	}
 
}
0 comments (0 inline, 0 general)