diff options
Diffstat (limited to 'src/RCONServer.cpp')
-rw-r--r-- | src/RCONServer.cpp | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/src/RCONServer.cpp b/src/RCONServer.cpp index 64ddfb4eb..d2336ac50 100644 --- a/src/RCONServer.cpp +++ b/src/RCONServer.cpp @@ -16,8 +16,8 @@ // Disable MSVC warnings: #if defined(_MSC_VER) - #pragma warning(push) - #pragma warning(disable:4355) // 'this' : used in base member initializer list +#pragma warning(push) +#pragma warning(disable : 4355) // 'this' : used in base member initializer list #endif @@ -28,11 +28,11 @@ enum { // Client -> Server: RCON_PACKET_COMMAND = 2, - RCON_PACKET_LOGIN = 3, + RCON_PACKET_LOGIN = 3, // Server -> Client: RCON_PACKET_RESPONSE = 2, -} ; +}; @@ -41,17 +41,15 @@ enum //////////////////////////////////////////////////////////////////////////////// // cRCONListenCallbacks: -class cRCONListenCallbacks: - public cNetwork::cListenCallbacks +class cRCONListenCallbacks : public cNetwork::cListenCallbacks { -public: - cRCONListenCallbacks(cRCONServer & a_RCONServer, UInt16 a_Port): - m_RCONServer(a_RCONServer), - m_Port(a_Port) + public: + cRCONListenCallbacks(cRCONServer & a_RCONServer, UInt16 a_Port) : + m_RCONServer(a_RCONServer), m_Port(a_Port) { } -protected: + protected: /** The RCON server instance that we're attached to. */ cRCONServer & m_RCONServer; @@ -59,7 +57,8 @@ protected: UInt16 m_Port; // cNetwork::cListenCallbacks overrides: - virtual cTCPLink::cCallbacksPtr OnIncomingConnection(const AString & a_RemoteIPAddress, UInt16 a_RemotePort) override + virtual cTCPLink::cCallbacksPtr OnIncomingConnection(const AString & a_RemoteIPAddress, UInt16 a_RemotePort) + override { LOG("RCON Client \"%s\" connected!", a_RemoteIPAddress.c_str()); return std::make_shared<cRCONServer::cConnection>(m_RCONServer, a_RemoteIPAddress); @@ -78,33 +77,29 @@ protected: //////////////////////////////////////////////////////////////////////////////// // cRCONCommandOutput: -class cRCONCommandOutput : - public cCommandOutputCallback +class cRCONCommandOutput : public cCommandOutputCallback { -public: + public: cRCONCommandOutput(cRCONServer::cConnection & a_Connection, UInt32 a_RequestID) : - m_Connection(a_Connection), - m_RequestID(a_RequestID) + m_Connection(a_Connection), m_RequestID(a_RequestID) { } // cCommandOutputCallback overrides: - virtual void Out(const AString & a_Text) override - { - m_Buffer.append(a_Text); - } + virtual void Out(const AString & a_Text) override { m_Buffer.append(a_Text); } virtual void Finished(void) override { - m_Connection.SendResponse(m_RequestID, RCON_PACKET_RESPONSE, static_cast<UInt32>(m_Buffer.size()), m_Buffer.c_str()); + m_Connection + .SendResponse(m_RequestID, RCON_PACKET_RESPONSE, static_cast<UInt32>(m_Buffer.size()), m_Buffer.c_str()); delete this; } -protected: + protected: cRCONServer::cConnection & m_Connection; UInt32 m_RequestID; AString m_Buffer; -} ; +}; @@ -124,7 +119,7 @@ cRCONServer::cRCONServer(cServer & a_Server) : cRCONServer::~cRCONServer() { - for (const auto & srv: m_ListenServers) + for (const auto & srv : m_ListenServers) { srv->Close(); } @@ -153,7 +148,7 @@ void cRCONServer::Initialize(cSettingsRepositoryInterface & a_Settings) AStringVector Ports = ReadUpgradeIniPorts(a_Settings, "RCON", "Ports", "PortsIPv4", "PortsIPv6", "25575"); // Start listening on each specified port: - for (const auto & port: Ports) + for (const auto & port : Ports) { UInt16 PortNum; if (!StringToInteger(port, PortNum)) @@ -182,9 +177,7 @@ void cRCONServer::Initialize(cSettingsRepositoryInterface & a_Settings) // cRCONServer::cConnection: cRCONServer::cConnection::cConnection(cRCONServer & a_RCONServer, const AString & a_IPAddress) : - m_IsAuthenticated(false), - m_RCONServer(a_RCONServer), - m_IPAddress(a_IPAddress) + m_IsAuthenticated(false), m_RCONServer(a_RCONServer), m_IPAddress(a_IPAddress) { } @@ -215,8 +208,10 @@ void cRCONServer::cConnection::OnReceivedData(const char * a_Data, size_t a_Size if (Length > 1500) { // Too long, drop the connection - LOGWARNING("Received an invalid RCON packet length (%d), dropping RCON connection to %s.", - Length, m_IPAddress.c_str() + LOGWARNING( + "Received an invalid RCON packet length (%d), dropping RCON connection to %s.", + Length, + m_IPAddress.c_str() ); m_Link->Close(); m_Link.reset(); @@ -228,7 +223,7 @@ void cRCONServer::cConnection::OnReceivedData(const char * a_Data, size_t a_Size return; } - UInt32 RequestID = UIntFromBuffer(m_Buffer.data() + 4); + UInt32 RequestID = UIntFromBuffer(m_Buffer.data() + 4); UInt32 PacketType = UIntFromBuffer(m_Buffer.data() + 8); if (!ProcessPacket(RequestID, PacketType, Length - 10, m_Buffer.data() + 12)) { @@ -263,7 +258,12 @@ void cRCONServer::cConnection::OnError(int a_ErrorCode, const AString & a_ErrorM -bool cRCONServer::cConnection::ProcessPacket(UInt32 a_RequestID, UInt32 a_PacketType, UInt32 a_PayloadLength, const char * a_Payload) +bool cRCONServer::cConnection::ProcessPacket( + UInt32 a_RequestID, + UInt32 a_PacketType, + UInt32 a_PayloadLength, + const char * a_Payload +) { switch (a_PacketType) { @@ -304,8 +304,10 @@ bool cRCONServer::cConnection::ProcessPacket(UInt32 a_RequestID, UInt32 a_Packet } // Unknown packet type, drop the connection: - LOGWARNING("RCON: Client at %s has sent an unknown packet type %d, dropping connection.", - m_IPAddress.c_str(), a_PacketType + LOGWARNING( + "RCON: Client at %s has sent an unknown packet type %d, dropping connection.", + m_IPAddress.c_str(), + a_PacketType ); return false; } @@ -327,7 +329,7 @@ UInt32 cRCONServer::cConnection::UIntFromBuffer(const char * a_Buffer) void cRCONServer::cConnection::UIntToBuffer(UInt32 a_Value, char * a_Buffer) { a_Buffer[0] = static_cast<char>(a_Value & 0xff); - a_Buffer[1] = static_cast<char>((a_Value >> 8) & 0xff); + a_Buffer[1] = static_cast<char>((a_Value >> 8) & 0xff); a_Buffer[2] = static_cast<char>((a_Value >> 16) & 0xff); a_Buffer[3] = static_cast<char>((a_Value >> 24) & 0xff); } @@ -336,7 +338,12 @@ void cRCONServer::cConnection::UIntToBuffer(UInt32 a_Value, char * a_Buffer) -void cRCONServer::cConnection::SendResponse(UInt32 a_RequestID, UInt32 a_PacketType, UInt32 a_PayloadLength, const char * a_Payload) +void cRCONServer::cConnection::SendResponse( + UInt32 a_RequestID, + UInt32 a_PacketType, + UInt32 a_PayloadLength, + const char * a_Payload +) { ASSERT((a_PayloadLength == 0) || (a_Payload != nullptr)); // Either zero data to send, or a valid payload ptr ASSERT(m_Link != nullptr); @@ -353,7 +360,3 @@ void cRCONServer::cConnection::SendResponse(UInt32 a_RequestID, UInt32 a_PacketT } m_Link->Send("\0", 2); // Send two zero chars as the padding } - - - - |