Kawe Mazidjatari 909977452e Client token authentication implementation
The game internally obtains a auth token from Origin. On connect to a gameserver, it will send it to the masterserver. The master server will create a JWT token and send this back to the client. The client stores this token in 3 userinfo cvars (token, sig1, sig2). the sig1 and sig2 cvars are there to compensate for the truncation caused by sending the cvar, as each cvar string length could be up to 255 (byte max). The server verifies this token (the signature, timestamp, expiry); if they are valid, the has successfully authenticated and will connect.
2024-04-05 16:24:45 +02:00

47 lines
2.1 KiB
C++

#pragma once
#include "thirdparty/curl/include/curl/curl.h"
#include "bansystem.h"
#include "serverlisting.h"
#include "localize/ilocalize.h"
class CPylon
{
public:
CPylon() { m_Language = g_LanguageNames[0]; }
vector<NetGameServer_t> GetServerList(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;
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 QueryServer(const char* endpoint, const char* request, string& outResponse, string& outMessage, CURLINFO& outStatus) const;
inline const string& GetCurrentToken() const { return m_Token; }
inline const string& GetCurrentError() const { return m_ErrorMsg; }
inline const string& GetHostIP() const { return m_HostIP; };
inline void SetCurrentToken(const string& token) { m_Token = token; }
inline void SetCurrentError(const string& error) { m_ErrorMsg = error; }
inline void SetHostIP(const string& ip) { m_HostIP = ip; };
inline void SetLanguage(const char* lang) { m_Language = lang; };
private:
string m_Token;
string m_ErrorMsg;
string m_HostIP;
string m_Language;
};
extern CPylon* g_pMasterServer;