Add report_player network capabilities

This commit is contained in:
Benau 2019-05-09 11:22:19 +08:00
parent bb3566ac81
commit c38278fbc1
7 changed files with 42 additions and 16 deletions

View File

@ -581,4 +581,9 @@
max-adjust-time="2.0"
adjust-length-threshold="4.0"/>
<!-- List of network capabilities to handle different servers with same version.
-->
<network-capabilities>
<capabilities name="report_player"/>
</network-capabilities>
</config>

View File

@ -539,6 +539,18 @@ void STKConfig::getAllData(const XMLNode * root)
ns->get("adjust-length-threshold", &m_snb_adjust_length_threshold);
}
if (const XMLNode* nc = root->getNode("network-capabilities"))
{
for (unsigned int i = 0; i < nc->getNumNodes(); i++)
{
const XMLNode* name = nc->getNode(i);
std::string cap;
name->get("name", &cap);
if (!cap.empty())
m_network_capabilities.insert(cap);
}
}
// Get the default KartProperties
// ------------------------------
const XMLNode *node = root -> getNode("general-kart-defaults");

View File

@ -31,9 +31,10 @@
#include "utils/no_copy.hpp"
#include "utils/constants.hpp"
#include <vector>
#include <string>
#include <map>
#include <set>
#include <string>
#include <vector>
class KartProperties;
class MusicInformation;
@ -229,6 +230,10 @@ public:
/** If true we allow all the server urls to be redirected by the news.xml. */
bool m_allow_news_redirects = true;
/** List of network capabilities to handle different servers with same
* version. */
std::set<std::string> m_network_capabilities;
private:
/** True if stk_config has been loaded. This is necessary if the
* --stk-config command line parameter has been specified to avoid

View File

@ -27,6 +27,7 @@
#include "utils/no_copy.hpp"
#include "irrString.h"
#include <set>
#include <tuple>
#include <vector>
@ -95,7 +96,7 @@ private:
/** List of server capabilities set when joining it, to determine features
* available in same version. */
std::vector<std::string> m_server_capabilities;
std::set<std::string> m_server_capabilities;
public:
/** Singleton get, which creates this object if necessary. */
@ -236,12 +237,12 @@ public:
// ------------------------------------------------------------------------
bool roundValuesNow() const;
// ------------------------------------------------------------------------
void setServerCapabilities(std::vector<std::string>& caps)
void setServerCapabilities(std::set<std::string>& caps)
{ m_server_capabilities = std::move(caps); }
// ------------------------------------------------------------------------
void clearServerCapabilities() { m_server_capabilities.clear(); }
// ------------------------------------------------------------------------
const std::vector<std::string>& getServerCapabilities() const
const std::set<std::string>& getServerCapabilities() const
{ return m_server_capabilities; }
}; // class NetworkConfig

View File

@ -360,8 +360,9 @@ void ClientLobby::update(int ticks)
ns->addUInt8(LE_CONNECTION_REQUESTED)
.addUInt32(ServerConfig::m_server_version)
.encodeString(StringUtils::getUserAgentString())
// Reserved for future to supply list of network capabilities
.addUInt16(0);
.addUInt16((uint16_t)stk_config->m_network_capabilities.size());
for (const std::string& cap : stk_config->m_network_capabilities)
ns->encodeString(cap);
auto all_k = kart_properties_manager->getAllAvailableKarts();
auto all_t = track_manager->getAllTrackIdentifiers();
@ -606,12 +607,12 @@ void ClientLobby::connectionAccepted(Event* event)
m_state.store(CONNECTED);
unsigned list_caps = data.getUInt16();
std::vector<std::string> caps;
std::set<std::string> caps;
for (unsigned i = 0; i < list_caps; i++)
{
std::string cap;
data.decodeString(&cap);
caps.push_back(cap);
caps.insert(cap);
}
NetworkConfig::get()->setServerCapabilities(caps);

View File

@ -2590,12 +2590,12 @@ void ServerLobby::connectionRequested(Event* event)
event->getPeer()->setUserVersion(user_version);
unsigned list_caps = data.getUInt16();
std::vector<std::string> caps;
std::set<std::string> caps;
for (unsigned i = 0; i < list_caps; i++)
{
std::string cap;
data.decodeString(&cap);
caps.push_back(cap);
caps.insert(cap);
}
event->getPeer()->setClientCapabilities(caps);
@ -2843,8 +2843,10 @@ void ServerLobby::handleUnencryptedConnection(std::shared_ptr<STKPeer> peer,
message_ack->addUInt8(LE_CONNECTION_ACCEPTED).addUInt32(peer->getHostId())
.addUInt32(ServerConfig::m_server_version);
// Reserved for future to supply list of network capabilities
message_ack->addUInt16(0);
message_ack->addUInt16(
(uint16_t)stk_config->m_network_capabilities.size());
for (const std::string& cap : stk_config->m_network_capabilities)
message_ack->encodeString(cap);
message_ack->addFloat(auto_start_timer)
.addUInt32(ServerConfig::m_state_frequency)

View File

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