2022-02-19 02:31:16 +01:00
|
|
|
//=====================================================================================//
|
|
|
|
//
|
|
|
|
// Purpose: Implementation of the pylon server backend.
|
|
|
|
//
|
|
|
|
// $NoKeywords: $
|
|
|
|
//=====================================================================================//
|
|
|
|
|
|
|
|
#include <core/stdafx.h>
|
2022-04-09 16:16:40 +02:00
|
|
|
#include <tier1/cvar.h>
|
2022-02-19 02:31:16 +01:00
|
|
|
#include <networksystem/pylon.h>
|
2022-08-28 17:40:03 +02:00
|
|
|
#ifndef CLIENT_DLL
|
|
|
|
#include <engine/server/server.h>
|
|
|
|
#endif // !CLIENT_DLL
|
2022-02-19 02:31:16 +01:00
|
|
|
|
2022-07-01 10:29:27 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: returns a vector of hosted servers.
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-08-30 12:07:09 +02:00
|
|
|
vector<NetGameServer_t> CPylon::GetServerList(string& svOutMessage) const
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
|
|
|
vector<NetGameServer_t> vslList{};
|
|
|
|
|
|
|
|
nlohmann::json jsRequestBody = nlohmann::json::object();
|
|
|
|
jsRequestBody["version"] = SDK_VERSION;
|
|
|
|
|
|
|
|
string svRequestBody = jsRequestBody.dump(4);
|
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
if (pylon_showdebuginfo->GetBool())
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
|
|
|
DevMsg(eDLL_T::ENGINE, "%s - Sending server list request to comp-server:\n%s\n", __FUNCTION__, svRequestBody.c_str());
|
|
|
|
}
|
|
|
|
|
2022-08-27 18:57:56 +02:00
|
|
|
httplib::Client htClient(pylon_matchmaking_hostname->GetString()); htClient.set_connection_timeout(10);
|
2022-08-31 17:18:26 +02:00
|
|
|
httplib::Result htResult = htClient.Post("/servers", svRequestBody.c_str(), svRequestBody.length(), "application/json");
|
2022-08-27 18:57:56 +02:00
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
if (htResult && pylon_showdebuginfo->GetBool())
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-31 17:18:26 +02:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s - Comp-server replied with '%d'\n", __FUNCTION__, htResult->status);
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
|
2022-08-28 17:12:58 +02:00
|
|
|
try
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-28 17:12:58 +02:00
|
|
|
if (htResult && htResult->status == 200) // STATUS_OK
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-28 17:12:58 +02:00
|
|
|
nlohmann::json jsResultBody = nlohmann::json::parse(htResult->body);
|
|
|
|
if (jsResultBody["success"].is_boolean() && jsResultBody["success"].get<bool>())
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-28 17:12:58 +02:00
|
|
|
for (auto& obj : jsResultBody["servers"])
|
|
|
|
{
|
|
|
|
vslList.push_back(
|
|
|
|
NetGameServer_t
|
|
|
|
{
|
|
|
|
obj.value("name",""),
|
|
|
|
obj.value("description",""),
|
|
|
|
obj.value("hidden","false") == "true",
|
|
|
|
obj.value("map",""),
|
|
|
|
obj.value("playlist",""),
|
|
|
|
obj.value("ip",""),
|
|
|
|
obj.value("port", ""),
|
|
|
|
obj.value("key",""),
|
|
|
|
obj.value("checksum",""),
|
|
|
|
obj.value("version", SDK_VERSION),
|
|
|
|
obj.value("playerCount", ""),
|
|
|
|
obj.value("maxPlayers", ""),
|
|
|
|
obj.value("timeStamp", 0),
|
|
|
|
obj.value("publicRef", ""),
|
|
|
|
obj.value("cachedID", ""),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
if (jsResultBody["error"].is_string())
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
svOutMessage = jsResultBody["error"].get<string>();
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-31 17:18:26 +02:00
|
|
|
svOutMessage = string("Unknown error with status: ") + std::to_string(htResult->status);
|
2022-08-28 17:12:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (htResult)
|
|
|
|
{
|
|
|
|
if (!htResult->body.empty())
|
|
|
|
{
|
|
|
|
nlohmann::json jsResultBody = nlohmann::json::parse(htResult->body);
|
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
if (jsResultBody["error"].is_string())
|
2022-08-28 17:12:58 +02:00
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
svOutMessage = jsResultBody["error"].get<string>();
|
2022-08-28 17:12:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-31 17:18:26 +02:00
|
|
|
svOutMessage = string("Failed HTTP request: ") + std::to_string(htResult->status);
|
2022-08-28 17:12:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return vslList;
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
|
2022-08-31 17:18:26 +02:00
|
|
|
svOutMessage = string("Failed HTTP request: ") + std::to_string(htResult->status);
|
2022-07-01 10:29:27 +02:00
|
|
|
return vslList;
|
|
|
|
}
|
|
|
|
|
2022-08-29 00:29:32 +02:00
|
|
|
svOutMessage = "Failed to reach comp-server: connection timed-out";
|
2022-07-01 10:29:27 +02:00
|
|
|
return vslList;
|
|
|
|
}
|
2022-08-28 17:12:58 +02:00
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
Warning(eDLL_T::ENGINE, "%s - Exception while parsing comp-server response:\n%s\n", __FUNCTION__, ex.what());
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return vslList;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-08-30 12:07:09 +02:00
|
|
|
// Purpose: Gets the server by token string.
|
|
|
|
// Input : &slOutServer -
|
|
|
|
// &svOutMessage -
|
|
|
|
// svToken -
|
2022-07-01 10:29:27 +02:00
|
|
|
// Output : Returns true on success, false on failure.
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-08-30 12:07:09 +02:00
|
|
|
bool CPylon::GetServerByToken(NetGameServer_t& slOutServer, string& svOutMessage, const string& svToken) const
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
|
|
|
nlohmann::json jsRequestBody = nlohmann::json::object();
|
2022-08-30 12:07:09 +02:00
|
|
|
jsRequestBody["token"] = svToken;
|
2022-07-01 10:29:27 +02:00
|
|
|
|
|
|
|
string svRequestBody = jsRequestBody.dump(4);
|
2022-08-30 12:07:09 +02:00
|
|
|
|
|
|
|
if (pylon_showdebuginfo->GetBool())
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s - Sending token connect request to comp-server:\n%s\n", __FUNCTION__, svRequestBody.c_str());
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
|
2022-08-27 18:57:56 +02:00
|
|
|
httplib::Client htClient(pylon_matchmaking_hostname->GetString()); htClient.set_connection_timeout(10);
|
2022-08-31 17:18:26 +02:00
|
|
|
httplib::Result htResult = htClient.Post("/server/byToken", svRequestBody.c_str(), svRequestBody.length(), "application/json");
|
2022-08-27 18:57:56 +02:00
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
if (pylon_showdebuginfo->GetBool())
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-27 18:57:56 +02:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s - Comp-server replied with '%d'\n", __FUNCTION__, htResult->status);
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
|
2022-08-28 17:12:58 +02:00
|
|
|
try
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-28 17:12:58 +02:00
|
|
|
if (htResult && htResult->status == 200) // STATUS_OK
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
if (!htResult->body.empty())
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
nlohmann::json jsResultBody = nlohmann::json::parse(htResult->body);
|
2022-07-01 10:29:27 +02:00
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
if (htResult && jsResultBody["success"].is_boolean() && jsResultBody["success"])
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
slOutServer = NetGameServer_t
|
|
|
|
{
|
|
|
|
jsResultBody["server"].value("name",""),
|
|
|
|
jsResultBody["server"].value("description",""),
|
|
|
|
jsResultBody["server"].value("hidden","false") == "true",
|
|
|
|
jsResultBody["server"].value("map",""),
|
|
|
|
jsResultBody["server"].value("playlist",""),
|
|
|
|
jsResultBody["server"].value("ip",""),
|
|
|
|
jsResultBody["server"].value("port", ""),
|
|
|
|
jsResultBody["server"].value("key",""),
|
|
|
|
jsResultBody["server"].value("checksum",""),
|
|
|
|
jsResultBody["server"].value("version", SDK_VERSION),
|
|
|
|
jsResultBody["server"].value("playerCount", ""),
|
|
|
|
jsResultBody["server"].value("maxPlayers", ""),
|
|
|
|
jsResultBody["server"].value("timeStamp", 0),
|
|
|
|
jsResultBody["server"].value("publicRef", ""),
|
|
|
|
jsResultBody["server"].value("cachedID", ""),
|
|
|
|
};
|
|
|
|
return true;
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
if (jsResultBody["error"].is_string())
|
|
|
|
{
|
|
|
|
svOutMessage = jsResultBody["error"].get<string>();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-31 17:18:26 +02:00
|
|
|
svOutMessage = string("Unknown error with status: ") + std::to_string(htResult->status);
|
2022-08-30 12:07:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
slOutServer = NetGameServer_t{};
|
|
|
|
return false;
|
2022-08-28 17:12:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (htResult)
|
|
|
|
{
|
|
|
|
if (!htResult->body.empty())
|
|
|
|
{
|
|
|
|
nlohmann::json jsResultBody = nlohmann::json::parse(htResult->body);
|
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
if (jsResultBody["error"].is_string())
|
2022-08-28 17:12:58 +02:00
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
svOutMessage = jsResultBody["error"].get<string>();
|
2022-08-28 17:12:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-31 17:18:26 +02:00
|
|
|
svOutMessage = string("Server not found: ") + std::to_string(htResult->status);
|
2022-08-28 17:12:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
|
2022-08-31 17:18:26 +02:00
|
|
|
svOutMessage = string("Failed HTTP request: ") + std::to_string(htResult->status);
|
2022-07-01 10:29:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-29 00:29:32 +02:00
|
|
|
svOutMessage = "Failed to reach comp-server: connection timed-out";
|
2022-08-30 12:07:09 +02:00
|
|
|
slOutServer = NetGameServer_t{};
|
2022-07-01 10:29:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
2022-08-28 17:12:58 +02:00
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
Warning(eDLL_T::ENGINE, "%s - Exception while parsing comp-server response:\n%s\n", __FUNCTION__, ex.what());
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-08-30 12:07:09 +02:00
|
|
|
// Purpose: Sends host server POST request.
|
|
|
|
// Input : &svOutMessage -
|
|
|
|
// &svOutToken -
|
|
|
|
// &slServerListing -
|
2022-07-01 10:29:27 +02:00
|
|
|
// Output : Returns true on success, false on failure.
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-08-30 12:07:09 +02:00
|
|
|
bool CPylon::PostServerHost(string& svOutMessage, string& svOutToken, const NetGameServer_t& slServerListing) const
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
|
|
|
nlohmann::json jsRequestBody = nlohmann::json::object();
|
2022-08-30 12:07:09 +02:00
|
|
|
jsRequestBody["name"] = slServerListing.m_svHostName;
|
|
|
|
jsRequestBody["description"] = slServerListing.m_svDescription;
|
|
|
|
jsRequestBody["hidden"] = slServerListing.m_bHidden;
|
|
|
|
jsRequestBody["map"] = slServerListing.m_svHostMap;
|
|
|
|
jsRequestBody["playlist"] = slServerListing.m_svPlaylist;
|
|
|
|
jsRequestBody["ip"] = slServerListing.m_svIpAddress;
|
|
|
|
jsRequestBody["port"] = slServerListing.m_svGamePort;
|
|
|
|
jsRequestBody["key"] = slServerListing.m_svEncryptionKey;
|
|
|
|
jsRequestBody["checksum"] = slServerListing.m_svRemoteChecksum;
|
|
|
|
jsRequestBody["version"] = slServerListing.m_svSDKVersion;
|
|
|
|
jsRequestBody["playerCount"] = slServerListing.m_svPlayerCount;
|
|
|
|
jsRequestBody["maxPlayers"] = slServerListing.m_svMaxPlayers;
|
|
|
|
jsRequestBody["timeStamp"] = slServerListing.m_nTimeStamp;
|
|
|
|
jsRequestBody["publicRef"] = slServerListing.m_svPublicRef;
|
|
|
|
jsRequestBody["cachedID"] = slServerListing.m_svCachedID;
|
2022-07-01 10:29:27 +02:00
|
|
|
|
|
|
|
string svRequestBody = jsRequestBody.dump(4);
|
2022-08-30 12:07:09 +02:00
|
|
|
if (pylon_showdebuginfo->GetBool())
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s - Sending post host request to comp-server:\n%s\n", __FUNCTION__, svRequestBody.c_str());
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
|
2022-08-27 18:57:56 +02:00
|
|
|
httplib::Client htClient(pylon_matchmaking_hostname->GetString()); htClient.set_connection_timeout(10);
|
2022-08-30 12:07:09 +02:00
|
|
|
httplib::Result htResult = htClient.Post("/servers/add", svRequestBody.c_str(), svRequestBody.length(), "application/json");
|
2022-07-01 10:29:27 +02:00
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
if (htResult && pylon_showdebuginfo->GetBool())
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-27 18:57:56 +02:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s - Comp-server replied with '%d'\n", __FUNCTION__, htResult->status);
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
|
2022-08-28 17:12:58 +02:00
|
|
|
try
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-28 17:12:58 +02:00
|
|
|
if (htResult && htResult->status == 200) // STATUS_OK
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
nlohmann::json jsResultBody = nlohmann::json::parse(htResult->body);
|
|
|
|
if (jsResultBody["success"].is_boolean() && jsResultBody["success"].get<bool>())
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
if (jsResultBody["token"].is_string())
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
svOutToken = jsResultBody["token"].get<string>();
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
svOutToken = string();
|
|
|
|
}
|
2022-07-01 10:29:27 +02:00
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (jsResultBody["error"].is_string())
|
|
|
|
{
|
|
|
|
svOutMessage = jsResultBody["error"].get<string>();
|
2022-08-28 17:12:58 +02:00
|
|
|
}
|
2022-08-30 12:07:09 +02:00
|
|
|
else
|
|
|
|
{
|
2022-08-31 17:18:26 +02:00
|
|
|
svOutMessage = string("Unknown error with status: ") + std::to_string(htResult->status);
|
2022-08-30 12:07:09 +02:00
|
|
|
}
|
|
|
|
return false;
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
}
|
2022-08-28 17:12:58 +02:00
|
|
|
else
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-28 17:12:58 +02:00
|
|
|
if (htResult)
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-28 17:12:58 +02:00
|
|
|
if (!htResult->body.empty())
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-28 17:12:58 +02:00
|
|
|
nlohmann::json jsResultBody = nlohmann::json::parse(htResult->body);
|
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
if (jsResultBody["error"].is_string())
|
2022-08-28 17:12:58 +02:00
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
svOutMessage = jsResultBody["error"].get<string>();
|
2022-08-28 17:12:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-31 17:18:26 +02:00
|
|
|
svOutMessage = string("Failed HTTP request: ") + std::to_string(htResult->status);
|
2022-08-28 17:12:58 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
svOutToken = string();
|
2022-08-28 17:12:58 +02:00
|
|
|
return false;
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
svOutToken = string();
|
2022-08-31 17:18:26 +02:00
|
|
|
svOutMessage = string("Failed HTTP request: ") + std::to_string(htResult->status);
|
2022-07-01 10:29:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
svOutToken = string();
|
2022-08-29 00:29:32 +02:00
|
|
|
svOutMessage = "Failed to reach comp-server: connection timed-out";
|
2022-07-01 10:29:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
2022-08-28 17:12:58 +02:00
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
Warning(eDLL_T::ENGINE, "%s - Exception while parsing comp-server response:\n%s\n", __FUNCTION__, ex.what());
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Send keep alive request to Pylon Master Server.
|
|
|
|
// Input : &netGameServer -
|
|
|
|
// Output : Returns true on success, false otherwise.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool CPylon::KeepAlive(const NetGameServer_t& netGameServer) const
|
|
|
|
{
|
|
|
|
#ifndef CLIENT_DLL
|
|
|
|
if (g_pServer->IsActive() && sv_pylonVisibility->GetBool()) // Check for active game.
|
|
|
|
{
|
|
|
|
string m_szHostToken;
|
|
|
|
string m_szHostRequestMessage;
|
|
|
|
|
|
|
|
bool result = g_pMasterServer->PostServerHost(m_szHostRequestMessage, m_szHostToken, netGameServer);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
#endif // !CLIENT_DLL
|
|
|
|
}
|
|
|
|
|
2022-07-01 10:29:27 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Checks if client is banned on the comp server.
|
|
|
|
// Input : svIpAddress -
|
2022-08-29 15:59:12 +02:00
|
|
|
// nNucleusID -
|
2022-08-30 12:07:09 +02:00
|
|
|
// &svOutReason -
|
2022-07-01 10:29:27 +02:00
|
|
|
// Output : Returns true if banned, false if not banned.
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-08-30 12:07:09 +02:00
|
|
|
bool CPylon::CheckForBan(const string& svIpAddress, const uint64_t nNucleusID, string& svOutReason) const
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
|
|
|
nlohmann::json jsRequestBody = nlohmann::json::object();
|
2022-08-29 15:59:12 +02:00
|
|
|
jsRequestBody["id"] = nNucleusID;
|
2022-07-01 10:29:27 +02:00
|
|
|
jsRequestBody["ip"] = svIpAddress;
|
|
|
|
|
2022-08-27 18:57:56 +02:00
|
|
|
httplib::Client htClient(pylon_matchmaking_hostname->GetString()); htClient.set_connection_timeout(10);
|
|
|
|
httplib::Result htResult = htClient.Post("/banlist/isBanned", jsRequestBody.dump(4).c_str(), jsRequestBody.dump(4).length(), "application/json");
|
|
|
|
|
2022-08-28 17:12:58 +02:00
|
|
|
try
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-28 17:12:58 +02:00
|
|
|
if (htResult && htResult->status == 200)
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-28 17:12:58 +02:00
|
|
|
nlohmann::json jsResultBody = nlohmann::json::parse(htResult->body);
|
|
|
|
if (jsResultBody["success"].is_boolean() && jsResultBody["success"].get<bool>())
|
2022-07-01 10:29:27 +02:00
|
|
|
{
|
2022-08-28 17:12:58 +02:00
|
|
|
if (jsResultBody["banned"].is_boolean() && jsResultBody["banned"].get<bool>())
|
|
|
|
{
|
2022-08-30 12:07:09 +02:00
|
|
|
svOutReason = jsResultBody.value("reason", "#DISCONNECT_BANNED");
|
2022-08-28 17:12:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
2022-07-01 10:29:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-28 17:12:58 +02:00
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
Warning(eDLL_T::ENGINE, "%s - Exception while parsing comp-server response:\n%s\n", __FUNCTION__, ex.what());
|
|
|
|
}
|
2022-07-01 10:29:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2022-08-27 18:57:56 +02:00
|
|
|
CPylon* g_pMasterServer(new CPylon());
|