r5sdk/r5dev/engine/server/sv_rcon.h
Kawe Mazidjatari 88b3336758 Many small code improvements and optimizations
* Use c++ methods as much as possible.
* Use enum types for accessing NavMesh objects from array.
* Use size_t for for loops when testing against size types.
* Don't compute strlen twice of more on the same string.
* Don't use unnecessary c string casts if there is a method with a std::string overload.
* Don't create string objects from string pointers if we could use them directly.
* Don't initialize RCON password twice on each change, and don't set if the new password equals the old.
2022-08-11 11:07:45 +02:00

56 lines
1.8 KiB
C++

#pragma once
#include "tier1/NetAdr2.h"
#include "tier2/socketcreator.h"
#include "protoc/sv_rcon.pb.h"
#include "protoc/cl_rcon.pb.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(void);
~CRConServer(void);
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, int nResponseId = -4) 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);
bool IsInitialized(void) const;
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();