Files
cuberite-2a/src/RCONServer.h
T

97 lines
2.1 KiB
C++
Raw Normal View History

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