Check server version again in connection request (for connect-now)

This commit is contained in:
Benau 2018-04-16 11:57:45 +08:00
parent a7deff5c3e
commit 12e4ba0f18
6 changed files with 39 additions and 4 deletions

View File

@ -9,6 +9,10 @@
Older versions will be ignored. -->
<track-version min="6" max="7"/>
<!-- Minimum and maxium server versions that be be read by this binary.
Older versions will be ignored. -->
<server-version min="1" max="1"/>
<!-- Maximum number of karts to be used at the same time. This limit
can easily be increased, but some tracks might not have valid start
positions for those additional karts. -->

View File

@ -141,6 +141,8 @@ void STKConfig::load(const std::string &filename)
CHECK_NEG(m_max_kart_version, "<kart-version max=...>" );
CHECK_NEG(m_min_track_version, "min-track-version" );
CHECK_NEG(m_max_track_version, "max-track-version" );
CHECK_NEG(m_min_server_version, "min-server-version" );
CHECK_NEG(m_max_server_version, "max-server-version" );
CHECK_NEG(m_skid_fadeout_time, "skid-fadeout-time" );
CHECK_NEG(m_near_ground, "near-ground" );
CHECK_NEG(m_delay_finish_time, "delay-finish-time" );
@ -187,6 +189,8 @@ void STKConfig::init_defaults()
m_max_kart_version = -100;
m_min_track_version = -100;
m_max_track_version = -100;
m_min_server_version = -100;
m_max_server_version = -100;
m_max_display_news = -100;
m_replay_max_time = -100;
m_replay_delta_angle = -100;
@ -233,6 +237,12 @@ void STKConfig::getAllData(const XMLNode * root)
node->get("max", &m_max_track_version);
}
if(const XMLNode *node = root->getNode("server-version"))
{
node->get("min", &m_min_server_version);
node->get("max", &m_max_server_version);
}
if(const XMLNode *kart_node = root->getNode("karts"))
kart_node->get("max-number", &m_max_karts);

View File

@ -117,6 +117,8 @@ public:
m_max_kart_version; /**<version supported by this binary. */
int m_min_track_version, /**<The minimum and maximum .track file */
m_max_track_version; /**<version supported by this binary. */
int m_min_server_version, /**<The minimum and maximum server */
m_max_server_version; /**<version supported by this binary. */
int m_max_display_news; /**<How often a news message is displayed
before it is ignored. */

View File

@ -260,6 +260,7 @@ void ClientLobby::update(int ticks)
{
NetworkString *ns = getNetworkString();
ns->addUInt8(LE_CONNECTION_REQUESTED)
.addUInt8(NetworkConfig::m_server_version)
.encodeString(NetworkConfig::get()->getPassword());
assert(!NetworkConfig::get()->isAddingNetworkPlayers());

View File

@ -772,6 +772,21 @@ void ServerLobby::connectionRequested(Event* event)
return;
}
// Check server version
int version = data.getUInt8();
if (version < stk_config->m_max_server_version ||
version > stk_config->m_max_server_version)
{
NetworkString *message = getNetworkString(2);
message->addUInt8(LE_CONNECTION_REFUSED)
.addUInt8(RR_INCOMPATIBLE_DATA);
peer->sendPacket(message);
peer->reset();
delete message;
Log::verbose("ServerLobby", "Player refused: wrong server version");
return;
}
// Check for password
std::string password;
data.decodeString(&password);

View File

@ -18,6 +18,7 @@
#include "network/servers_manager.hpp"
#include "config/stk_config.hpp"
#include "config/user_config.hpp"
#include "network/network.hpp"
#include "network/network_config.hpp"
@ -160,8 +161,9 @@ Online::XMLRequest* ServersManager::getLANRefreshRequest() const
if (len > 0)
{
BareNetworkString s(buffer, len);
uint8_t version = s.getUInt8();
if (version != NetworkConfig::m_server_version)
int version = s.getUInt8();
if (version < stk_config->m_max_server_version ||
version > stk_config->m_max_server_version)
{
Log::verbose("ServersManager", "Skipping a server");
continue;
@ -236,10 +238,11 @@ void ServersManager::setWanServers(bool success, const XMLNode* input)
const XMLNode *servers_xml = input->getNode("servers");
for (unsigned int i = 0; i < servers_xml->getNumNodes(); i++)
{
unsigned version = 0;
int version = 0;
servers_xml->getNode(i)->get("version", &version);
assert(version != 0);
if (version != NetworkConfig::m_server_version)
if (version < stk_config->m_max_server_version ||
version > stk_config->m_max_server_version)
{
Log::verbose("ServersManager", "Skipping a server");
continue;