1
0
mirror of https://github.com/Mauler125/r5sdk.git synced 2025-02-09 19:15:03 +01:00

Renamed master server related stuff

This commit is contained in:
Kawe Mazidjatari 2022-07-01 10:29:27 +02:00
parent d417b60e69
commit cdcc87b54b
20 changed files with 386 additions and 419 deletions

@ -13,7 +13,7 @@
#include "tier1/cvar.h"
#include "engine/server/sv_main.h"
#include "engine/server/server.h"
#include "networksystem/r5net.h"
#include "networksystem/pylon.h"
#include "public/include/edict.h"
#include "public/include/bansystem.h"
@ -98,9 +98,9 @@ CClient* CServer::Authenticate(CServer* pServer, user_creds_s* pInpacket)
if (g_bCheckCompBanDB)
{
if (g_pR5net)
if (g_pMasterServer)
{
std::thread th(SV_IsClientBanned, g_pR5net, svIpAddress, pInpacket->m_nNucleusID);
std::thread th(SV_IsClientBanned, g_pMasterServer, svIpAddress, pInpacket->m_nNucleusID);
th.detach();
}
}

@ -1,6 +1,6 @@
#pragma once
#include "tier1/NetAdr2.h"
#include "networksystem/r5net.h"
#include "networksystem/pylon.h"
#include "engine/client/client.h"
#include "engine/networkstringtable.h"
#include "public/include/iserver.h"

@ -1,16 +1,16 @@
#include "core/stdafx.h"
#include "engine/server/sv_main.h"
#include "networksystem/r5net.h"
#include "networksystem/pylon.h"
#include "public/include/bansystem.h"
//-----------------------------------------------------------------------------
// Purpose: checks if particular client is banned on the comp server
//-----------------------------------------------------------------------------
void SV_IsClientBanned(R5Net::Client* pR5net, const string svIPAddr, uint64_t nNucleusID)
void SV_IsClientBanned(CPylon* pPylon, const string svIPAddr, uint64_t nNucleusID)
{
string svError = string();
bool bCompBanned = pR5net->GetClientIsBanned(svIPAddr, nNucleusID, svError);
bool bCompBanned = pPylon->GetClientIsBanned(svIPAddr, nNucleusID, svError);
if (bCompBanned)
{
DevMsg(eDLL_T::SERVER, "Connection rejected for '%s' ('%llu' is banned from the master server!)\n", svIPAddr.c_str(), nNucleusID);

@ -1,5 +1,5 @@
#pragma once
#include "networksystem/r5net.h"
#include "networksystem/pylon.h"
#include "public/include/bansystem.h"
///////////////////////////////////////////////////////////////////////////////
@ -21,7 +21,7 @@ inline bool* s_bDedicated = nullptr;
///////////////////////////////////////////////////////////////////////////////
void SV_IsClientBanned(R5Net::Client* pR5net, const string svIPAddr, uint64_t nNucleusID);
void SV_IsClientBanned(CPylon* pPylon, const string svIPAddr, uint64_t nNucleusID);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

@ -27,7 +27,7 @@ History:
#include "engine/server/server.h"
#endif // CLIENT_DLL
#include "networksystem/serverlisting.h"
#include "networksystem/r5net.h"
#include "networksystem/pylon.h"
#include "squirrel/sqinit.h"
#include "squirrel/sqapi.h"
#include "client/vengineclient_impl.h"
@ -79,7 +79,7 @@ void CBrowser::Draw(void)
if (!m_bInitialized)
{
SetStyleVar();
m_szMatchmakingHostName = r5net_matchmaking_hostname->GetString();
m_szMatchmakingHostName = pylon_matchmaking_hostname->GetString();
m_bInitialized = true;
}
@ -277,9 +277,9 @@ void CBrowser::RefreshServerList(void)
{
std::thread t([this]()
{
DevMsg(eDLL_T::CLIENT, "Refreshing server list with matchmaking host '%s'\n", r5net_matchmaking_hostname->GetString());
DevMsg(eDLL_T::CLIENT, "Refreshing server list with matchmaking host '%s'\n", pylon_matchmaking_hostname->GetString());
bThreadLocked = true;
m_vServerList = g_pR5net->GetServersList(m_svServerListMessage);
m_vServerList = g_pMasterServer->GetServersList(m_svServerListMessage);
bThreadLocked = false;
});
@ -294,7 +294,7 @@ void CBrowser::GetServerList(void)
{
m_vServerList.clear();
m_svServerListMessage.clear();
m_vServerList = g_pR5net->GetServersList(m_svServerListMessage);
m_vServerList = g_pMasterServer->GetServersList(m_svServerListMessage);
}
//-----------------------------------------------------------------------------
@ -394,7 +394,7 @@ void CBrowser::HiddenServersModal(void)
{
m_svHiddenServerRequestMessage.clear();
NetGameServer_t server;
bool result = g_pR5net->GetServerByToken(server, m_svHiddenServerRequestMessage, m_svHiddenServerToken); // Send token connect request.
bool result = g_pMasterServer->GetServerByToken(server, m_svHiddenServerRequestMessage, m_svHiddenServerToken); // Send token connect request.
if (!server.m_svHostName.empty())
{
ConnectToServer(server.m_svIpAddress, server.m_svGamePort, server.m_svEncryptionKey); // Connect to the server
@ -633,7 +633,7 @@ void CBrowser::SendHostingPostRequest(void)
{
#ifndef CLIENT_DLL
m_svHostToken.clear();
bool result = g_pR5net->PostServerHost(m_svHostRequestMessage, m_svHostToken,
bool result = g_pMasterServer->PostServerHost(m_svHostRequestMessage, m_svHostToken,
NetGameServer_t
{
m_Server.m_svHostName,
@ -693,11 +693,11 @@ void CBrowser::SettingsPanel(void)
ImGui::InputTextWithHint("Hostname", "Matchmaking Server String", &m_szMatchmakingHostName);
if (ImGui::Button("Update Hostname"))
{
r5net_matchmaking_hostname->SetValue(m_szMatchmakingHostName.c_str());
if (g_pR5net)
pylon_matchmaking_hostname->SetValue(m_szMatchmakingHostName.c_str());
if (g_pMasterServer)
{
delete g_pR5net;
g_pR5net = new R5Net::Client(r5net_matchmaking_hostname->GetString());
delete g_pMasterServer;
g_pMasterServer = new CPylon(pylon_matchmaking_hostname->GetString());
}
}
ImGui::InputText("Netkey", const_cast<char*>(g_svNetKey.c_str()), ImGuiInputTextFlags_ReadOnly);

@ -3,7 +3,7 @@
#include "common/sdkdefs.h"
#include "windows/resource.h"
#include "networksystem/serverlisting.h"
#include "networksystem/r5net.h"
#include "networksystem/pylon.h"
enum class eHostStatus
{

@ -12,7 +12,6 @@
#include <engine/sys_utils.h>
#include <engine/server/server.h>
#include <squirrel/sqinit.h>
#include <networksystem/r5net.h>
#include <networksystem/pylon.h>
#include <public/include/edict.h>
@ -28,7 +27,7 @@ void KeepAliveToPylon()
std::string m_szHostToken = std::string();
std::string m_szHostRequestMessage = std::string();
bool result = g_pR5net->PostServerHost(m_szHostRequestMessage, m_szHostToken,
bool result = g_pMasterServer->PostServerHost(m_szHostRequestMessage, m_szHostToken,
NetGameServer_t
{
hostname->GetString(),
@ -50,4 +49,333 @@ void KeepAliveToPylon()
);
}
#endif // !CLIENT_DLL
}
}
//-----------------------------------------------------------------------------
// Purpose: returns a vector of hosted servers.
//-----------------------------------------------------------------------------
vector<NetGameServer_t> CPylon::GetServersList(string& svOutMessage)
{
vector<NetGameServer_t> vslList{};
nlohmann::json jsRequestBody = nlohmann::json::object();
jsRequestBody["version"] = SDK_VERSION;
string svRequestBody = jsRequestBody.dump(4);
if (pylon_showdebug->GetBool())
{
DevMsg(eDLL_T::ENGINE, "%s - Sending server list request to comp-server:\n%s\n", __FUNCTION__, svRequestBody.c_str());
}
httplib::Result htResults = m_HttpClient.Post("/servers", jsRequestBody.dump(4).c_str(), jsRequestBody.dump(4).length(), "application/json");
if (htResults && pylon_showdebug->GetBool())
{
DevMsg(eDLL_T::ENGINE, "%s - replied with '%d'.\n", __FUNCTION__, htResults->status);
}
if (htResults && htResults->status == 200) // STATUS_OK
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["success"].is_boolean() && jsResultBody["success"].get<bool>())
{
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", ""),
}
);
}
}
else
{
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<string>();
}
else
{
svOutMessage = "An unknown error occured!";
}
}
}
else
{
if (htResults)
{
if (!htResults->body.empty())
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<string>();
}
else
{
svOutMessage = string("Failed to reach comp-server: ") + std::to_string(htResults->status);
}
return vslList;
}
svOutMessage = string("Failed to reach comp-server: ") + std::to_string(htResults->status);
return vslList;
}
svOutMessage = "Failed to reach comp-server: Unknown error code";
return vslList;
}
return vslList;
}
//-----------------------------------------------------------------------------
// Purpose: Sends host server POST request.
// Input : &svOutMessage -
// &svOutToken -
// &slServerListing -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CPylon::PostServerHost(string& svOutMessage, string& svOutToken, const NetGameServer_t& slServerListing)
{
nlohmann::json jsRequestBody = nlohmann::json::object();
jsRequestBody["name"] = slServerListing.m_svHostName;
jsRequestBody["description"] = slServerListing.m_svDescription;
jsRequestBody["hidden"] = slServerListing.m_bHidden;
jsRequestBody["map"] = slServerListing.m_svMapName;
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;
string svRequestBody = jsRequestBody.dump(4);
if (pylon_showdebug->GetBool())
{
DevMsg(eDLL_T::ENGINE, "%s - Sending post host request to comp-server:\n%s\n", __FUNCTION__, svRequestBody.c_str());
}
httplib::Result htResults = m_HttpClient.Post("/servers/add", svRequestBody.c_str(), svRequestBody.length(), "application/json");
if (htResults && pylon_showdebug->GetBool())
{
DevMsg(eDLL_T::ENGINE, "%s - Comp-server replied with '%d'\n", __FUNCTION__, htResults->status);
}
if (htResults && htResults->status == 200) // STATUS_OK
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["success"].is_boolean() && jsResultBody["success"].get<bool>())
{
if (jsResultBody["token"].is_string())
{
svOutToken = jsResultBody["token"].get<string>();
}
else
{
svOutToken = string();
}
return true;
}
else
{
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<string>();
}
else
{
svOutMessage = "An unknown error occured!";
}
return false;
}
}
else
{
if (htResults)
{
if (!htResults->body.empty())
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<string>();
}
else
{
svOutMessage = string("Failed to reach comp-server ") + std::to_string(htResults->status);
}
svOutToken = string();
return false;
}
svOutToken = string();
svOutMessage = string("Failed to reach comp-server: ") + std::to_string(htResults->status);
return false;
}
svOutToken = string();
svOutMessage = "Failed to reach comp-server: Unknown error code";
return false;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Gets the server by token string.
// Input : &slOutServer -
// &svOutMessage -
// svToken -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CPylon::GetServerByToken(NetGameServer_t& slOutServer, string& svOutMessage, const string& svToken)
{
nlohmann::json jsRequestBody = nlohmann::json::object();
jsRequestBody["token"] = svToken;
string svRequestBody = jsRequestBody.dump(4);
if (pylon_showdebug->GetBool())
{
DevMsg(eDLL_T::ENGINE, "%s - Sending token connect request to comp-server:\n%s\n", __FUNCTION__, svRequestBody.c_str());
}
httplib::Result htResults = m_HttpClient.Post("/server/byToken", jsRequestBody.dump(4).c_str(), jsRequestBody.dump(4).length(), "application/json");
if (pylon_showdebug->GetBool())
{
DevMsg(eDLL_T::ENGINE, "%s - Comp-server replied with '%d'\n", __FUNCTION__, htResults->status);
}
if (htResults && htResults->status == 200) // STATUS_OK
{
if (!htResults->body.empty())
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (htResults && jsResultBody["success"].is_boolean() && jsResultBody["success"])
{
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;
}
else
{
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<string>();
}
else
{
svOutMessage = "";
}
slOutServer = NetGameServer_t{};
return false;
}
}
}
else
{
if (htResults)
{
if (!htResults->body.empty())
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<string>();
}
else
{
svOutMessage = string("Failed to reach comp-server: ") + std::to_string(htResults->status);
}
return false;
}
svOutMessage = string("Failed to reach comp-server: ") + std::to_string(htResults->status);
return false;
}
svOutMessage = "Failed to reach comp-server: Unknown error code";
slOutServer = NetGameServer_t{};
return false;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Checks if client is banned on the comp server.
// Input : svIpAddress -
// nOriginID -
// &svOutErrCl -
// Output : Returns true if banned, false if not banned.
//-----------------------------------------------------------------------------
bool CPylon::GetClientIsBanned(const string& svIpAddress, uint64_t nOriginID, string& svOutErrCl)
{
nlohmann::json jsRequestBody = nlohmann::json::object();
jsRequestBody["oid"] = nOriginID;
jsRequestBody["ip"] = svIpAddress;
httplib::Result htResults = m_HttpClient.Post("/banlist/isBanned", jsRequestBody.dump(4).c_str(), jsRequestBody.dump(4).length(), "application/json");
if (htResults && htResults->status == 200)
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["success"].is_boolean() && jsResultBody["success"].get<bool>())
{
if (jsResultBody["banned"].is_boolean() && jsResultBody["banned"].get<bool>())
{
svOutErrCl = jsResultBody.value("errCl", "#DISCONNECT_BANNED");
return true;
}
}
}
return false;
}
///////////////////////////////////////////////////////////////////////////////
CPylon* g_pMasterServer(new CPylon("127.0.0.1:3000"));

@ -1,3 +1,25 @@
#pragma once
#include "serverlisting.h"
void KeepAliveToPylon();
void KeepAliveToPylon();
class CPylon
{
public:
CPylon(string serverString) : m_HttpClient(serverString.c_str())
{
m_HttpClient.set_connection_timeout(10);
}
vector<NetGameServer_t> GetServersList(string& svOutMessage);
bool PostServerHost(string& svOutMessage, string& svOutToken, const NetGameServer_t& slServerListing);
bool GetServerByToken(NetGameServer_t& slOutServer, string& svOutMessage, const string& svToken);
bool GetClientIsBanned(const string& svIpAddress, uint64_t nOriginID, string& svOutErrCl);
CPylon* pR5net = nullptr;
CPylon* GetR5Net() { return pR5net; }
private:
httplib::Client m_HttpClient;
};
extern CPylon* g_pMasterServer;

@ -1,335 +0,0 @@
// r5net.cpp : Defines the functions for the static library.
//
#include "core/stdafx.h"
#include "tier1/cvar.h"
#include "networksystem/r5net.h"
//-----------------------------------------------------------------------------
// Purpose: returns a vector of hosted servers.
//-----------------------------------------------------------------------------
vector<NetGameServer_t> R5Net::Client::GetServersList(string& svOutMessage)
{
vector<NetGameServer_t> vslList{};
nlohmann::json jsRequestBody = nlohmann::json::object();
jsRequestBody["version"] = SDK_VERSION;
string svRequestBody = jsRequestBody.dump(4);
if (r5net_show_debug->GetBool())
{
DevMsg(eDLL_T::ENGINE, "%s - Sending server list request to comp-server:\n%s\n", __FUNCTION__, svRequestBody.c_str());
}
httplib::Result htResults = m_HttpClient.Post("/servers", jsRequestBody.dump(4).c_str(), jsRequestBody.dump(4).length(), "application/json");
if (htResults && r5net_show_debug->GetBool())
{
DevMsg(eDLL_T::ENGINE, "%s - replied with '%d'.\n", __FUNCTION__, htResults->status);
}
if (htResults && htResults->status == 200) // STATUS_OK
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["success"].is_boolean() && jsResultBody["success"].get<bool>())
{
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", ""),
}
);
}
}
else
{
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<string>();
}
else
{
svOutMessage = "An unknown error occured!";
}
}
}
else
{
if (htResults)
{
if (!htResults->body.empty())
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<string>();
}
else
{
svOutMessage = string("Failed to reach comp-server: ") + std::to_string(htResults->status);
}
return vslList;
}
svOutMessage = string("Failed to reach comp-server: ") + std::to_string(htResults->status);
return vslList;
}
svOutMessage = "Failed to reach comp-server: Unknown error code";
return vslList;
}
return vslList;
}
//-----------------------------------------------------------------------------
// Purpose: Sends host server POST request.
// Input : &svOutMessage -
// &svOutToken -
// &slServerListing -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool R5Net::Client::PostServerHost(string& svOutMessage, string& svOutToken, const NetGameServer_t& slServerListing)
{
nlohmann::json jsRequestBody = nlohmann::json::object();
jsRequestBody["name"] = slServerListing.m_svHostName;
jsRequestBody["description"] = slServerListing.m_svDescription;
jsRequestBody["hidden"] = slServerListing.m_bHidden;
jsRequestBody["map"] = slServerListing.m_svMapName;
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;
string svRequestBody = jsRequestBody.dump(4);
if (r5net_show_debug->GetBool())
{
DevMsg(eDLL_T::ENGINE, "%s - Sending post host request to comp-server:\n%s\n", __FUNCTION__, svRequestBody.c_str());
}
httplib::Result htResults = m_HttpClient.Post("/servers/add", svRequestBody.c_str(), svRequestBody.length(), "application/json");
if (htResults && r5net_show_debug->GetBool())
{
DevMsg(eDLL_T::ENGINE, "%s - Comp-server replied with '%d'\n", __FUNCTION__, htResults->status);
}
if (htResults && htResults->status == 200) // STATUS_OK
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["success"].is_boolean() && jsResultBody["success"].get<bool>())
{
if (jsResultBody["token"].is_string())
{
svOutToken = jsResultBody["token"].get<string>();
}
else
{
svOutToken = string();
}
return true;
}
else
{
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<string>();
}
else
{
svOutMessage = "An unknown error occured!";
}
return false;
}
}
else
{
if (htResults)
{
if (!htResults->body.empty())
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<string>();
}
else
{
svOutMessage = string("Failed to reach comp-server ") + std::to_string(htResults->status);
}
svOutToken = string();
return false;
}
svOutToken = string();
svOutMessage = string("Failed to reach comp-server: ") + std::to_string(htResults->status);
return false;
}
svOutToken = string();
svOutMessage = "Failed to reach comp-server: Unknown error code";
return false;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Gets the server by token string.
// Input : &slOutServer -
// &svOutMessage -
// svToken -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool R5Net::Client::GetServerByToken(NetGameServer_t& slOutServer, string& svOutMessage, const string& svToken)
{
nlohmann::json jsRequestBody = nlohmann::json::object();
jsRequestBody["token"] = svToken;
string svRequestBody = jsRequestBody.dump(4);
if (r5net_show_debug->GetBool())
{
DevMsg(eDLL_T::ENGINE, "%s - Sending token connect request to comp-server:\n%s\n", __FUNCTION__, svRequestBody.c_str());
}
httplib::Result htResults = m_HttpClient.Post("/server/byToken", jsRequestBody.dump(4).c_str(), jsRequestBody.dump(4).length(), "application/json");
if (r5net_show_debug->GetBool())
{
DevMsg(eDLL_T::ENGINE, "%s - Comp-server replied with '%d'\n", __FUNCTION__, htResults->status);
}
if (htResults && htResults->status == 200) // STATUS_OK
{
if (!htResults->body.empty())
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (htResults && jsResultBody["success"].is_boolean() && jsResultBody["success"])
{
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;
}
else
{
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<string>();
}
else
{
svOutMessage = "";
}
slOutServer = NetGameServer_t{};
return false;
}
}
}
else
{
if (htResults)
{
if (!htResults->body.empty())
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["err"].is_string())
{
svOutMessage = jsResultBody["err"].get<string>();
}
else
{
svOutMessage = string("Failed to reach comp-server: ") + std::to_string(htResults->status);
}
return false;
}
svOutMessage = string("Failed to reach comp-server: ") + std::to_string(htResults->status);
return false;
}
svOutMessage = "Failed to reach comp-server: Unknown error code";
slOutServer = NetGameServer_t{};
return false;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Checks if client is banned on the comp server.
// Input : svIpAddress -
// nOriginID -
// &svOutErrCl -
// Output : Returns true if banned, false if not banned.
//-----------------------------------------------------------------------------
bool R5Net::Client::GetClientIsBanned(const string& svIpAddress, uint64_t nOriginID, string& svOutErrCl)
{
nlohmann::json jsRequestBody = nlohmann::json::object();
jsRequestBody["oid"] = nOriginID;
jsRequestBody["ip"] = svIpAddress;
httplib::Result htResults = m_HttpClient.Post("/banlist/isBanned", jsRequestBody.dump(4).c_str(), jsRequestBody.dump(4).length(), "application/json");
if (htResults && htResults->status == 200)
{
nlohmann::json jsResultBody = nlohmann::json::parse(htResults->body);
if (jsResultBody["success"].is_boolean() && jsResultBody["success"].get<bool>())
{
if (jsResultBody["banned"].is_boolean() && jsResultBody["banned"].get<bool>())
{
svOutErrCl = jsResultBody.value("errCl", "#DISCONNECT_BANNED");
return true;
}
}
}
return false;
}
///////////////////////////////////////////////////////////////////////////////
R5Net::Client* g_pR5net(new R5Net::Client("127.0.0.1:3000"));

@ -1,26 +0,0 @@
#pragma once
#include "serverlisting.h"
namespace R5Net
{
class Client
{
public:
Client(string serverString) : m_HttpClient(serverString.c_str())
{
m_HttpClient.set_connection_timeout(10);
}
vector<NetGameServer_t> GetServersList(string& svOutMessage);
bool PostServerHost(string& svOutMessage, string& svOutToken, const NetGameServer_t& slServerListing);
bool GetServerByToken(NetGameServer_t& slOutServer, string& svOutMessage, const string& svToken);
bool GetClientIsBanned(const string& svIpAddress, uint64_t nOriginID, string& svOutErrCl);
Client* pR5net = nullptr;
Client* GetR5Net() { return pR5net; }
private:
httplib::Client m_HttpClient;
};
}
extern R5Net::Client* g_pR5net;

@ -21,7 +21,7 @@
#include "squirrel/sqtype.h"
#include "squirrel/sqapi.h"
#include "squirrel/sqinit.h"
#include "networksystem/r5net.h"
#include "networksystem/pylon.h"
#ifndef DEDICATED
#include "gameui/IBrowser.h" // TODO: create dedicated class for exposing server utils to ImGui and UI VM.
@ -286,7 +286,7 @@ namespace VSquirrel
string svToken = sq_getstring(v, 1);
NetGameServer_t svListing;
bool result = g_pR5net->GetServerByToken(svListing, svHiddenServerRequestMessage, svToken); // Send szToken connect request.
bool result = g_pMasterServer->GetServerByToken(svListing, svHiddenServerRequestMessage, svToken); // Send szToken connect request.
if (result)
{
g_pBrowser->ConnectToServer(svListing.m_svIpAddress, svListing.m_svGamePort, svListing.m_svEncryptionKey);
@ -304,7 +304,7 @@ namespace VSquirrel
string svToken = sq_getstring(v, 1);
NetGameServer_t serverListing;
bool result = g_pR5net->GetServerByToken(serverListing, svHiddenServerRequestMessage, svToken); // Send token connect request.
bool result = g_pMasterServer->GetServerByToken(serverListing, svHiddenServerRequestMessage, svToken); // Send token connect request.
if (!serverListing.m_svHostName.empty())
{
svHiddenServerRequestMessage = "Found Server: " + serverListing.m_svHostName;

@ -147,8 +147,10 @@ void ConVar::Init(void) const
net_tracePayload = new ConVar("net_tracePayload" , "0", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT , "Log the payload of the send/recv datagram to a file on the disk.", false, 0.f, false, 0.f, nullptr, nullptr);
net_encryptionEnable = new ConVar("net_encryptionEnable" , "1", FCVAR_DEVELOPMENTONLY | FCVAR_REPLICATED , "Use AES encryption on game packets.", false, 0.f, false, 0.f, nullptr, nullptr);
net_useRandomKey = new ConVar("net_useRandomKey" , "1" , FCVAR_RELEASE , "Use random base64 netkey for game packets.", false, 0.f, false, 0.f, nullptr, nullptr);
r5net_matchmaking_hostname = new ConVar("r5net_matchmaking_hostname", "127.0.0.1:3000" , FCVAR_RELEASE , "Holds the R5Net matchmaking hostname.", false, 0.f, false, 0.f, nullptr, nullptr);
r5net_show_debug = new ConVar("r5net_show_debug" , "0" , FCVAR_DEVELOPMENTONLY, "Shows debug output for R5Net.", false, 0.f, false, 0.f, nullptr, nullptr);
//-------------------------------------------------------------------------
// NETWORKSYSTEM |
pylon_matchmaking_hostname = new ConVar("pylon_matchmaking_hostname", "127.0.0.1:3000" , FCVAR_RELEASE , "Holds the pylon matchmaking hostname.", false, 0.f, false, 0.f, nullptr, nullptr);
pylon_showdebug = new ConVar("pylon_showdebug" , "0" , FCVAR_DEVELOPMENTONLY, "Shows debug output for pylon.", false, 0.f, false, 0.f, nullptr, nullptr);
//-------------------------------------------------------------------------
// RTECH API |
//-------------------------------------------------------------------------

@ -126,8 +126,8 @@ ConVar* net_tracePayload = nullptr;
ConVar* net_encryptionEnable = nullptr;
ConVar* net_useRandomKey = nullptr;
ConVar* net_usesocketsforloopback = nullptr;
ConVar* r5net_matchmaking_hostname = nullptr;
ConVar* r5net_show_debug = nullptr;
ConVar* pylon_matchmaking_hostname = nullptr;
ConVar* pylon_showdebug = nullptr;
//-----------------------------------------------------------------------------
// RTECH API |
//-----------------------------------------------------------------------------

@ -123,8 +123,8 @@ extern ConVar* net_tracePayload;
extern ConVar* net_encryptionEnable;
extern ConVar* net_useRandomKey;
extern ConVar* net_usesocketsforloopback;
extern ConVar* r5net_matchmaking_hostname;
extern ConVar* r5net_show_debug;
extern ConVar* pylon_matchmaking_hostname;
extern ConVar* pylon_showdebug;
//-------------------------------------------------------------------------
// RTECH API |
//-------------------------------------------------------------------------

@ -64,7 +64,6 @@
<ClCompile Include="..\mathlib\sha1.cpp" />
<ClCompile Include="..\mathlib\sha256.cpp" />
<ClCompile Include="..\networksystem\pylon.cpp" />
<ClCompile Include="..\networksystem\r5net.cpp" />
<ClCompile Include="..\protoc\cl_rcon.pb.cc">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
@ -198,7 +197,6 @@
<ClInclude Include="..\mathlib\vector.h" />
<ClInclude Include="..\milessdk\win64_rrthreads.h" />
<ClInclude Include="..\networksystem\pylon.h" />
<ClInclude Include="..\networksystem\r5net.h" />
<ClInclude Include="..\networksystem\serverlisting.h" />
<ClInclude Include="..\networksystem\sm_protocol.h" />
<ClInclude Include="..\protoc\cl_rcon.pb.h" />

@ -303,9 +303,6 @@
<ClCompile Include="..\mathlib\IceKey.cpp">
<Filter>sdk\mathlib</Filter>
</ClCompile>
<ClCompile Include="..\networksystem\r5net.cpp">
<Filter>sdk\networksystem</Filter>
</ClCompile>
<ClCompile Include="..\squirrel\sqinit.cpp">
<Filter>sdk\squirrel</Filter>
</ClCompile>
@ -959,9 +956,6 @@
<ClInclude Include="..\mathlib\IceKey.H">
<Filter>sdk\mathlib</Filter>
</ClInclude>
<ClInclude Include="..\networksystem\r5net.h">
<Filter>sdk\networksystem</Filter>
</ClInclude>
<ClInclude Include="..\networksystem\serverlisting.h">
<Filter>sdk\networksystem</Filter>
</ClInclude>

@ -195,7 +195,6 @@
<ClInclude Include="..\mathlib\swap.h" />
<ClInclude Include="..\mathlib\vector.h" />
<ClInclude Include="..\networksystem\pylon.h" />
<ClInclude Include="..\networksystem\r5net.h" />
<ClInclude Include="..\networksystem\serverlisting.h" />
<ClInclude Include="..\networksystem\sm_protocol.h" />
<ClInclude Include="..\protoc\cl_rcon.pb.h" />
@ -484,7 +483,6 @@
<ClCompile Include="..\mathlib\sha1.cpp" />
<ClCompile Include="..\mathlib\sha256.cpp" />
<ClCompile Include="..\networksystem\pylon.cpp" />
<ClCompile Include="..\networksystem\r5net.cpp" />
<ClCompile Include="..\protoc\cl_rcon.pb.cc">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>

@ -573,9 +573,6 @@
<ClInclude Include="..\windows\console.h">
<Filter>windows</Filter>
</ClInclude>
<ClInclude Include="..\networksystem\r5net.h">
<Filter>sdk\networksystem</Filter>
</ClInclude>
<ClInclude Include="..\mathlib\IceKey.H">
<Filter>sdk\mathlib</Filter>
</ClInclude>
@ -1193,9 +1190,6 @@
<ClCompile Include="..\windows\console.cpp">
<Filter>windows</Filter>
</ClCompile>
<ClCompile Include="..\networksystem\r5net.cpp">
<Filter>sdk\networksystem</Filter>
</ClCompile>
<ClCompile Include="..\mathlib\IceKey.cpp">
<Filter>sdk\mathlib</Filter>
</ClCompile>

@ -70,7 +70,6 @@
<ClCompile Include="..\mathlib\sha1.cpp" />
<ClCompile Include="..\mathlib\sha256.cpp" />
<ClCompile Include="..\networksystem\pylon.cpp" />
<ClCompile Include="..\networksystem\r5net.cpp" />
<ClCompile Include="..\protoc\cl_rcon.pb.cc">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
@ -214,7 +213,6 @@
<ClInclude Include="..\mathlib\vector.h" />
<ClInclude Include="..\milessdk\win64_rrthreads.h" />
<ClInclude Include="..\networksystem\pylon.h" />
<ClInclude Include="..\networksystem\r5net.h" />
<ClInclude Include="..\networksystem\serverlisting.h" />
<ClInclude Include="..\networksystem\sm_protocol.h" />
<ClInclude Include="..\protoc\cl_rcon.pb.h" />

@ -318,9 +318,6 @@
<ClCompile Include="..\mathlib\IceKey.cpp">
<Filter>sdk\mathlib</Filter>
</ClCompile>
<ClCompile Include="..\networksystem\r5net.cpp">
<Filter>sdk\networksystem</Filter>
</ClCompile>
<ClCompile Include="..\squirrel\sqinit.cpp">
<Filter>sdk\squirrel</Filter>
</ClCompile>
@ -995,9 +992,6 @@
<ClInclude Include="..\mathlib\IceKey.H">
<Filter>sdk\mathlib</Filter>
</ClInclude>
<ClInclude Include="..\networksystem\r5net.h">
<Filter>sdk\networksystem</Filter>
</ClInclude>
<ClInclude Include="..\networksystem\serverlisting.h">
<Filter>sdk\networksystem</Filter>
</ClInclude>