mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
This patch splits host logic from CServerListManager. CServerListManager is actually meant for the client to manage the server list to which the client could connect to. The hosting logic has been moved to the new CServerHostManager class. Previously, we stored all the hosting details in CServerListManager, with connection criteria in CPylon, this data has been moved over to CServerHostManager as well. Previously, we also needed a mutex to access the server host data, function HostState_KeepAlive() has been refactored to the point this mutex is no longer necessary as the only threaded process is the actual request, the rest is being applied in the main thread. We also now only construct a NetGameServer_t struct if we actually plan to host. Access to CPylon::m_Language is now also protected by a mutex, as the change callback of cvar 'language' and the threaded method 'CPylon::QueryServer()' are competing for access.
57 lines
2.1 KiB
C++
57 lines
2.1 KiB
C++
#pragma once
|
|
#include "thirdparty/curl/include/curl/curl.h"
|
|
#include "bansystem.h"
|
|
#include "serverlisting.h"
|
|
#include "localize/ilocalize.h"
|
|
|
|
extern ConVar pylon_matchmaking_hostname;
|
|
extern ConVar pylon_host_update_interval;
|
|
extern ConVar pylon_showdebuginfo;
|
|
|
|
struct MSEulaData_t
|
|
{
|
|
int version;
|
|
string language;
|
|
string contents;
|
|
};
|
|
|
|
class CPylon
|
|
{
|
|
public:
|
|
CPylon() { SetLanguage(g_LanguageNames[0]); }
|
|
|
|
bool GetServerList(vector<NetGameServer_t>& outServerList, string& outMessage) const;
|
|
bool GetServerByToken(NetGameServer_t& slOutServer, string& outMessage, const string& svToken) const;
|
|
bool PostServerHost(string& outMessage, string& svOutToken, string& outHostIp, const NetGameServer_t& netGameServer) const;
|
|
|
|
bool GetBannedList(const CBanSystem::BannedList_t& inBannedVec, CBanSystem::BannedList_t& outBannedVec) const;
|
|
bool CheckForBan(const string& ipAddress, const uint64_t nucleusId, const string& personaName, string& outReason) const;
|
|
|
|
bool AuthForConnection(const uint64_t nucleusId, const char* ipAddress, const char* authCode, string& outToken, string& outMessage) const;
|
|
|
|
bool GetEULA(MSEulaData_t& outData, string& outMessage) const;
|
|
|
|
void ExtractError(const rapidjson::Document& resultBody, string& outMessage, CURLINFO status, const char* errorText = nullptr) const;
|
|
void ExtractError(const string& response, string& outMessage, CURLINFO status, const char* messageText = nullptr) const;
|
|
|
|
void LogBody(const rapidjson::Document& responseJson) const;
|
|
bool SendRequest(const char* endpoint, const rapidjson::Document& requestJson, rapidjson::Document& responseJson, string& outMessage, CURLINFO& status, const char* errorText = nullptr, const bool checkEula = true) const;
|
|
bool QueryServer(const char* endpoint, const char* request, string& outResponse, string& outMessage, CURLINFO& outStatus) const;
|
|
|
|
inline void SetLanguage(const char* lang)
|
|
{
|
|
AUTO_LOCK(m_StringMutex);
|
|
m_Language = lang;
|
|
};
|
|
inline const string& GetLanguage() const
|
|
{
|
|
AUTO_LOCK(m_StringMutex);
|
|
return m_Language;
|
|
};
|
|
|
|
private:
|
|
string m_Language;
|
|
mutable CThreadFastMutex m_StringMutex;
|
|
};
|
|
extern CPylon g_MasterServer;
|