r5sdk/r5dev/engine/server/sv_rcon.h
Kawe Mazidjatari 179bd31ee6 Initial large refactor of the RCON implementation
* Decoding and encoding is done into a single buffer, from raw buffers to avoid extraneous copies.
* Added base class holding all core logic for encoding, decoding, receiving and processing of the RCON protocol. This code was initially identical between all implementations of RCON, deduplicating this avoids bugs.
* Added more sophisticated error handling, stop right away when decoding for example fails.
* Added ability to have more than one active authenticated net console on the server. Controlled by cvar 'sv_rcon_maxconnections' (default 1).
* Max packet size for accepted, but not authenticated sockets is now controled by cvar 'sv_rcon_maxpacketsize' (default 1024).
2023-04-19 01:35:31 +02:00

60 lines
2.1 KiB
C++

#pragma once
#include "tier1/NetAdr.h"
#include "tier2/socketcreator.h"
#include "protoc/sv_rcon.pb.h"
#include "protoc/cl_rcon.pb.h"
#include "engine/shared/base_rcon.h"
#define RCON_MIN_PASSWORD_LEN 8
#define RCON_MAX_BANNEDLIST_SIZE 512
class CRConServer : public CNetConBase
{
public:
CRConServer(void);
~CRConServer(void);
void Init(void);
void Shutdown(void);
bool SetPassword(const char* pszPassword);
bool SetWhiteListAddress(const char* pszAddress);
void Think(void);
void RunFrame(void);
bool SendEncode(const char* pResponseMsg, const char* pResponseVal, const sv_rcon::response_t responseType,
const int nMessageId = static_cast<int>(eDLL_T::NETCON), const int nMessageType = static_cast<int>(LogType_t::LOG_NET)) const;
bool SendEncode(const SocketHandle_t hSocket, const char* pResponseMsg, const char* pResponseVal, const sv_rcon::response_t responseType,
const int nMessageId = static_cast<int>(eDLL_T::NETCON), const int nMessageType = static_cast<int>(LogType_t::LOG_NET)) const;
bool SendToAll(const char* pMsgBuf, int nMsgLen) const;
bool Serialize(vector<char>& vecBuf, const char* pResponseMsg, const char* pResponseVal, const sv_rcon::response_t responseType,
const int nMessageId = static_cast<int>(eDLL_T::NETCON), const int nMessageType = static_cast<int>(LogType_t::LOG_NET)) const;
void Authenticate(const cl_rcon::request& cl_request, CConnectedNetConsoleData* pData);
bool Comparator(std::string svPassword) const;
virtual bool ProcessMessage(const char* pMsgBug, int nMsgLen) override;
void Execute(const cl_rcon::request& cl_request, const bool bConVar) const;
bool CheckForBan(CConnectedNetConsoleData* pData);
virtual void Disconnect(const char* szReason = nullptr) override;
void CloseNonAuthConnection(void);
bool ShouldSend(const sv_rcon::response_t responseType) const;
bool IsInitialized(void) const;
private:
int m_nConnIndex;
int m_nAuthConnections;
bool m_bInitialized;
std::unordered_set<std::string> m_BannedList;
std::string m_svPasswordHash;
netadr_t m_WhiteListAddress;
};
CRConServer* RCONServer();