diff options
Diffstat (limited to '')
-rw-r--r-- | Tools/ProtoProxy/Connection.cpp | 109 |
1 files changed, 99 insertions, 10 deletions
diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index fc8fceb99..c4776949e 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -8,11 +8,21 @@ #include "Server.h" #include <iostream> +#ifdef _WIN32 + #include <direct.h> // For _mkdir() +#endif -#ifdef _DEBUG +/// When defined, the following macro causes a sleep after each parsed packet (DEBUG-mode only) +// #define SLEEP_AFTER_PACKET + + + + + +#if defined(_DEBUG) && defined(SLEEP_AFTER_PACKET) #define DebugSleep Sleep #else #define DebugSleep(X) @@ -179,6 +189,7 @@ enum PACKET_BLOCK_CHANGE = 0x35, PACKET_BLOCK_ACTION = 0x36, PACKET_MAP_CHUNK_BULK = 0x38, + PACKET_EXPLOSION = 0x3c, PACKET_SOUND_EFFECT = 0x3d, PACKET_NAMED_SOUND_EFFECT = 0x3e, PACKET_CHANGE_GAME_STATE = 0x46, @@ -261,7 +272,14 @@ cConnection::cConnection(SOCKET a_ClientSocket, cServer & a_Server) : m_ServerBuffer(1024 KiB), m_HasClientPinged(false) { - Printf(m_LogNameBase, "Log_%d", (int)time(NULL)); + // Create the Logs subfolder, if not already created: + #if defined(_WIN32) + _mkdir("Logs"); + #else + mkdir("Logs", 0777); + #endif + + Printf(m_LogNameBase, "Logs/Log_%d", (int)time(NULL)); AString fnam(m_LogNameBase); fnam.append(".log"); m_LogFile = fopen(fnam.c_str(), "w"); @@ -289,7 +307,7 @@ void cConnection::Run(void) Log("Cannot connect to server; aborting"); return; } - + while (true) { fd_set ReadFDs; @@ -684,6 +702,7 @@ bool cConnection::DecodeServersPackets(const char * a_Data, int a_Size) case PACKET_ENTITY_STATUS: HANDLE_SERVER_READ(HandleServerEntityStatus); break; case PACKET_ENTITY_TELEPORT: HANDLE_SERVER_READ(HandleServerEntityTeleport); break; case PACKET_ENTITY_VELOCITY: HANDLE_SERVER_READ(HandleServerEntityVelocity); break; + case PACKET_EXPLOSION: HANDLE_SERVER_READ(HandleServerExplosion); break; case PACKET_INCREMENT_STATISTIC: HANDLE_SERVER_READ(HandleServerIncrementStatistic); break; case PACKET_KEEPALIVE: HANDLE_SERVER_READ(HandleServerKeepAlive); break; case PACKET_KICK: HANDLE_SERVER_READ(HandleServerKick); break; @@ -1576,6 +1595,49 @@ bool cConnection::HandleServerEntityVelocity(void) +bool cConnection::HandleServerExplosion(void) +{ + HANDLE_SERVER_PACKET_READ(ReadBEDouble, double, PosX); + HANDLE_SERVER_PACKET_READ(ReadBEDouble, double, PosY); + HANDLE_SERVER_PACKET_READ(ReadBEDouble, double, PosZ); + HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, Force); + HANDLE_SERVER_PACKET_READ(ReadBEInt, int, NumRecords); + struct sCoords + { + int x, y, z; + + sCoords(int a_X, int a_Y, int a_Z) : x(a_X), y(a_Y), z(a_Z) {} + } ; + std::vector<sCoords> Records; + Records.reserve(NumRecords); + int PosXI = (int)PosX, PosYI = (int)PosY, PosZI = (int)PosZ; + for (int i = 0; i < NumRecords; i++) + { + HANDLE_SERVER_PACKET_READ(ReadChar, char, rx); + HANDLE_SERVER_PACKET_READ(ReadChar, char, ry); + HANDLE_SERVER_PACKET_READ(ReadChar, char, rz); + Records.push_back(sCoords(PosXI + rx, PosYI + ry, PosZI + rz)); + } + HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PlayerMotionX); + HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PlayerMotionY); + HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PlayerMotionZ); + 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(" Records[%d] = {%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(); + return true; +} + + + + + bool cConnection::HandleServerIncrementStatistic(void) { // 0xc8 @@ -1636,7 +1698,8 @@ bool cConnection::HandleServerKick(void) // Split by NULL chars (StringSplit() won't work here): size_t Last = 0; - for (size_t i = 0; i < Reason.size(); i++) + size_t Len = Reason.size(); + for (size_t i = 0; i < Len; i++) { if (Reason[i] == 0) { @@ -1644,14 +1707,40 @@ bool cConnection::HandleServerKick(void) Last = i + 1; } } + if (Last < Len) + { + Split.push_back(Reason.substr(Last)); + } - if (Split.size() == 5) + if (Split.size() == 6) { - Log(" Protocol version: \"%s\"", Split[0].c_str()); - Log(" Server version: \"%s\"", Split[1].c_str()); - Log(" MOTD: \"%s\"", Split[2].c_str()); - Log(" Cur players: \"%s\"", Split[3].c_str()); - Log(" Max players: \"%s\"", Split[4].c_str()); + Log(" Preamble: \"%s\"", Split[0].c_str()); + Log(" Protocol version: \"%s\"", Split[1].c_str()); + Log(" Server version: \"%s\"", Split[2].c_str()); + Log(" MOTD: \"%s\"", Split[3].c_str()); + Log(" Cur players: \"%s\"", Split[4].c_str()); + Log(" Max players: \"%s\"", Split[5].c_str()); + + // Modify the MOTD to show that it's being ProtoProxied: + Reason.assign(Split[0]); + Reason.push_back(0); + Reason.append(Split[1]); + Reason.push_back(0); + Reason.append(Split[2]); + Reason.push_back(0); + Reason.append(Printf("ProtoProxy: %s", Split[3].c_str())); + Reason.push_back(0); + Reason.append(Split[4]); + Reason.push_back(0); + Reason.append(Split[5]); + AString ReasonBE16; + UTF8ToRawBEUTF16(Reason.data(), Reason.size(), ReasonBE16); + AString PacketStart("\xff"); + PacketStart.push_back((ReasonBE16.size() / 2) / 256); + PacketStart.push_back((ReasonBE16.size() / 2) % 256); + CLIENTSEND(PacketStart.data(), PacketStart.size()); + CLIENTSEND(ReasonBE16.data(), ReasonBE16.size()); + return true; } else { |