Use 32bit for server version

This commit is contained in:
Benau 2018-08-03 14:01:36 +08:00
parent 90073bc954
commit 9d78173ec6
6 changed files with 17 additions and 7 deletions

View File

@ -29,7 +29,7 @@
NetworkConfig *NetworkConfig::m_network_config = NULL;
bool NetworkConfig::m_disable_lan = false;
const uint8_t NetworkConfig::m_server_version = 1;
const uint32_t NetworkConfig::m_server_version = 1;
/** \class NetworkConfig
* This class is the interface between STK and the online code, particularly
@ -65,6 +65,7 @@ NetworkConfig::NetworkConfig()
m_server_port = UserConfigParams::m_random_server_port ?
0 : stk_config->m_server_port;
m_team_choosing = false;
m_joined_server_version = 0;
} // NetworkConfig
// ----------------------------------------------------------------------------

View File

@ -121,13 +121,15 @@ private:
NetworkConfig();
uint32_t m_joined_server_version;
public:
/** Stores the command line flag to disable lan detection (i.e. force
* WAN code to be used when connection client and server). */
static bool m_disable_lan;
/** Server version, will be advanced if there are protocol changes. */
static const uint8_t m_server_version;
static const uint32_t m_server_version;
/** Singleton get, which creates this object if necessary. */
static NetworkConfig *get()
@ -330,7 +332,10 @@ public:
void setTeamChoosing(bool val) { m_team_choosing = val; }
// ------------------------------------------------------------------------
bool hasTeamChoosing() const { return m_team_choosing; }
// ------------------------------------------------------------------------
void setJoinedServerVersion(uint32_t v) { m_joined_server_version = v; }
// ------------------------------------------------------------------------
uint32_t getJoinedServerVersion() const { return m_joined_server_version; }
}; // class NetworkConfig
#endif // HEADER_NETWORK_CONFIG

View File

@ -267,7 +267,7 @@ void ClientLobby::update(int ticks)
{
NetworkString* ns = getNetworkString();
ns->addUInt8(LE_CONNECTION_REQUESTED)
.addUInt8(NetworkConfig::m_server_version);
.addUInt32(NetworkConfig::m_server_version);
auto all_k = kart_properties_manager->getAllAvailableKarts();
auto all_t = track_manager->getAllTrackIdentifiers();
@ -491,6 +491,9 @@ void ClientLobby::connectionAccepted(Event* event)
Log::info("ClientLobby", "The server accepted the connection.");
STKHost::get()->setMyHostId(data.getUInt32());
assert(!NetworkConfig::get()->isAddingNetworkPlayers());
uint32_t server_version = data.getUInt32();
NetworkConfig::get()->setJoinedServerVersion(server_version);
assert(server_version != 0);
m_state.store(CONNECTED);
float auto_start_timer = data.getFloat();
if (auto_start_timer != std::numeric_limits<float>::max())

View File

@ -1273,7 +1273,7 @@ void ServerLobby::connectionRequested(Event* event)
}
// Check server version
int version = data.getUInt8();
int version = data.getUInt32();
if (version < stk_config->m_min_server_version ||
version > stk_config->m_max_server_version)
{
@ -1481,6 +1481,7 @@ void ServerLobby::handleUnencryptedConnection(std::shared_ptr<STKPeer> peer,
// connection success -- return the host id of peer
float auto_start_timer = m_timeout.load();
message_ack->addUInt8(LE_CONNECTION_ACCEPTED).addUInt32(peer->getHostId())
.addUInt32(NetworkConfig::m_server_version)
.addFloat(auto_start_timer == std::numeric_limits<float>::max() ?
auto_start_timer : auto_start_timer - (float)StkTime::getRealTime());
peer->sendPacket(message_ack);

View File

@ -176,7 +176,7 @@ Online::XMLRequest* ServersManager::getLANRefreshRequest() const
if (len > 0)
{
BareNetworkString s(buffer, len);
int version = s.getUInt8();
int version = s.getUInt32();
if (version < stk_config->m_max_server_version ||
version > stk_config->m_max_server_version)
{

View File

@ -993,7 +993,7 @@ void STKHost::handleDirectSocketRequest(Network* direct_socket,
// Send the answer, consisting of server name, max players,
// current players
BareNetworkString s((int)name.size()+1+11);
s.addUInt8(NetworkConfig::m_server_version);
s.addUInt32(NetworkConfig::m_server_version);
s.encodeString(name);
s.addUInt8(NetworkConfig::get()->getMaxPlayers());
s.addUInt8((uint8_t)sl->getGameSetup()->getPlayerCount());