aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/serverauthentication.h
blob: 02429f48fd756b0ab74ae6d2f13ca194381dc17d (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
#pragma once
#include "convar.h"
#include "httplib.h"
#include <unordered_map>
#include <string>

struct AuthData
{
	char uid[33];

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

struct AdditionalPlayerData
{
	bool usingLocalPdata;
	size_t pdataSize;
	bool needPersistenceWriteOnLeave = true;

	double lastClientCommandQuotaStart = 0;
	int numClientCommandsInQuota = 0;

	double lastNetChanProcessingLimitStart = -1.0;
	double netChanProcessingLimitTime = 0;
};

class ServerAuthenticationManager
{
private:
	httplib::Server m_playerAuthServer;

public:
	std::mutex m_authDataMutex;
	std::unordered_map<std::string, AuthData> m_authData;
	std::unordered_map<void*, AdditionalPlayerData> m_additionalPlayerData;
	bool m_runningPlayerAuthThread = false;
	bool m_bNeedLocalAuthForNewgame = false;

public:
	void StartPlayerAuthServer();
	void StopPlayerAuthServer();
	bool AuthenticatePlayer(void* player, int64_t uid, char* authToken);
	bool RemovePlayerAuthData(void* player);
	void WritePersistentData(void* player);
};

void InitialiseServerAuthentication(HMODULE baseAddress);

extern ServerAuthenticationManager* g_ServerAuthenticationManager;
extern ConVar* Cvar_ns_player_auth_port;