Add network capabilities to handle same server version changes

This commit is contained in:
Benau 2019-03-09 15:14:13 +08:00
parent cb8525492a
commit 4c2fe75cb4
5 changed files with 55 additions and 2 deletions

View File

@ -67,6 +67,7 @@ NetworkConfig::NetworkConfig()
*/
void NetworkConfig::unsetNetworking()
{
clearServerCapabilities();
m_network_type = NETWORK_NONE;
ServerConfig::m_private_server_password = "";
} // unsetNetworking

View File

@ -93,6 +93,10 @@ private:
/** Set by client or server which is required to be the same. */
int m_state_frequency;
/** List of server capabilities set when joining it, to determine features
* available in same version. */
std::vector<std::string> m_server_capabilities;
public:
/** Singleton get, which creates this object if necessary. */
static NetworkConfig *get()
@ -231,6 +235,15 @@ public:
int getStateFrequency() const { return m_state_frequency; }
// ------------------------------------------------------------------------
bool roundValuesNow() const;
// ------------------------------------------------------------------------
void setServerCapabilities(std::vector<std::string>& caps)
{ m_server_capabilities = std::move(caps); }
// ------------------------------------------------------------------------
void clearServerCapabilities() { m_server_capabilities.clear(); }
// ------------------------------------------------------------------------
const std::vector<std::string>& getServerCapabilities() const
{ return m_server_capabilities; }
}; // class NetworkConfig
#endif // HEADER_NETWORK_CONFIG

View File

@ -332,10 +332,13 @@ void ClientLobby::update(int ticks)
break;
case LINKED:
{
NetworkConfig::get()->clearServerCapabilities();
NetworkString* ns = getNetworkString();
ns->addUInt8(LE_CONNECTION_REQUESTED)
.addUInt32(ServerConfig::m_server_version)
.encodeString(StringUtils::getUserAgentString());
.encodeString(StringUtils::getUserAgentString())
// Reserved for future to supply list of network capabilities
.addUInt16(0);
auto all_k = kart_properties_manager->getAllAvailableKarts();
auto all_t = track_manager->getAllTrackIdentifiers();
@ -578,6 +581,17 @@ void ClientLobby::connectionAccepted(Event* event)
assert(server_version != 0);
m_auto_started = false;
m_state.store(CONNECTED);
unsigned list_caps = data.getUInt16();
std::vector<std::string> caps;
for (unsigned i = 0; i < list_caps; i++)
{
std::string cap;
data.decodeString(&cap);
caps.push_back(cap);
}
NetworkConfig::get()->setServerCapabilities(caps);
float auto_start_timer = data.getFloat();
int state_frequency_in_server = data.getUInt32();
NetworkConfig::get()->setStateFrequency(state_frequency_in_server);

View File

@ -2011,6 +2011,16 @@ void ServerLobby::connectionRequested(Event* event)
data.decodeString(&user_version);
event->getPeer()->setUserVersion(user_version);
unsigned list_caps = data.getUInt16();
std::vector<std::string> caps;
for (unsigned i = 0; i < list_caps; i++)
{
std::string cap;
data.decodeString(&cap);
caps.push_back(cap);
}
event->getPeer()->setClientCapabilities(caps);
std::set<std::string> client_karts, client_tracks;
const unsigned kart_num = data.getUInt16();
const unsigned track_num = data.getUInt16();
@ -2267,7 +2277,12 @@ void ServerLobby::handleUnencryptedConnection(std::shared_ptr<STKPeer> peer,
(m_timeout.load() - (int64_t)StkTime::getRealTimeMs()) / 1000.0f;
}
message_ack->addUInt8(LE_CONNECTION_ACCEPTED).addUInt32(peer->getHostId())
.addUInt32(ServerConfig::m_server_version).addFloat(auto_start_timer)
.addUInt32(ServerConfig::m_server_version);
// Reserved for future to supply list of network capabilities
message_ack->addUInt16(0);
message_ack->addFloat(auto_start_timer)
.addUInt32(ServerConfig::m_state_frequency);
peer->setSpectator(false);

View File

@ -100,6 +100,10 @@ protected:
std::string m_user_version;
/** List of client capabilities set when connecting it, to determine
* features available in same version. */
std::vector<std::string> m_client_capabilities;
public:
STKPeer(ENetPeer *enet_peer, STKHost* host, uint32_t host_id);
// ------------------------------------------------------------------------
@ -231,6 +235,12 @@ public:
return 0;
return (int)(diff / 1000);
}
// ------------------------------------------------------------------------
void setClientCapabilities(std::vector<std::string>& caps)
{ m_client_capabilities = std::move(caps); }
// ------------------------------------------------------------------------
const std::vector<std::string>& getClientCapabilities() const
{ return m_client_capabilities; }
}; // STKPeer
#endif // STK_PEER_HPP