diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2013-09-02 15:15:28 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2013-09-02 15:15:28 +0200 |
commit | 20b64e18e49550e7a105899045fd51be192e86bc (patch) | |
tree | c261c71ea2feb99bc5d4b058da5811c6b80db70c /Tools/ProtoProxy | |
parent | Minecart enhancements [SEE DESC] (diff) | |
parent | Exported BroadcastSoundEffect and BroadcastSoundParticleEffect to the Lua API (diff) | |
download | cuberite-20b64e18e49550e7a105899045fd51be192e86bc.tar cuberite-20b64e18e49550e7a105899045fd51be192e86bc.tar.gz cuberite-20b64e18e49550e7a105899045fd51be192e86bc.tar.bz2 cuberite-20b64e18e49550e7a105899045fd51be192e86bc.tar.lz cuberite-20b64e18e49550e7a105899045fd51be192e86bc.tar.xz cuberite-20b64e18e49550e7a105899045fd51be192e86bc.tar.zst cuberite-20b64e18e49550e7a105899045fd51be192e86bc.zip |
Diffstat (limited to 'Tools/ProtoProxy')
-rw-r--r-- | Tools/ProtoProxy/Connection.cpp | 61 | ||||
-rw-r--r-- | Tools/ProtoProxy/Connection.h | 6 | ||||
-rw-r--r-- | Tools/ProtoProxy/Globals.h | 1 | ||||
-rw-r--r-- | Tools/ProtoProxy/ProtoProxy.vcproj | 8 |
4 files changed, 66 insertions, 10 deletions
diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index 4c2b0d4e9..70dd6acd8 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -201,6 +201,9 @@ enum PACKET_ENCRYPTION_KEY_REQUEST = 0xfd, PACKET_PING = 0xfe, PACKET_KICK = 0xff, + + // Synonyms: + PACKET_DISCONNECT = PACKET_KICK, } ; @@ -238,7 +241,7 @@ cConnection::cConnection(SOCKET a_ClientSocket, cServer & a_Server) : m_Server(a_Server), m_ClientSocket(a_ClientSocket), m_ServerSocket(-1), - m_BeginTick(clock()), + m_BeginTick(m_Timer.GetNowTime()), m_ClientState(csUnencrypted), m_ServerState(csUnencrypted), m_Nonce(0), @@ -475,8 +478,7 @@ bool cConnection::RelayFromClient(void) double cConnection::GetRelativeTime(void) { - return (double)(clock() - m_BeginTick) / CLOCKS_PER_SEC; - + return (double)(m_Timer.GetNowTime() - m_BeginTick) / 1000; } @@ -558,9 +560,9 @@ bool cConnection::DecodeClientsPackets(const char * a_Data, int a_Size) while (m_ClientBuffer.CanReadBytes(1)) { - Log("Decoding client's packets, there are now %d bytes in the queue", m_ClientBuffer.GetReadableSpace()); unsigned char PacketType; m_ClientBuffer.ReadByte(PacketType); + Log("Decoding client's packets, there are now %d bytes in the queue; next packet is 0x%02x", m_ClientBuffer.GetReadableSpace(), PacketType); switch (PacketType) { case PACKET_BLOCK_DIG: HANDLE_CLIENT_READ(HandleClientBlockDig); break; @@ -568,6 +570,7 @@ bool cConnection::DecodeClientsPackets(const char * a_Data, int a_Size) case PACKET_CHAT_MESSAGE: HANDLE_CLIENT_READ(HandleClientChatMessage); break; case PACKET_CLIENT_STATUSES: HANDLE_CLIENT_READ(HandleClientClientStatuses); break; case PACKET_CREATIVE_INVENTORY_ACTION: HANDLE_CLIENT_READ(HandleClientCreativeInventoryAction); break; + case PACKET_DISCONNECT: HANDLE_CLIENT_READ(HandleClientDisconnect); break; case PACKET_ENCRYPTION_KEY_RESPONSE: HANDLE_CLIENT_READ(HandleClientEncryptionKeyResponse); break; case PACKET_ENTITY_ACTION: HANDLE_CLIENT_READ(HandleClientEntityAction); break; case PACKET_HANDSHAKE: HANDLE_CLIENT_READ(HandleClientHandshake); break; @@ -644,7 +647,7 @@ bool cConnection::DecodeServersPackets(const char * a_Data, int a_Size) { unsigned char PacketType; m_ServerBuffer.ReadByte(PacketType); - Log("Decoding server's packets, there are now %d bytes in the queue; next packet is 0x%x", m_ServerBuffer.GetReadableSpace(), PacketType); + Log("Decoding server's packets, there are now %d bytes in the queue; next packet is 0x%02x", m_ServerBuffer.GetReadableSpace(), PacketType); LogFlush(); switch (PacketType) { @@ -843,6 +846,19 @@ bool cConnection::HandleClientCreativeInventoryAction(void) +bool cConnection::HandleClientDisconnect(void) +{ + HANDLE_CLIENT_PACKET_READ(ReadBEUTF16String16, AString, Reason); + Log("Received a PACKET_DISCONNECT from the client:"); + Log(" Reason = \"%s\"", Reason.c_str()); + COPY_TO_SERVER(); + return true; +} + + + + + bool cConnection::HandleClientEncryptionKeyResponse(void) { HANDLE_CLIENT_PACKET_READ(ReadBEShort, short, EncKeyLength); @@ -1704,16 +1720,45 @@ bool cConnection::HandleServerMapChunkBulk(void) { return false; } - AString Meta; - if (!m_ServerBuffer.ReadString(Meta, ChunkCount * 12)) + + // Read individual chunk metas. + // Need to read them first and only then start logging (in case we don't have the full packet yet) + struct sChunkMeta { - return false; + int m_ChunkX, m_ChunkZ; + short m_PrimaryBitmap; + short m_AddBitmap; + sChunkMeta(int a_ChunkX, int a_ChunkZ, short a_PrimaryBitmap, short a_AddBitmap) : + m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ), m_PrimaryBitmap(a_PrimaryBitmap), m_AddBitmap(a_AddBitmap) + { + } + } ; + typedef std::vector<sChunkMeta> sChunkMetas; + sChunkMetas ChunkMetas; + ChunkMetas.reserve(ChunkCount); + for (short i = 0; i < ChunkCount; i++) + { + HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkX); + HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkZ); + HANDLE_SERVER_PACKET_READ(ReadBEShort, short, PrimaryBitmap); + HANDLE_SERVER_PACKET_READ(ReadBEShort, short, AddBitmap); + ChunkMetas.push_back(sChunkMeta(ChunkX, ChunkZ, PrimaryBitmap, AddBitmap)); } + Log("Received a PACKET_MAP_CHUNK_BULK from the server:"); Log(" ChunkCount = %d", ChunkCount); Log(" Compressed size = %d (0x%x)", CompressedSize, CompressedSize); Log(" IsSkyLightSent = %s", IsSkyLightSent ? "true" : "false"); + // Log individual chunk coords: + int idx = 0; + for (sChunkMetas::iterator itr = ChunkMetas.begin(), end = ChunkMetas.end(); itr != end; ++itr, ++idx) + { + Log(" [%d]: [%d, %d], primary bitmap 0x%02x, add bitmap 0x%02x", + idx, itr->m_ChunkX, itr->m_ChunkZ, itr->m_PrimaryBitmap, itr->m_AddBitmap + ); + } // for itr - ChunkMetas[] + // TODO: Save the compressed data into a file for later analysis COPY_TO_CLIENT(); diff --git a/Tools/ProtoProxy/Connection.h b/Tools/ProtoProxy/Connection.h index 8d466c62d..c30a28727 100644 --- a/Tools/ProtoProxy/Connection.h +++ b/Tools/ProtoProxy/Connection.h @@ -9,8 +9,8 @@ #pragma once -#include <time.h> #include "ByteBuffer.h" +#include "../../source/OSSupport/Timer.h" @@ -35,7 +35,8 @@ class cConnection SOCKET m_ClientSocket; SOCKET m_ServerSocket; - clock_t m_BeginTick; // Tick when the relative time was first retrieved (used for GetRelativeTime()) + cTimer m_Timer; + long long m_BeginTick; // Tick when the relative time was first retrieved (used for GetRelativeTime()) enum eConnectionState { @@ -115,6 +116,7 @@ protected: bool HandleClientChatMessage(void); bool HandleClientClientStatuses(void); bool HandleClientCreativeInventoryAction(void); + bool HandleClientDisconnect(void); bool HandleClientEncryptionKeyResponse(void); bool HandleClientEntityAction(void); bool HandleClientHandshake(void); diff --git a/Tools/ProtoProxy/Globals.h b/Tools/ProtoProxy/Globals.h index f2c47e96f..3b154b866 100644 --- a/Tools/ProtoProxy/Globals.h +++ b/Tools/ProtoProxy/Globals.h @@ -143,6 +143,7 @@ typedef short Int16; #include <stdio.h> #include <math.h> #include <stdarg.h> +#include <time.h> diff --git a/Tools/ProtoProxy/ProtoProxy.vcproj b/Tools/ProtoProxy/ProtoProxy.vcproj index 695e01e76..926bbe586 100644 --- a/Tools/ProtoProxy/ProtoProxy.vcproj +++ b/Tools/ProtoProxy/ProtoProxy.vcproj @@ -256,6 +256,14 @@ RelativePath="..\..\source\StringUtils.h" > </File> + <File + RelativePath="..\..\source\OSSupport\Timer.cpp" + > + </File> + <File + RelativePath="..\..\source\OSSupport\Timer.h" + > + </File> </Filter> <File RelativePath=".\ProtoProxy.txt" |