1
0
Fork 0
cuberite-2a/src/RCONServer.h

97 lines
2.1 KiB
C
Raw Normal View History

// RCONServer.h
// Declares the cRCONServer class representing the RCON server
#pragma once
2015-01-24 12:31:42 +00:00
#include "OSSupport/Network.h"
// fwd:
class cServer;
class cSettingsRepositoryInterface;
2015-01-24 12:31:42 +00:00
class cRCONServer
{
public:
cRCONServer(cServer & a_Server);
virtual ~cRCONServer();
2016-02-05 21:45:45 +00:00
void Initialize(cSettingsRepositoryInterface & a_Settings);
2016-02-05 21:45:45 +00:00
protected:
friend class cRCONCommandOutput;
2015-01-24 12:31:42 +00:00
friend class cRCONListenCallbacks;
2016-02-05 21:45:45 +00:00
class cConnection :
2015-01-24 12:31:42 +00:00
public cTCPLink::cCallbacks
{
public:
2015-01-24 12:31:42 +00:00
cConnection(cRCONServer & a_RCONServer, const AString & a_IPAddress);
2016-02-05 21:45:45 +00:00
protected:
friend class cRCONCommandOutput;
2016-02-05 21:45:45 +00:00
2015-01-24 12:31:42 +00:00
/** Set to true if the client has successfully authenticated */
bool m_IsAuthenticated;
2016-02-05 21:45:45 +00:00
2015-01-24 12:31:42 +00:00
/** Buffer for the incoming data */
AString m_Buffer;
2016-02-05 21:45:45 +00:00
2015-01-24 12:31:42 +00:00
/** Server that owns this connection and processes requests */
cRCONServer & m_RCONServer;
2016-02-05 21:45:45 +00:00
2015-01-24 12:31:42 +00:00
/** The TCP link to the client */
cTCPLinkPtr m_Link;
2016-02-05 21:45:45 +00:00
2015-01-24 12:31:42 +00:00
/** Address of the client */
AString m_IPAddress;
2016-02-05 21:45:45 +00:00
2015-01-24 12:31:42 +00:00
// cTCPLink::cCallbacks overrides:
virtual void OnLinkCreated(cTCPLinkPtr a_Link) override;
2015-01-24 12:31:42 +00: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;
2016-02-05 21:45:45 +00:00
2015-01-24 12:31:42 +00:00
/** Processes the given packet and sends the response; returns true if successful, false if the connection is to be dropped */
bool ProcessPacket(UInt32 a_RequestID, UInt32 a_PacketType, UInt32 a_PayloadLength, const char * a_Payload);
2016-02-05 21:45:45 +00:00
/** Reads 4 bytes from a_Buffer and returns the LE UInt32 they represent */
UInt32 UIntFromBuffer(const char * a_Buffer);
2016-02-05 21:45:45 +00:00
2015-01-24 12:31:42 +00:00
/** Puts 4 bytes representing the int into the buffer */
void UIntToBuffer(UInt32 a_Value, char * a_Buffer);
2016-02-05 21:45:45 +00:00
2015-01-24 12:31:42 +00:00
/** Sends a RCON packet back to the client */
void SendResponse(UInt32 a_RequestID, UInt32 a_PacketType, UInt32 a_PayloadLength, const char * a_Payload);
} ;
2016-02-05 21:45:45 +00:00
2015-01-24 12:31:42 +00:00
/** The server object that will process the commands received */
cServer & m_Server;
2016-02-05 21:45:45 +00:00
2015-01-24 12:31:42 +00:00
/** The sockets for accepting RCON connections (one socket per port). */
cServerHandlePtrs m_ListenServers;
2016-02-05 21:45:45 +00:00
2015-01-24 12:31:42 +00:00
/** Password for authentication */
AString m_Password;
} ;