summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-01-25 16:33:49 +0100
committerMattes D <github@xoft.cz>2015-01-27 14:53:33 +0100
commit13091e0fa0339a7e84b6a9e75cc91c96de0eae2b (patch)
treed5ea9123e960cc1db2f68d6604faae3e16a2f5ac
parentReplaced atoi() with StringToInteger(). (diff)
downloadcuberite-13091e0fa0339a7e84b6a9e75cc91c96de0eae2b.tar
cuberite-13091e0fa0339a7e84b6a9e75cc91c96de0eae2b.tar.gz
cuberite-13091e0fa0339a7e84b6a9e75cc91c96de0eae2b.tar.bz2
cuberite-13091e0fa0339a7e84b6a9e75cc91c96de0eae2b.tar.lz
cuberite-13091e0fa0339a7e84b6a9e75cc91c96de0eae2b.tar.xz
cuberite-13091e0fa0339a7e84b6a9e75cc91c96de0eae2b.tar.zst
cuberite-13091e0fa0339a7e84b6a9e75cc91c96de0eae2b.zip
-rw-r--r--src/RCONServer.cpp51
-rw-r--r--src/RCONServer.h10
2 files changed, 29 insertions, 32 deletions
diff --git a/src/RCONServer.cpp b/src/RCONServer.cpp
index cd8409367..a02baf761 100644
--- a/src/RCONServer.cpp
+++ b/src/RCONServer.cpp
@@ -82,7 +82,7 @@ class cRCONCommandOutput :
public cCommandOutputCallback
{
public:
- cRCONCommandOutput(cRCONServer::cConnection & a_Connection, int a_RequestID) :
+ cRCONCommandOutput(cRCONServer::cConnection & a_Connection, UInt32 a_RequestID) :
m_Connection(a_Connection),
m_RequestID(a_RequestID)
{
@@ -96,13 +96,13 @@ public:
virtual void Finished(void) override
{
- m_Connection.SendResponse(m_RequestID, RCON_PACKET_RESPONSE, (int)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:
cRCONServer::cConnection & m_Connection;
- int m_RequestID;
+ UInt32 m_RequestID;
AString m_Buffer;
} ;
@@ -211,7 +211,7 @@ void cRCONServer::cConnection::OnReceivedData(const char * a_Data, size_t a_Size
// Process the packets in the buffer:
while (m_Buffer.size() >= 14)
{
- int Length = IntFromBuffer(m_Buffer.data());
+ UInt32 Length = UIntFromBuffer(m_Buffer.data());
if (Length > 1500)
{
// Too long, drop the connection
@@ -222,14 +222,14 @@ void cRCONServer::cConnection::OnReceivedData(const char * a_Data, size_t a_Size
m_Link.reset();
return;
}
- if (Length > static_cast<int>(m_Buffer.size() + 4))
+ if (Length > static_cast<Int32>(m_Buffer.size() + 4))
{
// Incomplete packet yet, wait for more data to come
return;
}
- int RequestID = IntFromBuffer(m_Buffer.data() + 4);
- int PacketType = IntFromBuffer(m_Buffer.data() + 8);
+ UInt32 RequestID = UIntFromBuffer(m_Buffer.data() + 4);
+ UInt32 PacketType = UIntFromBuffer(m_Buffer.data() + 8);
if (!ProcessPacket(RequestID, PacketType, Length - 10, m_Buffer.data() + 12))
{
m_Link->Close();
@@ -263,7 +263,7 @@ void cRCONServer::cConnection::OnError(int a_ErrorCode, const AString & a_ErrorM
-bool cRCONServer::cConnection::ProcessPacket(int a_RequestID, int a_PacketType, int 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)
{
@@ -272,7 +272,7 @@ bool cRCONServer::cConnection::ProcessPacket(int a_RequestID, int a_PacketType,
if (strncmp(a_Payload, m_RCONServer.m_Password.c_str(), a_PayloadLength) != 0)
{
LOGINFO("RCON: Invalid password from client %s, dropping connection.", m_IPAddress.c_str());
- SendResponse(-1, RCON_PACKET_RESPONSE, 0, nullptr);
+ SendResponse(0xffffffffU, RCON_PACKET_RESPONSE, 0, nullptr);
return false;
}
m_IsAuthenticated = true;
@@ -314,23 +314,22 @@ bool cRCONServer::cConnection::ProcessPacket(int a_RequestID, int a_PacketType,
-/// Reads 4 bytes from a_Buffer and returns the int they represent
-int cRCONServer::cConnection::IntFromBuffer(const char * a_Buffer)
+UInt32 cRCONServer::cConnection::UIntFromBuffer(const char * a_Buffer)
{
- return ((unsigned char)a_Buffer[3] << 24) | ((unsigned char)a_Buffer[2] << 16) | ((unsigned char)a_Buffer[1] << 8) | (unsigned char)a_Buffer[0];
+ const Byte * Buffer = reinterpret_cast<const Byte *>(a_Buffer);
+ return (Buffer[3] << 24) | (Buffer[2] << 16) | (Buffer[1] << 8) | Buffer[0];
}
-/// Puts 4 bytes representing the int into the buffer
-void cRCONServer::cConnection::IntToBuffer(int a_Value, char * a_Buffer)
+void cRCONServer::cConnection::UIntToBuffer(UInt32 a_Value, char * a_Buffer)
{
- a_Buffer[0] = a_Value & 0xff;
- a_Buffer[1] = (a_Value >> 8) & 0xff;
- a_Buffer[2] = (a_Value >> 16) & 0xff;
- a_Buffer[3] = (a_Value >> 24) & 0xff;
+ a_Buffer[0] = static_cast<char>(a_Value & 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);
}
@@ -338,19 +337,17 @@ void cRCONServer::cConnection::IntToBuffer(int a_Value, char * a_Buffer)
/// Sends a RCON packet back to the client
-void cRCONServer::cConnection::SendResponse(int a_RequestID, int a_PacketType, int 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);
- char Buffer[4];
- int Length = a_PayloadLength + 10;
- IntToBuffer(Length, Buffer);
- m_Link->Send(Buffer, 4);
- IntToBuffer(a_RequestID, Buffer);
- m_Link->Send(Buffer, 4);
- IntToBuffer(a_PacketType, Buffer);
- m_Link->Send(Buffer, 4);
+ char Buffer[12];
+ UInt32 Length = a_PayloadLength + 10;
+ UIntToBuffer(Length, Buffer);
+ UIntToBuffer(a_RequestID, Buffer + 4);
+ UIntToBuffer(a_PacketType, Buffer + 8);
+ m_Link->Send(Buffer, 12);
if (a_PayloadLength > 0)
{
m_Link->Send(a_Payload, a_PayloadLength);
diff --git a/src/RCONServer.h b/src/RCONServer.h
index 1d599b279..352fa7b50 100644
--- a/src/RCONServer.h
+++ b/src/RCONServer.h
@@ -67,16 +67,16 @@ protected:
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(int a_RequestID, int a_PacketType, int a_PayloadLength, const char * a_Payload);
+ bool ProcessPacket(UInt32 a_RequestID, UInt32 a_PacketType, UInt32 a_PayloadLength, const char * a_Payload);
- /** Reads 4 bytes from a_Buffer and returns the int they represent */
- int IntFromBuffer(const char * a_Buffer);
+ /** 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 IntToBuffer(int a_Value, char * a_Buffer);
+ void UIntToBuffer(UInt32 a_Value, char * a_Buffer);
/** Sends a RCON packet back to the client */
- void SendResponse(int a_RequestID, int a_PacketType, int a_PayloadLength, const char * a_Payload);
+ void SendResponse(UInt32 a_RequestID, UInt32 a_PacketType, UInt32 a_PayloadLength, const char * a_Payload);
} ;