From c836b52dd1b8d6a2999721f235e6c2b6079b266c Mon Sep 17 00:00:00 2001 From: Masy98 Date: Thu, 18 Dec 2014 19:30:32 +0100 Subject: Added Entity Guardian --- Tools/AnvilStats/Utils.cpp | 1 + Tools/AnvilStats/Utils.h | 1 + 2 files changed, 2 insertions(+) (limited to 'Tools') diff --git a/Tools/AnvilStats/Utils.cpp b/Tools/AnvilStats/Utils.cpp index d7543cb4c..f5b3b58fb 100644 --- a/Tools/AnvilStats/Utils.cpp +++ b/Tools/AnvilStats/Utils.cpp @@ -26,6 +26,7 @@ struct {entEnderman, "Enderman"}, {entGhast, "Ghast"}, {entGiant, "Giant"}, + {entGuardian, "Guardian"}, {entLavaSlime, "LavaSlime"}, {entMushroomCow, "MushroomCow"}, {entOzelot, "Ozelot"}, diff --git a/Tools/AnvilStats/Utils.h b/Tools/AnvilStats/Utils.h index ab2d7166c..4c4e89f26 100644 --- a/Tools/AnvilStats/Utils.h +++ b/Tools/AnvilStats/Utils.h @@ -25,6 +25,7 @@ enum eEntityType entEnderman, entGhast, entGiant, + entGuardian, entLavaSlime, entMushroomCow, entOzelot, -- cgit v1.2.3 From 6e8e1c6d8da3d5a0f5ca39f6f18d88c2ca6c1e71 Mon Sep 17 00:00:00 2001 From: Masy98 Date: Sat, 20 Dec 2014 10:31:34 +0100 Subject: Added Rabbits --- Tools/AnvilStats/Utils.cpp | 1 + Tools/AnvilStats/Utils.h | 1 + 2 files changed, 2 insertions(+) (limited to 'Tools') diff --git a/Tools/AnvilStats/Utils.cpp b/Tools/AnvilStats/Utils.cpp index f5b3b58fb..34374647b 100644 --- a/Tools/AnvilStats/Utils.cpp +++ b/Tools/AnvilStats/Utils.cpp @@ -32,6 +32,7 @@ struct {entOzelot, "Ozelot"}, {entPig, "Pig"}, {entPigZombie, "PigZombie"}, + {entRabbit, "Rabbit"}, {entSheep, "Sheep"}, {entSilverfish, "Slverfish"}, {entSkeleton, "Skeleton"}, diff --git a/Tools/AnvilStats/Utils.h b/Tools/AnvilStats/Utils.h index 4c4e89f26..e3172649c 100644 --- a/Tools/AnvilStats/Utils.h +++ b/Tools/AnvilStats/Utils.h @@ -31,6 +31,7 @@ enum eEntityType entOzelot, entPig, entPigZombie, + entRabbit, entSheep, entSilverfish, entSkeleton, -- cgit v1.2.3 From f5b4c92a10a6e196d9487083672e91fbe60a12fd Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 21 Dec 2014 22:50:32 +0100 Subject: MCADefrag: Added a sanity check for chunk size. Fixes CID 66448. --- Tools/MCADefrag/MCADefrag.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Tools') diff --git a/Tools/MCADefrag/MCADefrag.cpp b/Tools/MCADefrag/MCADefrag.cpp index d5d233fd2..0d38a87f1 100644 --- a/Tools/MCADefrag/MCADefrag.cpp +++ b/Tools/MCADefrag/MCADefrag.cpp @@ -269,7 +269,7 @@ bool cMCADefrag::cThread::ReadChunk(cFile & a_File, const Byte * a_LocationRaw) return false; } m_CompressedChunkDataSize = (Buf[0] << 24) | (Buf[1] << 16) | (Buf[2] << 8) | Buf[3]; - if (m_CompressedChunkDataSize > SizeInSectors) + if ((m_CompressedChunkDataSize > SizeInSectors) || (m_CompressedChunkDataSize < 0)) { LOGWARNING("Invalid chunk data - SizeInSectors (%d) smaller that RealSize (%d)", SizeInSectors, m_CompressedChunkDataSize); return false; -- cgit v1.2.3 From 557dc5a93f04798474e7ca114a47f7c379547f94 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 21 Dec 2014 22:51:17 +0100 Subject: ProtoProxy: Added a sanity check to metadata string lengths. Fixes CID 66415. --- Tools/ProtoProxy/Connection.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Tools') diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index fb2d40e5b..468529124 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -2687,7 +2687,7 @@ bool cConnection::ParseSlot(cByteBuffer & a_Buffer, AString & a_ItemDesc) char ItemCount; short ItemDamage; short MetadataLength; - a_Buffer.ReadChar(ItemCount); + a_Buffer.ReadChar(ItemCount); // We already know we can read these bytes - we checked before. a_Buffer.ReadBEShort(ItemDamage); a_Buffer.ReadBEShort(MetadataLength); Printf(a_ItemDesc, "%d:%d * %d", ItemType, ItemDamage, ItemCount); @@ -2846,7 +2846,11 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount) bb.Write(a_Metadata.data() + pos + 1, RestLen); UInt32 Length; int rs = bb.GetReadableSpace(); - bb.ReadVarInt(Length); + if (!bb.ReadVarInt(Length)) + { + Log("Invalid metadata value, was supposed to be a varint-prefixed string, but cannot read the varint"); + break; + } rs = rs - bb.GetReadableSpace(); Log("%sstring[%d] = \"%*s\"", Indent.c_str(), Index, Length, a_Metadata.c_str() + pos + rs + 1); pos += Length + rs + 2; -- cgit v1.2.3 From 7d35e84578488769c4ee515568bd5f9ed7ef0dac Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 25 Dec 2014 08:47:35 +0100 Subject: Fixed tools compilation. Fixes errors introduced in 081e7ddd028d9382bd52c2b117dae6b6f84225e5. --- Tools/MCADefrag/CMakeLists.txt | 2 ++ Tools/MCADefrag/Globals.h | 1 + Tools/ProtoProxy/CMakeLists.txt | 2 ++ 3 files changed, 5 insertions(+) (limited to 'Tools') diff --git a/Tools/MCADefrag/CMakeLists.txt b/Tools/MCADefrag/CMakeLists.txt index 82e048671..700310edc 100644 --- a/Tools/MCADefrag/CMakeLists.txt +++ b/Tools/MCADefrag/CMakeLists.txt @@ -53,6 +53,7 @@ source_group("Shared" FILES ${SHARED_SRC} ${SHARED_HDR}) set(SHARED_OSS_SRC ../../src/OSSupport/CriticalSection.cpp + ../../src/OSSupport/Event.cpp ../../src/OSSupport/File.cpp ../../src/OSSupport/IsThread.cpp ../../src/OSSupport/StackTrace.cpp @@ -60,6 +61,7 @@ set(SHARED_OSS_SRC set(SHARED_OSS_HDR ../../src/OSSupport/CriticalSection.h + ../../src/OSSupport/Event.h ../../src/OSSupport/File.h ../../src/OSSupport/IsThread.h ../../src/OSSupport/StackTrace.h diff --git a/Tools/MCADefrag/Globals.h b/Tools/MCADefrag/Globals.h index 288069599..f13a06566 100644 --- a/Tools/MCADefrag/Globals.h +++ b/Tools/MCADefrag/Globals.h @@ -201,6 +201,7 @@ typedef unsigned char Byte; // Common headers (without macros): #include "StringUtils.h" #include "OSSupport/CriticalSection.h" +#include "OSSupport/Event.h" #include "OSSupport/IsThread.h" #include "OSSupport/File.h" diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt index cca0c1b8b..132a14f78 100644 --- a/Tools/ProtoProxy/CMakeLists.txt +++ b/Tools/ProtoProxy/CMakeLists.txt @@ -55,12 +55,14 @@ set(SHARED_HDR ) set(SHARED_OSS_SRC ../../src/OSSupport/CriticalSection.cpp + ../../src/OSSupport/Event.cpp ../../src/OSSupport/File.cpp ../../src/OSSupport/IsThread.cpp ../../src/OSSupport/StackTrace.cpp ) set(SHARED_OSS_HDR ../../src/OSSupport/CriticalSection.h + ../../src/OSSupport/Event.h ../../src/OSSupport/File.h ../../src/OSSupport/IsThread.h ../../src/OSSupport/StackTrace.h -- cgit v1.2.3 From 9e4528793ac49d9b1e61bfa02dd472c875ed6e99 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 25 Dec 2014 17:15:37 +0100 Subject: ProtoProxy: Log block change packet details. --- Tools/ProtoProxy/Connection.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Tools') diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index 468529124..d42afb7ba 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -1392,6 +1392,9 @@ bool cConnection::HandleServerBlockChange(void) HANDLE_SERVER_PACKET_READ(ReadVarInt, UInt32, BlockType); HANDLE_SERVER_PACKET_READ(ReadChar, char, BlockMeta); Log("Received a PACKET_BLOCK_CHANGE from the server"); + Log(" Pos = {%d, %d, %d}", BlockX, BlockY, BlockZ); + Log(" BlockType = %d (0x%x", BlockType, BlockType); + Log(" BlockMeta = %d", BlockMeta); COPY_TO_CLIENT(); return true; } -- cgit v1.2.3 From b3335518302014d20cf4b8c9a08f851cec07c809 Mon Sep 17 00:00:00 2001 From: Matyas Dolak Date: Wed, 21 Jan 2015 11:24:32 +0100 Subject: ProtoProxy: Fixed warnings in Connection.cpp. --- Tools/ProtoProxy/Connection.cpp | 38 +++++++++++++++++++++++--------------- Tools/ProtoProxy/Connection.h | 2 +- 2 files changed, 24 insertions(+), 16 deletions(-) (limited to 'Tools') diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index d42afb7ba..1f88f4b6e 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -141,8 +141,14 @@ typedef unsigned char Byte; +// fwd declarations, to avoid clang warnings: +AString PrintableAbsIntTriplet(int a_X, int a_Y, int a_Z, double a_Divisor = 32); -AString PrintableAbsIntTriplet(int a_X, int a_Y, int a_Z, double a_Divisor = 32) + + + + +AString PrintableAbsIntTriplet(int a_X, int a_Y, int a_Z, double a_Divisor) { return Printf("<%d, %d, %d> ~ {%.02f, %.02f, %.02f}", a_X, a_Y, a_Z, @@ -298,7 +304,7 @@ void cConnection::Log(const char * a_Format, ...) -void cConnection::DataLog(const void * a_Data, int a_Size, const char * a_Format, ...) +void cConnection::DataLog(const void * a_Data, size_t a_Size, const char * a_Format, ...) { va_list args; va_start(args, a_Format); @@ -359,14 +365,14 @@ bool cConnection::ConnectToServer(void) bool cConnection::RelayFromServer(void) { char Buffer[64 KiB]; - int res = recv(m_ServerSocket, Buffer, sizeof(Buffer), 0); + int res = static_cast(recv(m_ServerSocket, Buffer, sizeof(Buffer), 0)); // recv returns int on windows, ssize_t on linux if (res <= 0) { Log("Server closed the socket: %d; %d; aborting connection", res, SocketError); return false; } - DataLog(Buffer, res, "Received %d bytes from the SERVER", res); + DataLog(Buffer, static_cast(res), "Received %d bytes from the SERVER", res); switch (m_ServerState) { @@ -377,15 +383,15 @@ bool cConnection::RelayFromServer(void) } case csEncryptedUnderstood: { - m_ServerDecryptor.ProcessData((Byte *)Buffer, (Byte *)Buffer, res); + m_ServerDecryptor.ProcessData(reinterpret_cast(Buffer), reinterpret_cast(Buffer), static_cast(res)); DataLog(Buffer, res, "Decrypted %d bytes from the SERVER", res); return DecodeServersPackets(Buffer, res); } case csEncryptedUnknown: { - m_ServerDecryptor.ProcessData((Byte *)Buffer, (Byte *)Buffer, res); + m_ServerDecryptor.ProcessData(reinterpret_cast(Buffer), reinterpret_cast(Buffer), static_cast(res)); DataLog(Buffer, res, "Decrypted %d bytes from the SERVER", res); - return CLIENTSEND(Buffer, res); + return CLIENTSEND(Buffer, static_cast(res)); } } ASSERT(!"Unhandled server state while relaying from server"); @@ -399,7 +405,7 @@ bool cConnection::RelayFromServer(void) bool cConnection::RelayFromClient(void) { char Buffer[64 KiB]; - int res = recv(m_ClientSocket, Buffer, sizeof(Buffer), 0); + int res = static_cast(recv(m_ClientSocket, Buffer, sizeof(Buffer), 0)); // recv returns int on Windows, ssize_t on Linux if (res <= 0) { Log("Client closed the socket: %d; %d; aborting connection", res, SocketError); @@ -422,8 +428,8 @@ bool cConnection::RelayFromClient(void) case csEncryptedUnknown: { DataLog(Buffer, res, "Decrypted %d bytes from the CLIENT", res); - m_ServerEncryptor.ProcessData((Byte *)Buffer, (Byte *)Buffer, res); - return SERVERSEND(Buffer, res); + m_ServerEncryptor.ProcessData(reinterpret_cast(Buffer), reinterpret_cast(Buffer), static_cast(res)); + return SERVERSEND(Buffer, static_cast(res)); } } ASSERT(!"Unhandled server state while relaying from client"); @@ -446,9 +452,9 @@ double cConnection::GetRelativeTime(void) bool cConnection::SendData(SOCKET a_Socket, const char * a_Data, size_t a_Size, const char * a_Peer) { - DataLog(a_Data, a_Size, "Sending data to %s, %u bytes", a_Peer, (unsigned)a_Size); + DataLog(a_Data, a_Size, "Sending data to %s, %u bytes", a_Peer, static_cast(a_Size)); - int res = send(a_Socket, a_Data, (int)a_Size, 0); + int res = send(a_Socket, a_Data, a_Size, 0); // Windows uses int for a_Size, Linux uses size_t; but Windows doesn't complain if (res <= 0) { Log("%s closed the socket: %d, %d; aborting connection", a_Peer, res, SocketError); @@ -511,7 +517,7 @@ bool cConnection::SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Enc bool cConnection::DecodeClientsPackets(const char * a_Data, int a_Size) { - if (!m_ClientBuffer.Write(a_Data, a_Size)) + if (!m_ClientBuffer.Write(a_Data, static_cast(a_Size))) { Log("Too much queued data for the server, aborting connection"); return false; @@ -529,10 +535,12 @@ bool cConnection::DecodeClientsPackets(const char * a_Data, int a_Size) break; } UInt32 PacketType, PacketReadSoFar; - PacketReadSoFar = m_ClientBuffer.GetReadableSpace(); + PacketReadSoFar = static_cast(m_ClientBuffer.GetReadableSpace()); VERIFY(m_ClientBuffer.ReadVarInt(PacketType)); PacketReadSoFar -= m_ClientBuffer.GetReadableSpace(); - Log("Decoding client's packets, there are now %d bytes in the queue; next packet is 0x%0x, %u bytes long", m_ClientBuffer.GetReadableSpace(), PacketType, PacketLen); + Log("Decoding client's packets, there are now %u bytes in the queue; next packet is 0x%02x, %u bytes long", + static_cast(m_ClientBuffer.GetReadableSpace()), PacketType, PacketLen + ); switch (m_ClientProtocolState) { case -1: diff --git a/Tools/ProtoProxy/Connection.h b/Tools/ProtoProxy/Connection.h index c79273f8a..8aacaaa7f 100644 --- a/Tools/ProtoProxy/Connection.h +++ b/Tools/ProtoProxy/Connection.h @@ -58,7 +58,7 @@ public: void Run(void); void Log(const char * a_Format, ...); - void DataLog(const void * a_Data, int a_Size, const char * a_Format, ...); + void DataLog(const void * a_Data, size_t a_Size, const char * a_Format, ...); void LogFlush(void); protected: -- cgit v1.2.3 From dc5ab256a54d193ace30fb9ceee6b0f4262e1e6d Mon Sep 17 00:00:00 2001 From: Matyas Dolak Date: Wed, 21 Jan 2015 14:15:35 +0100 Subject: ProtoProxy: Fixed warnings in Connection.cpp. --- Tools/ProtoProxy/Connection.cpp | 176 ++++++++++++++++++++-------------------- 1 file changed, 89 insertions(+), 87 deletions(-) (limited to 'Tools') diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index 1f88f4b6e..6d347e07d 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -100,13 +100,11 @@ CLIENTENCRYPTSEND(ToClient.data(), ToClient.size()); \ break; \ } \ - /* case csWaitingForEncryption: \ + case csWaitingForEncryption: \ { \ - Log("Waiting for client encryption, queued %u bytes", ToClient.size()); \ - m_ClientEncryptionBuffer.append(ToClient.data(), ToClient.size()); \ break; \ } \ - */ \ + \ } \ DebugSleep(50); \ } @@ -384,13 +382,13 @@ bool cConnection::RelayFromServer(void) case csEncryptedUnderstood: { m_ServerDecryptor.ProcessData(reinterpret_cast(Buffer), reinterpret_cast(Buffer), static_cast(res)); - DataLog(Buffer, res, "Decrypted %d bytes from the SERVER", res); + DataLog(Buffer, static_cast(res), "Decrypted %d bytes from the SERVER", res); return DecodeServersPackets(Buffer, res); } case csEncryptedUnknown: { m_ServerDecryptor.ProcessData(reinterpret_cast(Buffer), reinterpret_cast(Buffer), static_cast(res)); - DataLog(Buffer, res, "Decrypted %d bytes from the SERVER", res); + DataLog(Buffer, static_cast(res), "Decrypted %d bytes from the SERVER", res); return CLIENTSEND(Buffer, static_cast(res)); } } @@ -412,7 +410,7 @@ bool cConnection::RelayFromClient(void) return false; } - DataLog(Buffer, res, "Received %d bytes from the CLIENT", res); + DataLog(Buffer, static_cast(res), "Received %d bytes from the CLIENT", res); switch (m_ClientState) { @@ -427,7 +425,7 @@ bool cConnection::RelayFromClient(void) } case csEncryptedUnknown: { - DataLog(Buffer, res, "Decrypted %d bytes from the CLIENT", res); + DataLog(Buffer, static_cast(res), "Decrypted %d bytes from the CLIENT", res); m_ServerEncryptor.ProcessData(reinterpret_cast(Buffer), reinterpret_cast(Buffer), static_cast(res)); return SERVERSEND(Buffer, static_cast(res)); } @@ -454,7 +452,7 @@ bool cConnection::SendData(SOCKET a_Socket, const char * a_Data, size_t a_Size, { DataLog(a_Data, a_Size, "Sending data to %s, %u bytes", a_Peer, static_cast(a_Size)); - int res = send(a_Socket, a_Data, a_Size, 0); // Windows uses int for a_Size, Linux uses size_t; but Windows doesn't complain + int res = static_cast(send(a_Socket, a_Data, a_Size, 0)); // Windows uses int for a_Size, Linux uses size_t; but Windows doesn't complain. Return type is int on Windows and ssize_t on Linux if (res <= 0) { Log("%s closed the socket: %d, %d; aborting connection", a_Peer, res, SocketError); @@ -627,7 +625,7 @@ bool cConnection::DecodeClientsPackets(const char * a_Data, int a_Size) bool cConnection::DecodeServersPackets(const char * a_Data, int a_Size) { - if (!m_ServerBuffer.Write(a_Data, a_Size)) + if (!m_ServerBuffer.Write(a_Data, static_cast(a_Size))) { Log("Too much queued data for the client, aborting connection"); return false; @@ -663,7 +661,7 @@ bool cConnection::DecodeServersPackets(const char * a_Data, int a_Size) break; } UInt32 PacketType, PacketReadSoFar; - PacketReadSoFar = m_ServerBuffer.GetReadableSpace(); + PacketReadSoFar = static_cast(m_ServerBuffer.GetReadableSpace()); VERIFY(m_ServerBuffer.ReadVarInt(PacketType)); PacketReadSoFar -= m_ServerBuffer.GetReadableSpace(); Log("Decoding server's packets, there are now %d bytes in the queue; next packet is 0x%0x, %u bytes long", m_ServerBuffer.GetReadableSpace(), PacketType, PacketLen); @@ -1119,7 +1117,7 @@ bool cConnection::HandleClientPlayerPositionLook(void) bool cConnection::HandleClientPluginMessage(void) { HANDLE_CLIENT_PACKET_READ(ReadVarUTF8String, AString, ChannelName); - HANDLE_CLIENT_PACKET_READ(ReadBEShort, short, Length); + HANDLE_CLIENT_PACKET_READ(ReadBEUInt16, UInt16, Length); AString Data; if (!m_ClientBuffer.ReadString(Data, Length)) { @@ -1127,7 +1125,7 @@ bool cConnection::HandleClientPluginMessage(void) } Log("Received a PACKET_PLUGIN_MESSAGE from the client"); Log(" ChannelName = \"%s\"", ChannelName.c_str()); - DataLog(Data.data(), Length, " Data: %d bytes", Length); + DataLog(Data.data(), Length, " Data: %u bytes", Length); COPY_TO_SERVER(); return true; } @@ -1296,13 +1294,13 @@ bool cConnection::HandleServerLoginEncryptionKeyRequest(void) { // Read the packet from the server: HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, ServerID); - HANDLE_SERVER_PACKET_READ(ReadBEShort, short, PublicKeyLength); + HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, PublicKeyLength); AString PublicKey; if (!m_ServerBuffer.ReadString(PublicKey, PublicKeyLength)) { return false; } - HANDLE_SERVER_PACKET_READ(ReadBEShort, short, NonceLength); + HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, NonceLength); AString Nonce; if (!m_ServerBuffer.ReadString(Nonce, NonceLength)) { @@ -1472,12 +1470,12 @@ bool cConnection::HandleServerCompass(void) bool cConnection::HandleServerDestroyEntities(void) { HANDLE_SERVER_PACKET_READ(ReadByte, Byte, NumEntities); - if (!m_ServerBuffer.SkipRead((int)NumEntities * 4)) + if (!m_ServerBuffer.SkipRead(static_cast(NumEntities) * 4)) { return false; } Log("Received PACKET_DESTROY_ENTITIES from the server:"); - Log(" NumEntities = %d", NumEntities); + Log(" NumEntities = %u", NumEntities); COPY_TO_CLIENT(); return true; } @@ -1698,15 +1696,15 @@ bool cConnection::HandleServerEntityVelocity(void) bool cConnection::HandleServerExplosion(void) { - HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PosX); - HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PosY); - HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PosZ); - HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, Force); - HANDLE_SERVER_PACKET_READ(ReadBEInt, int, NumRecords); + HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PosX); + HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PosY); + HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PosZ); + HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, Force); + HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, NumRecords); std::vector Records; Records.reserve(NumRecords); int PosXI = (int)PosX, PosYI = (int)PosY, PosZI = (int)PosZ; - for (int i = 0; i < NumRecords; i++) + for (UInt32 i = 0; i < NumRecords; i++) { HANDLE_SERVER_PACKET_READ(ReadChar, char, rx); HANDLE_SERVER_PACKET_READ(ReadChar, char, ry); @@ -1719,10 +1717,10 @@ bool cConnection::HandleServerExplosion(void) Log("Received a PACKET_EXPLOSION from the server:"); Log(" Pos = {%.02f, %.02f, %.02f}", PosX, PosY, PosZ); Log(" Force = %.02f", Force); - Log(" NumRecords = %d", NumRecords); - for (int i = 0; i < NumRecords; i++) + Log(" NumRecords = %u", NumRecords); + for (UInt32 i = 0; i < NumRecords; i++) { - Log(" Records[%d] = {%d, %d, %d}", i, Records[i].x, Records[i].y, Records[i].z); + Log(" Records[%u] = {%d, %d, %d}", i, Records[i].x, Records[i].y, Records[i].z); } Log(" Player motion = <%.02f, %.02f, %.02f>", PlayerMotionX, PlayerMotionY, PlayerMotionZ); COPY_TO_CLIENT(); @@ -1833,8 +1831,8 @@ bool cConnection::HandleServerKick(void) Reason.append(Split[5]); AString ReasonBE16 = UTF8ToRawBEUTF16(Reason.data(), Reason.size()); AString PacketStart("\xff"); - PacketStart.push_back((ReasonBE16.size() / 2) / 256); - PacketStart.push_back((ReasonBE16.size() / 2) % 256); + PacketStart.push_back(static_cast((ReasonBE16.size() / 2) / 256)); + PacketStart.push_back(static_cast((ReasonBE16.size() / 2) % 256)); CLIENTSEND(PacketStart.data(), PacketStart.size()); CLIENTSEND(ReasonBE16.data(), ReasonBE16.size()); return true; @@ -1858,12 +1856,12 @@ bool cConnection::HandleServerKick(void) bool cConnection::HandleServerMapChunk(void) { - HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkX); - HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkZ); - HANDLE_SERVER_PACKET_READ(ReadChar, char, IsContiguous); - HANDLE_SERVER_PACKET_READ(ReadBEShort, short, PrimaryBitmap); - HANDLE_SERVER_PACKET_READ(ReadBEShort, short, AdditionalBitmap); - HANDLE_SERVER_PACKET_READ(ReadBEInt, int, CompressedSize); + HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkX); + HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkZ); + HANDLE_SERVER_PACKET_READ(ReadChar, char, IsContiguous); + HANDLE_SERVER_PACKET_READ(ReadBEShort, short, PrimaryBitmap); + HANDLE_SERVER_PACKET_READ(ReadBEShort, short, AdditionalBitmap); + HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, CompressedSize); AString CompressedData; if (!m_ServerBuffer.ReadString(CompressedData, CompressedSize)) { @@ -1871,7 +1869,7 @@ bool cConnection::HandleServerMapChunk(void) } Log("Received a PACKET_MAP_CHUNK from the server:"); Log(" ChunkPos = [%d, %d]", ChunkX, ChunkZ); - Log(" Compressed size = %d (0x%x)", CompressedSize, CompressedSize); + Log(" Compressed size = %u (0x%x)", CompressedSize, CompressedSize); // TODO: Save the compressed data into a file for later analysis @@ -1885,9 +1883,9 @@ bool cConnection::HandleServerMapChunk(void) bool cConnection::HandleServerMapChunkBulk(void) { - HANDLE_SERVER_PACKET_READ(ReadBEShort, short, ChunkCount); - HANDLE_SERVER_PACKET_READ(ReadBEInt, int, CompressedSize); - HANDLE_SERVER_PACKET_READ(ReadBool, bool, IsSkyLightSent); + HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, ChunkCount); + HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, CompressedSize); + HANDLE_SERVER_PACKET_READ(ReadBool, bool, IsSkyLightSent); AString CompressedData; if (!m_ServerBuffer.ReadString(CompressedData, CompressedSize)) { @@ -1909,8 +1907,8 @@ bool cConnection::HandleServerMapChunkBulk(void) } Log("Received a PACKET_MAP_CHUNK_BULK from the server:"); - Log(" ChunkCount = %d", ChunkCount); - Log(" Compressed size = %d (0x%x)", CompressedSize, CompressedSize); + Log(" ChunkCount = %u", ChunkCount); + Log(" Compressed size = %u (0x%x)", CompressedSize, CompressedSize); Log(" IsSkyLightSent = %s", IsSkyLightSent ? "true" : "false"); // Log individual chunk coords: @@ -1934,10 +1932,10 @@ bool cConnection::HandleServerMapChunkBulk(void) bool cConnection::HandleServerMultiBlockChange(void) { - HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkX); - HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkZ); - HANDLE_SERVER_PACKET_READ(ReadBEShort, short, NumBlocks); - HANDLE_SERVER_PACKET_READ(ReadBEInt, int, DataSize); + HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkX); + HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkZ); + HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, NumBlocks); + HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, DataSize); AString BlockChangeData; if (!m_ServerBuffer.ReadString(BlockChangeData, DataSize)) { @@ -1945,7 +1943,7 @@ bool cConnection::HandleServerMultiBlockChange(void) } Log("Received a PACKET_MULTI_BLOCK_CHANGE packet from the server:"); Log(" Chunk = [%d, %d]", ChunkX, ChunkZ); - Log(" NumBlocks = %d", NumBlocks); + Log(" NumBlocks = %u", NumBlocks); COPY_TO_CLIENT(); return true; } @@ -2046,7 +2044,7 @@ bool cConnection::HandleServerPlayerPositionLook(void) bool cConnection::HandleServerPluginMessage(void) { HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, ChannelName); - HANDLE_SERVER_PACKET_READ(ReadBEShort, short, Length); + HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, Length); AString Data; if (!m_ServerBuffer.ReadString(Data, Length)) { @@ -2054,7 +2052,7 @@ bool cConnection::HandleServerPluginMessage(void) } Log("Received a PACKET_PLUGIN_MESSAGE from the server"); Log(" ChannelName = \"%s\"", ChannelName.c_str()); - DataLog(Data.data(), Length, " Data: %d bytes", Length); + DataLog(Data.data(), Length, " Data: %u bytes", Length); COPY_TO_CLIENT(); return true; } @@ -2541,11 +2539,11 @@ bool cConnection::HandleServerUpdateSign(void) bool cConnection::HandleServerUpdateTileEntity(void) { - HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BlockX); - HANDLE_SERVER_PACKET_READ(ReadBEShort, short, BlockY); - HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BlockZ); - HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Action); - HANDLE_SERVER_PACKET_READ(ReadBEShort, short, DataLength); + HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BlockX); + HANDLE_SERVER_PACKET_READ(ReadBEShort, short, BlockY); + HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BlockZ); + HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Action); + HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, DataLength); AString Data; if ((DataLength > 0) && !m_ServerBuffer.ReadString(Data, DataLength)) @@ -2559,7 +2557,7 @@ bool cConnection::HandleServerUpdateTileEntity(void) // Save metadata to a file: AString fnam; - Printf(fnam, "%s_item_%08x.nbt", m_LogNameBase.c_str(), m_ItemIdx++); + Printf(fnam, "%s_tile_%08x.nbt", m_LogNameBase.c_str(), m_ItemIdx++); FILE * f = fopen(fnam.c_str(), "wb"); if (f != NULL) { @@ -2697,10 +2695,10 @@ bool cConnection::ParseSlot(cByteBuffer & a_Buffer, AString & a_ItemDesc) } char ItemCount; short ItemDamage; - short MetadataLength; + UInt16 MetadataLength; a_Buffer.ReadChar(ItemCount); // We already know we can read these bytes - we checked before. a_Buffer.ReadBEShort(ItemDamage); - a_Buffer.ReadBEShort(MetadataLength); + a_Buffer.ReadBEUInt16(MetadataLength); Printf(a_ItemDesc, "%d:%d * %d", ItemType, ItemDamage, ItemCount); if (MetadataLength <= 0) { @@ -2708,13 +2706,13 @@ bool cConnection::ParseSlot(cByteBuffer & a_Buffer, AString & a_ItemDesc) } AString Metadata; Metadata.resize(MetadataLength); - if (!a_Buffer.ReadBuf((void *)Metadata.data(), MetadataLength)) + if (!a_Buffer.ReadBuf(const_cast(Metadata.data()), MetadataLength)) { return false; } AString MetaHex; CreateHexDump(MetaHex, Metadata.data(), Metadata.size(), 16); - AppendPrintf(a_ItemDesc, "; %d bytes of meta:\n%s", MetadataLength, MetaHex.c_str()); + AppendPrintf(a_ItemDesc, "; %u bytes of meta:\n%s", MetadataLength, MetaHex.c_str()); // Save metadata to a file: AString fnam; @@ -2736,17 +2734,19 @@ bool cConnection::ParseSlot(cByteBuffer & a_Buffer, AString & a_ItemDesc) bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata) { - char x; - if (!a_Buffer.ReadChar(x)) + Byte x; + if (!a_Buffer.ReadByte(x)) { return false; } - a_Metadata.push_back(x); + a_Metadata.push_back(static_cast(x)); while (x != 0x7f) { - // int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index - int Type = ((unsigned)((unsigned char)x)) >> 5; // Upper 3 bits = type - int Length = 0; + // int Index = static_cast(x) & 0x1f; // Lower 5 bits = index + int Type = static_cast(x) >> 5; // Upper 3 bits = type + + // Get the length of the data for this item: + UInt32 Length = 0; switch (Type) { case 0: Length = 1; break; // Byte @@ -2756,12 +2756,12 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata) case 4: // UTF-8 string with VarInt length { UInt32 Len; - int rs = a_Buffer.GetReadableSpace(); + int rs = static_cast(a_Buffer.GetReadableSpace()); if (!a_Buffer.ReadVarInt(Len)) { return false; } - rs = rs - a_Buffer.GetReadableSpace(); + rs = rs - static_cast(a_Buffer.GetReadableSpace()); cByteBuffer LenBuf(8); LenBuf.WriteVarInt(Len); AString VarLen; @@ -2770,18 +2770,18 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata) Length = Len; break; } - case 5: + case 5: // Item, in "slot" format { - int Before = a_Buffer.GetReadableSpace(); + size_t Before = a_Buffer.GetReadableSpace(); AString ItemDesc; if (!ParseSlot(a_Buffer, ItemDesc)) { return false; } - int After = a_Buffer.GetReadableSpace(); + size_t After = a_Buffer.GetReadableSpace(); a_Buffer.ResetRead(); a_Buffer.SkipRead(a_Buffer.GetReadableSpace() - Before); - Length = Before - After; + Length = static_cast(Before - After); break; } case 6: Length = 12; break; // 3 * int @@ -2792,17 +2792,19 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata) break; } } // switch (Type) + + // Read the data in this item: AString data; if (!a_Buffer.ReadString(data, Length)) { return false; } a_Metadata.append(data); - if (!a_Buffer.ReadChar(x)) + if (!a_Buffer.ReadByte(x)) { return false; } - a_Metadata.push_back(x); + a_Metadata.push_back(static_cast(x)); } // while (x != 0x7f) return true; } @@ -2814,62 +2816,62 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata) void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount) { AString Indent(a_IndentCount, ' '); - int pos = 0; + size_t pos = 0; while (a_Metadata[pos] != 0x7f) { - int Index = ((unsigned)((unsigned char)a_Metadata[pos])) & 0x1f; // Lower 5 bits = index - int Type = ((unsigned)((unsigned char)a_Metadata[pos])) >> 5; // Upper 3 bits = type + unsigned Index = static_cast(static_cast(a_Metadata[pos])) & 0x1f; // Lower 5 bits = index + unsigned Type = static_cast(static_cast(a_Metadata[pos])) >> 5; // Upper 3 bits = type // int Length = 0; switch (Type) { case 0: { - Log("%sbyte[%d] = %d", Indent.c_str(), Index, a_Metadata[pos + 1]); + Log("%sbyte[%u] = %d", Indent.c_str(), Index, a_Metadata[pos + 1]); pos += 1; break; } case 1: { - Log("%sshort[%d] = %d", Indent.c_str(), Index, (a_Metadata[pos + 1] << 8) | a_Metadata[pos + 2]); + Log("%sshort[%u] = %d", Indent.c_str(), Index, (a_Metadata[pos + 1] << 8) | a_Metadata[pos + 2]); pos += 2; break; } case 2: { - Log("%sint[%d] = %d", Indent.c_str(), Index, (a_Metadata[pos + 1] << 24) | (a_Metadata[pos + 2] << 16) | (a_Metadata[pos + 3] << 8) | a_Metadata[pos + 4]); + Log("%sint[%u] = %d", Indent.c_str(), Index, (a_Metadata[pos + 1] << 24) | (a_Metadata[pos + 2] << 16) | (a_Metadata[pos + 3] << 8) | a_Metadata[pos + 4]); pos += 4; break; } case 3: { - Log("%sfloat[%d] = 0x%x", Indent.c_str(), Index, (a_Metadata[pos + 1] << 24) | (a_Metadata[pos + 2] << 16) | (a_Metadata[pos + 3] << 8) | a_Metadata[pos + 4]); + Log("%sfloat[%u] = 0x%x", Indent.c_str(), Index, (a_Metadata[pos + 1] << 24) | (a_Metadata[pos + 2] << 16) | (a_Metadata[pos + 3] << 8) | a_Metadata[pos + 4]); pos += 4; break; } case 4: // UTF-8 string with VarInt length { cByteBuffer bb(10); - int RestLen = (int)a_Metadata.size() - pos - 1; + size_t RestLen = a_Metadata.size() - pos - 1; if (RestLen > 8) { RestLen = 8; } bb.Write(a_Metadata.data() + pos + 1, RestLen); UInt32 Length; - int rs = bb.GetReadableSpace(); + size_t rs = bb.GetReadableSpace(); if (!bb.ReadVarInt(Length)) { Log("Invalid metadata value, was supposed to be a varint-prefixed string, but cannot read the varint"); break; } rs = rs - bb.GetReadableSpace(); - Log("%sstring[%d] = \"%*s\"", Indent.c_str(), Index, Length, a_Metadata.c_str() + pos + rs + 1); + Log("%sstring[%u] = \"%*s\"", Indent.c_str(), Index, Length, a_Metadata.c_str() + pos + rs + 1); pos += Length + rs + 2; break; } case 5: { - int BytesLeft = a_Metadata.size() - pos - 1; + size_t BytesLeft = a_Metadata.size() - pos - 1; cByteBuffer bb(BytesLeft); bb.Write(a_Metadata.data() + pos + 1, BytesLeft); AString ItemDesc; @@ -2878,16 +2880,16 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount) ASSERT(!"Cannot parse item description from metadata"); return; } - // int After = bb.GetReadableSpace(); - int BytesConsumed = BytesLeft - bb.GetReadableSpace(); + // size_t After = bb.GetReadableSpace(); + size_t BytesConsumed = BytesLeft - bb.GetReadableSpace(); - Log("%sslot[%d] = %s (%d bytes)", Indent.c_str(), Index, ItemDesc.c_str(), BytesConsumed); + Log("%sslot[%u] = %s (%u bytes)", Indent.c_str(), Index, ItemDesc.c_str(), static_cast(BytesConsumed)); pos += BytesConsumed; break; } case 6: { - Log("%spos[%d] = <%d, %d, %d>", Indent.c_str(), Index, + Log("%spos[%u] = <%d, %d, %d>", Indent.c_str(), Index, (a_Metadata[pos + 1] << 24) | (a_Metadata[pos + 2] << 16) | (a_Metadata[pos + 3] << 8) | a_Metadata[pos + 4], (a_Metadata[pos + 5] << 24) | (a_Metadata[pos + 6] << 16) | (a_Metadata[pos + 7] << 8) | a_Metadata[pos + 8], (a_Metadata[pos + 9] << 24) | (a_Metadata[pos + 10] << 16) | (a_Metadata[pos + 11] << 8) | a_Metadata[pos + 12] @@ -2946,7 +2948,7 @@ void cConnection::SendEncryptionKeyResponse(const AString & a_ServerPublicKey, c DataLog(EncryptedSecret, sizeof(EncryptedSecret), "Encrypted secret (%u bytes)", (unsigned)sizeof(EncryptedSecret)); DataLog(EncryptedNonce, sizeof(EncryptedNonce), "Encrypted nonce (%u bytes)", (unsigned)sizeof(EncryptedNonce)); cByteBuffer Len(5); - Len.WriteVarInt(ToServer.GetReadableSpace()); + Len.WriteVarInt(static_cast(ToServer.GetReadableSpace())); SERVERSEND(Len); SERVERSEND(ToServer); m_ServerState = csEncryptedUnderstood; -- cgit v1.2.3 From 2b75c8905150b06f94df289ef965145b3fe1087f Mon Sep 17 00:00:00 2001 From: Matyas Dolak Date: Fri, 23 Jan 2015 10:10:25 +0100 Subject: ProtoProxy: Added socket startup error reporting. Fixes CID 66433, fixes CID 66443. --- Tools/ProtoProxy/Server.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'Tools') diff --git a/Tools/ProtoProxy/Server.cpp b/Tools/ProtoProxy/Server.cpp index bb042b259..9545af852 100644 --- a/Tools/ProtoProxy/Server.cpp +++ b/Tools/ProtoProxy/Server.cpp @@ -38,13 +38,41 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort) m_PublicKeyDER = m_PrivateKey.GetPubKeyDER(); m_ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (m_ListenSocket < 0) + { + #ifdef _WIN32 + int err = WSAGetLastError(); + #else + int err = errno; + #endif + printf("Failed to create listener socket: %d\n", err); + return err; + } sockaddr_in local; memset(&local, 0, sizeof(local)); local.sin_family = AF_INET; - local.sin_addr.s_addr = 0; // All interfaces + local.sin_addr.s_addr = 130; // INADDR_ANY; // All interfaces local.sin_port = htons(a_ListenPort); - bind(m_ListenSocket, (sockaddr *)&local, sizeof(local)); - listen(m_ListenSocket, 1); + if (!bind(m_ListenSocket, (sockaddr *)&local, sizeof(local))) + { + #ifdef _WIN32 + int err = WSAGetLastError(); + #else + int err = errno; + #endif + printf("Failed to bind listener socket: %d\n", err); + return err; + } + if (listen(m_ListenSocket, 1) != 0) + { + #ifdef _WIN32 + int err = WSAGetLastError(); + #else + int err = errno; + #endif + printf("Failed to listen on socket: %d\n", err); + return err; + } printf("Listening on port %d, connecting to localhost:%d\n", a_ListenPort, a_ConnectPort); -- cgit v1.2.3