Add network capabilities to handle same server version changes
This commit is contained in:
parent
cb8525492a
commit
4c2fe75cb4
@ -67,6 +67,7 @@ NetworkConfig::NetworkConfig()
|
|||||||
*/
|
*/
|
||||||
void NetworkConfig::unsetNetworking()
|
void NetworkConfig::unsetNetworking()
|
||||||
{
|
{
|
||||||
|
clearServerCapabilities();
|
||||||
m_network_type = NETWORK_NONE;
|
m_network_type = NETWORK_NONE;
|
||||||
ServerConfig::m_private_server_password = "";
|
ServerConfig::m_private_server_password = "";
|
||||||
} // unsetNetworking
|
} // unsetNetworking
|
||||||
|
@ -93,6 +93,10 @@ private:
|
|||||||
/** Set by client or server which is required to be the same. */
|
/** Set by client or server which is required to be the same. */
|
||||||
int m_state_frequency;
|
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:
|
public:
|
||||||
/** Singleton get, which creates this object if necessary. */
|
/** Singleton get, which creates this object if necessary. */
|
||||||
static NetworkConfig *get()
|
static NetworkConfig *get()
|
||||||
@ -231,6 +235,15 @@ public:
|
|||||||
int getStateFrequency() const { return m_state_frequency; }
|
int getStateFrequency() const { return m_state_frequency; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
bool roundValuesNow() const;
|
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
|
}; // class NetworkConfig
|
||||||
|
|
||||||
#endif // HEADER_NETWORK_CONFIG
|
#endif // HEADER_NETWORK_CONFIG
|
||||||
|
@ -332,10 +332,13 @@ void ClientLobby::update(int ticks)
|
|||||||
break;
|
break;
|
||||||
case LINKED:
|
case LINKED:
|
||||||
{
|
{
|
||||||
|
NetworkConfig::get()->clearServerCapabilities();
|
||||||
NetworkString* ns = getNetworkString();
|
NetworkString* ns = getNetworkString();
|
||||||
ns->addUInt8(LE_CONNECTION_REQUESTED)
|
ns->addUInt8(LE_CONNECTION_REQUESTED)
|
||||||
.addUInt32(ServerConfig::m_server_version)
|
.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_k = kart_properties_manager->getAllAvailableKarts();
|
||||||
auto all_t = track_manager->getAllTrackIdentifiers();
|
auto all_t = track_manager->getAllTrackIdentifiers();
|
||||||
@ -578,6 +581,17 @@ void ClientLobby::connectionAccepted(Event* event)
|
|||||||
assert(server_version != 0);
|
assert(server_version != 0);
|
||||||
m_auto_started = false;
|
m_auto_started = false;
|
||||||
m_state.store(CONNECTED);
|
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();
|
float auto_start_timer = data.getFloat();
|
||||||
int state_frequency_in_server = data.getUInt32();
|
int state_frequency_in_server = data.getUInt32();
|
||||||
NetworkConfig::get()->setStateFrequency(state_frequency_in_server);
|
NetworkConfig::get()->setStateFrequency(state_frequency_in_server);
|
||||||
|
@ -2011,6 +2011,16 @@ void ServerLobby::connectionRequested(Event* event)
|
|||||||
data.decodeString(&user_version);
|
data.decodeString(&user_version);
|
||||||
event->getPeer()->setUserVersion(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;
|
std::set<std::string> client_karts, client_tracks;
|
||||||
const unsigned kart_num = data.getUInt16();
|
const unsigned kart_num = data.getUInt16();
|
||||||
const unsigned track_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;
|
(m_timeout.load() - (int64_t)StkTime::getRealTimeMs()) / 1000.0f;
|
||||||
}
|
}
|
||||||
message_ack->addUInt8(LE_CONNECTION_ACCEPTED).addUInt32(peer->getHostId())
|
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);
|
.addUInt32(ServerConfig::m_state_frequency);
|
||||||
|
|
||||||
peer->setSpectator(false);
|
peer->setSpectator(false);
|
||||||
|
@ -100,6 +100,10 @@ protected:
|
|||||||
|
|
||||||
std::string m_user_version;
|
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:
|
public:
|
||||||
STKPeer(ENetPeer *enet_peer, STKHost* host, uint32_t host_id);
|
STKPeer(ENetPeer *enet_peer, STKHost* host, uint32_t host_id);
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -231,6 +235,12 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
return (int)(diff / 1000);
|
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
|
}; // STKPeer
|
||||||
|
|
||||||
#endif // STK_PEER_HPP
|
#endif // STK_PEER_HPP
|
||||||
|
Loading…
Reference in New Issue
Block a user