aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/server/auth/serverauthentication.h
blob: 4ffbbfd643d411aef937fd2f81b9c74e1922ee3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
#include "core/convar/convar.h"
#include "httplib.h"
#include "engine/r2engine.h"
#include <unordered_map>
#include <string>

struct RemoteAuthData
{
	char uid[33];
	char username[64];

	// pdata
	char* pdata;
	size_t pdataSize;
};

struct PlayerAuthenticationData
{
	bool usingLocalPdata;
	size_t pdataSize;
	bool needPersistenceWriteOnLeave = true;
};

typedef int64_t (*CBaseServer__RejectConnectionType)(void* a1, unsigned int a2, void* a3, const char* a4, ...);
extern CBaseServer__RejectConnectionType CBaseServer__RejectConnection;

class ServerAuthenticationManager
{
  private:
	httplib::Server m_PlayerAuthServer;

  public:
	ConVar* Cvar_ns_player_auth_port;
	ConVar* Cvar_ns_erase_auth_info;
	ConVar* CVar_ns_auth_allow_insecure;
	ConVar* CVar_ns_auth_allow_insecure_write;

	std::mutex m_AuthDataMutex;
	std::unordered_map<std::string, RemoteAuthData> m_RemoteAuthenticationData;
	std::unordered_map<R2::CBaseClient*, PlayerAuthenticationData> m_PlayerAuthenticationData;
	bool m_bAllowDuplicateAccounts = false;
	bool m_bRunningPlayerAuthThread = false;
	bool m_bNeedLocalAuthForNewgame = false;
	bool m_bForceResetLocalPlayerPersistence = false;

  public:
	void StartPlayerAuthServer();
	void StopPlayerAuthServer();
	void AddPlayer(R2::CBaseClient* player, const char* pToken);
	void RemovePlayer(R2::CBaseClient* player);
	bool CheckDuplicateAccounts(R2::CBaseClient* player);
	bool AuthenticatePlayer(R2::CBaseClient* player, uint64_t uid, char* authToken);
	bool VerifyPlayerName(const char* authToken, const char* name);
	bool RemovePlayerAuthData(R2::CBaseClient* player);
	void WritePersistentData(R2::CBaseClient* player);
};

extern ServerAuthenticationManager* g_pServerAuthentication;