2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
// RCONServer.h
|
|
|
|
|
|
|
|
// Declares the cRCONServer class representing the RCON server
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
#include "OSSupport/Network.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fwd:
|
|
|
|
class cServer;
|
2015-05-14 10:47:51 -04:00
|
|
|
class cSettingsRepositoryInterface;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
class cRCONServer
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
cRCONServer(cServer & a_Server);
|
2014-03-28 16:35:45 -04:00
|
|
|
virtual ~cRCONServer();
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2015-05-14 10:47:51 -04:00
|
|
|
void Initialize(cSettingsRepositoryInterface & a_Settings);
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class cRCONCommandOutput;
|
2015-01-24 07:31:42 -05:00
|
|
|
friend class cRCONListenCallbacks;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
class cConnection :
|
2015-01-24 07:31:42 -05:00
|
|
|
public cTCPLink::cCallbacks
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
public:
|
2015-01-24 07:31:42 -05:00
|
|
|
cConnection(cRCONServer & a_RCONServer, const AString & a_IPAddress);
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class cRCONCommandOutput;
|
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
/** Set to true if the client has successfully authenticated */
|
2013-07-29 07:13:03 -04:00
|
|
|
bool m_IsAuthenticated;
|
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
/** Buffer for the incoming data */
|
2013-07-29 07:13:03 -04:00
|
|
|
AString m_Buffer;
|
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
/** Server that owns this connection and processes requests */
|
2013-07-29 07:13:03 -04:00
|
|
|
cRCONServer & m_RCONServer;
|
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
/** The TCP link to the client */
|
|
|
|
cTCPLinkPtr m_Link;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
/** Address of the client */
|
2013-07-29 07:13:03 -04:00
|
|
|
AString m_IPAddress;
|
|
|
|
|
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
// cTCPLink::cCallbacks overrides:
|
2015-05-23 07:56:08 -04:00
|
|
|
virtual void OnLinkCreated(cTCPLinkPtr a_Link) override;
|
2015-01-24 07:31:42 -05:00
|
|
|
virtual void OnReceivedData(const char * a_Data, size_t a_Length) override;
|
|
|
|
virtual void OnRemoteClosed(void) override;
|
|
|
|
virtual void OnError(int a_ErrorCode, const AString & a_ErrorMsg) override;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
/** Processes the given packet and sends the response; returns true if successful, false if the connection is to be dropped */
|
2015-01-25 10:33:49 -05:00
|
|
|
bool ProcessPacket(UInt32 a_RequestID, UInt32 a_PacketType, UInt32 a_PayloadLength, const char * a_Payload);
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2015-01-25 10:33:49 -05:00
|
|
|
/** Reads 4 bytes from a_Buffer and returns the LE UInt32 they represent */
|
|
|
|
UInt32 UIntFromBuffer(const char * a_Buffer);
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
/** Puts 4 bytes representing the int into the buffer */
|
2015-01-25 10:33:49 -05:00
|
|
|
void UIntToBuffer(UInt32 a_Value, char * a_Buffer);
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
/** Sends a RCON packet back to the client */
|
2015-01-25 10:33:49 -05:00
|
|
|
void SendResponse(UInt32 a_RequestID, UInt32 a_PacketType, UInt32 a_PayloadLength, const char * a_Payload);
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
/** The server object that will process the commands received */
|
2013-07-29 07:13:03 -04:00
|
|
|
cServer & m_Server;
|
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
/** The sockets for accepting RCON connections (one socket per port). */
|
|
|
|
cServerHandlePtrs m_ListenServers;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2015-01-24 07:31:42 -05:00
|
|
|
/** Password for authentication */
|
2013-07-29 07:13:03 -04:00
|
|
|
AString m_Password;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|