20 #pragma warning(disable:4355) // 'this' : used in base member initializer list 64 LOG(
"RCON Client \"%s\" connected!", a_RemoteIPAddress.c_str());
65 return std::make_shared<cRCONServer::cConnection>(
m_RCONServer, a_RemoteIPAddress);
70 LOGWARNING(
"RCON server error on port %d: %d (%s)", m_Port, a_ErrorCode, a_ErrorMsg.c_str());
86 m_Connection(a_Connection),
87 m_RequestID(a_RequestID)
94 m_Buffer.append(a_Text);
99 m_Connection.SendResponse(m_RequestID,
RCON_PACKET_RESPONSE, static_cast<UInt32>(m_Buffer.size()), m_Buffer.c_str());
148 LOGWARNING(
"RCON is requested, but the password is not set. RCON is now disabled.");
156 for (
auto port: Ports)
161 LOGINFO(
"Invalid RCON port value: \"%s\". Ignoring.", port.c_str());
164 auto Handle =
cNetwork::Listen(PortNum, std::make_shared<cRCONListenCallbacks>(*
this, PortNum));
165 if (Handle->IsListening())
173 LOGWARNING(
"RCON is enabled but no valid ports were found. RCON is not accessible.");
185 m_IsAuthenticated(false),
186 m_RCONServer(a_RCONServer),
187 m_IPAddress(a_IPAddress)
218 LOGWARNING(
"Received an invalid RCON packet length (%d), dropping RCON connection to %s.",
225 if (Length > static_cast<UInt32>(
m_Buffer.size() + 4))
258 LOGD(
"Error in RCON connection %s: %d (%s)",
m_IPAddress.c_str(), a_ErrorCode, a_ErrorMsg.c_str());
268 switch (a_PacketType)
274 LOGINFO(
"RCON: Invalid password from client %s, dropping connection.",
m_IPAddress.c_str());
280 LOGD(
"RCON: Client at %s has successfully authenticated",
m_IPAddress.c_str());
291 char AuthNeeded[] =
"You need to authenticate first!";
296 AString cmd(a_Payload, a_PayloadLength);
297 LOGD(
"RCON command from %s: \"%s\"",
m_IPAddress.c_str(), cmd.c_str());
307 LOGWARNING(
"RCON: Client at %s has sent an unknown packet type %d, dropping connection.",
319 const Byte * Buffer =
reinterpret_cast<const Byte *
>(a_Buffer);
320 return static_cast<UInt32>((Buffer[3] << 24) | (Buffer[2] << 16) | (Buffer[1] << 8) | Buffer[0]);
329 a_Buffer[0] =
static_cast<char>(a_Value & 0xff);
330 a_Buffer[1] =
static_cast<char>((a_Value >> 8) & 0xff);
331 a_Buffer[2] =
static_cast<char>((a_Value >> 16) & 0xff);
332 a_Buffer[3] =
static_cast<char>((a_Value >> 24) & 0xff);
341 ASSERT((a_PayloadLength == 0) || (a_Payload !=
nullptr));
345 UInt32 Length = a_PayloadLength + 10;
350 if (a_PayloadLength > 0)
352 m_Link->Send(a_Payload, a_PayloadLength);
void ExecuteConsoleCommand(const AString &a_Cmd, cCommandOutputCallback &a_Output)
Executes a console command through the cServer class; does special handling for "stop" and "restart"...
AString m_Password
Password for authentication.
cServerHandlePtrs m_ListenServers
The sockets for accepting RCON connections (one socket per port).
bool StringToInteger(const AString &a_str, T &a_Num)
Parses any integer type.
virtual void Out(const AString &a_Text) override
Called when the command wants to output anything; may be called multiple times.
bool ProcessPacket(UInt32 a_RequestID, UInt32 a_PacketType, UInt32 a_PayloadLength, const char *a_Payload)
Processes the given packet and sends the response; returns true if successful, false if the connectio...
cRCONServer & m_RCONServer
Server that owns this connection and processes requests.
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
Called when the socket fails to listen on the specified port.
virtual cTCPLink::cCallbacksPtr OnIncomingConnection(const AString &a_RemoteIPAddress, UInt16 a_RemotePort) override
Called when the TCP server created with Listen() receives a new incoming connection.
void UIntToBuffer(UInt32 a_Value, char *a_Buffer)
Puts 4 bytes representing the int into the buffer.
cRCONServer(cServer &a_Server)
virtual void OnAccepted(cTCPLink &a_Link) override
Called when the TCP server created with Listen() creates a new link for an incoming connection...
cRCONServer & m_RCONServer
The RCON server instance that we're attached to.
cTCPLinkPtr m_Link
The TCP link to the client.
std::vector< AString > AStringVector
cRCONServer::cConnection & m_Connection
virtual void OnRemoteClosed(void) override
Called when the remote end closes the connection.
virtual void OnReceivedData(const char *a_Data, size_t a_Length) override
Called when there's data incoming from the remote peer.
AString m_Buffer
Buffer for the incoming data.
virtual void OnLinkCreated(cTCPLinkPtr a_Link) override
Called when the cTCPLink for the connection is created.
cRCONListenCallbacks(cRCONServer &a_RCONServer, UInt16 a_Port)
std::shared_ptr< cTCPLink > cTCPLinkPtr
void LOGINFO(const char *a_Format, fmt::ArgList a_ArgList)
void LOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
virtual AString GetValueSet(const AString &keyname, const AString &valuename, const AString &defValue="")=0
Gets the value; if not found, write the default to the repository.
cConnection(cRCONServer &a_RCONServer, const AString &a_IPAddress)
std::shared_ptr< cCallbacks > cCallbacksPtr
Callbacks used when listening for incoming connections as a server.
virtual bool GetValueSetB(const AString &keyname, const AString &valuename, const bool defValue=false)=0
virtual void Finished(void) override
Called when the command processing has been finished.
void Initialize(cSettingsRepositoryInterface &a_Settings)
void LOG(const char *a_Format, fmt::ArgList a_ArgList)
UInt16 m_Port
The port for which this instance is responsible.
static cServerHandlePtr Listen(UInt16 a_Port, cListenCallbacksPtr a_ListenCallbacks)
Opens up the specified port for incoming connections.
Interface that provides the methods available on a single TCP connection.
AString m_IPAddress
Address of the client.
cRCONCommandOutput(cRCONServer::cConnection &a_Connection, UInt32 a_RequestID)
AStringVector ReadUpgradeIniPorts(cSettingsRepositoryInterface &a_Settings, const AString &a_KeyName, const AString &a_PortsValueName, const AString &a_OldIPv4ValueName, const AString &a_OldIPv6ValueName, const AString &a_DefaultValue)
Reads the list of ports from the INI file, possibly upgrading from IPv4 / IPv6-specific values into n...
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
Called when an error is detected on the connection.
bool m_IsAuthenticated
Set to true if the client has successfully authenticated.
UInt32 UIntFromBuffer(const char *a_Buffer)
Reads 4 bytes from a_Buffer and returns the LE UInt32 they represent.
Interface for a callback that receives command output The Out() function is called for any output the...
void SendResponse(UInt32 a_RequestID, UInt32 a_PacketType, UInt32 a_PayloadLength, const char *a_Payload)
Sends a RCON packet back to the client.
friend class cRCONCommandOutput