aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/sv_rcon.h
blob: 8d89c615b67184a701c456d3e1cd9e5953f64665 (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
#pragma once
#include "NetAdr2.h"
#include "socketcreator.h"
#include "sv_rcon.pb.h"
#include "cl_rcon.pb.h"
#include "igameserverdata.h"

constexpr char s_pszNoAuthMessage[] =
	"This server is password protected for console access. Authenticate with 'PASS <password>' command.\n";
constexpr char s_pszWrongPwMessage[] = "Admin password incorrect.\n";
constexpr char s_pszBannedMessage[] = "Go away.\n";
constexpr char s_pszAuthMessage[] = "RCON authentication successfull.\n";

class CRConServer
{
  public:
	CRConServer();
	~CRConServer();

	void Init(void);
	void Shutdown(void);
	bool SetPassword(const char* pszPassword);

	void Think(void);
	void RunFrame(void);

	void Send(const std::string& svMessage) const;
	void Send(SocketHandle_t hSocket, const std::string& svMessage) const;
	void Recv(void);

	std::string Serialize(const std::string& svRspBuf, const std::string& svRspVal, sv_rcon::response_t response_t) const;
	cl_rcon::request Deserialize(const std::string& svBuf) const;

	void Authenticate(const cl_rcon::request& cl_request, CConnectedNetConsoleData* pData);
	bool Comparator(std::string svPassword) const;

	void ProcessBuffer(const char* pszIn, int nRecvLen, CConnectedNetConsoleData* pData);
	void ProcessMessage(const cl_rcon::request& cl_request);

	void Execute(const cl_rcon::request& cl_request, bool bConVar) const;
	bool CheckForBan(CConnectedNetConsoleData* pData);

	void CloseConnection(void);
	void CloseNonAuthConnection(void);

  private:
	bool m_bInitialized;
	int m_nConnIndex;
	CNetAdr2* m_pAdr2;
	CSocketCreator* m_pSocket;
	std::vector<std::string> m_vBannedAddress;
	std::string m_svPasswordHash;
};
extern CRConServer* g_pRConServer;
CRConServer* RCONServer();