LucidCube/src/RCONServer.h
Rebekah Rowe 6c4b2e9186
Implement GPL3+ and Apache2.0 Dual License.
Commit is being made to allow additions of GPL3+ code previously
un-addable. With these changes, contributions back to cuberite are
possible with the backporting exemtion, as well as adding stuff in
minetest with minetest code properly being read through and implimented
to upgrade it to GPL3 from GPL2.

project still has Apache2.0 license and credits to all its contributers, but now has the freedom of GPL3+ and all the code that can be implimented and shared with it.
2023-03-20 11:49:56 -04:00

113 lines
2.7 KiB
C++

/*
* Copyright 2011-2022 Cuberite Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// RCONServer.h
// Declares the cRCONServer class representing the RCON server
#pragma once
#include "OSSupport/Network.h"
// fwd:
class cServer;
class cSettingsRepositoryInterface;
class cRCONServer
{
public:
cRCONServer(cServer & a_Server);
virtual ~cRCONServer();
void Initialize(cSettingsRepositoryInterface & a_Settings);
protected:
friend class cRCONCommandOutput;
friend class cRCONListenCallbacks;
class cConnection :
public cTCPLink::cCallbacks
{
public:
cConnection(cRCONServer & a_RCONServer, const AString & a_IPAddress);
protected:
friend class cRCONCommandOutput;
/** Set to true if the client has successfully authenticated */
bool m_IsAuthenticated;
/** Buffer for the incoming data */
AString m_Buffer;
/** Server that owns this connection and processes requests */
cRCONServer & m_RCONServer;
/** The TCP link to the client */
cTCPLinkPtr m_Link;
/** Address of the client */
AString m_IPAddress;
// cTCPLink::cCallbacks overrides:
virtual void OnLinkCreated(cTCPLinkPtr a_Link) override;
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;
/** 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);
/** Reads 4 bytes from a_Buffer and returns the LE UInt32 they represent */
UInt32 UIntFromBuffer(const char * a_Buffer);
/** Puts 4 bytes representing the int into the buffer */
void UIntToBuffer(UInt32 a_Value, char * a_Buffer);
/** Sends a RCON packet back to the client */
void SendResponse(UInt32 a_RequestID, UInt32 a_PacketType, UInt32 a_PayloadLength, const char * a_Payload);
} ;
/** The server object that will process the commands received */
cServer & m_Server;
/** The sockets for accepting RCON connections (one socket per port). */
cServerHandlePtrs m_ListenServers;
/** Password for authentication */
AString m_Password;
} ;