Add user version in string to connection request

This commit is contained in:
Benau
2018-09-15 15:57:27 +08:00
parent 57d4017cc6
commit 4cf9542be1
6 changed files with 38 additions and 19 deletions

View File

@@ -107,7 +107,8 @@ void mainLoop(STKHost* host)
for (unsigned int i = 0; i < peers.size(); i++)
{
std::cout << peers[i]->getHostId() << ": " <<
peers[i]->getAddress().toString() << std::endl;
peers[i]->getAddress().toString() << " " <<
peers[i]->getUserVersion() << std::endl;
}
}
else if (str == "listban")

View File

@@ -300,7 +300,8 @@ void ClientLobby::update(int ticks)
{
NetworkString* ns = getNetworkString();
ns->addUInt8(LE_CONNECTION_REQUESTED)
.addUInt32(ServerConfig::m_server_version);
.addUInt32(ServerConfig::m_server_version)
.encodeString(StringUtils::getUserAgentString());
auto all_k = kart_properties_manager->getAllAvailableKarts();
auto all_t = track_manager->getAllTrackIdentifiers();

View File

@@ -1362,6 +1362,9 @@ void ServerLobby::connectionRequested(Event* event)
Log::verbose("ServerLobby", "Player refused: wrong server version");
return;
}
std::string user_version;
data.decodeString(&user_version);
event->getPeer()->setUserVersion(user_version);
std::set<std::string> client_karts, client_tracks;
const unsigned kart_num = data.getUInt16();
@@ -1615,9 +1618,10 @@ void ServerLobby::handleUnencryptedConnection(std::shared_ptr<STKPeer> peer,
{
m_game_setup->addPlayer(npp);
Log::info("ServerLobby",
"New player %s with online id %u from %s.",
"New player %s with online id %u from %s with %s.",
StringUtils::wideToUtf8(npp->getName()).c_str(),
npp->getOnlineId(), peer->getAddress().toString().c_str());
npp->getOnlineId(), peer->getAddress().toString().c_str(),
peer->getUserVersion().c_str());
}
updatePlayerList();
peer->sendPacket(message_ack);

View File

@@ -35,6 +35,7 @@
#include <memory>
#include <numeric>
#include <set>
#include <string>
#include <vector>
class Crypto;
@@ -91,6 +92,8 @@ protected:
std::set<unsigned> m_available_kart_ids;
std::string m_user_version;
public:
STKPeer(ENetPeer *enet_peer, STKHost* host, uint32_t host_id);
// ------------------------------------------------------------------------
@@ -190,6 +193,11 @@ public:
// ------------------------------------------------------------------------
bool availableKartID(unsigned id)
{ return m_available_kart_ids.find(id) != m_available_kart_ids.end(); }
// ------------------------------------------------------------------------
void setUserVersion(const std::string& uv) { m_user_version = uv; }
// ------------------------------------------------------------------------
const std::string& getUserVersion() const { return m_user_version; }
}; // STKPeer
#endif // STK_PEER_HPP

View File

@@ -276,20 +276,7 @@ namespace Online
} // end log http request
curl_easy_setopt(m_curl_session, CURLOPT_POSTFIELDS, m_parameters.c_str());
std::string uagent( std::string("SuperTuxKart/") + STK_VERSION );
#ifdef WIN32
uagent += (std::string)" (Windows)";
#elif defined(__APPLE__)
uagent += (std::string)" (Macintosh)";
#elif defined(__FreeBSD__)
uagent += (std::string)" (FreeBSD)";
#elif defined(ANDROID)
uagent += (std::string)" (Android)";
#elif defined(linux)
uagent += (std::string)" (Linux)";
#else
// Unknown system type
#endif
const std::string& uagent = StringUtils::getUserAgentString();
curl_easy_setopt(m_curl_session, CURLOPT_USERAGENT, uagent.c_str());
m_curl_code = curl_easy_perform(m_curl_session);

View File

@@ -26,6 +26,7 @@
#include <vector>
#include <sstream>
#include <irrString.h>
#include "utils/constants.hpp"
#include "utils/types.hpp"
#include "utils/log.hpp"
@@ -245,7 +246,24 @@ namespace StringUtils
std::string wideToUtf8(const irr::core::stringw& input);
std::string findAndReplace(const std::string& source, const std::string& find, const std::string& replace);
std::string removeWhitespaces(const std::string& input);
inline std::string getUserAgentString()
{
std::string uagent(std::string("SuperTuxKart/") + STK_VERSION);
#ifdef WIN32
uagent += (std::string)" (Windows)";
#elif defined(__APPLE__)
uagent += (std::string)" (Macintosh)";
#elif defined(__FreeBSD__)
uagent += (std::string)" (FreeBSD)";
#elif defined(ANDROID)
uagent += (std::string)" (Android)";
#elif defined(linux)
uagent += (std::string)" (Linux)";
#else
// Unknown system type
#endif
return uagent;
}
} // namespace StringUtils
#endif