summaryrefslogtreecommitdiffstats
path: root/Tools/ProtoProxy
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/ProtoProxy')
-rw-r--r--Tools/ProtoProxy/.gitignore1
-rw-r--r--Tools/ProtoProxy/Connection.cpp93
2 files changed, 72 insertions, 22 deletions
diff --git a/Tools/ProtoProxy/.gitignore b/Tools/ProtoProxy/.gitignore
index 3097f7aab..2a38341e5 100644
--- a/Tools/ProtoProxy/.gitignore
+++ b/Tools/ProtoProxy/.gitignore
@@ -1,4 +1,5 @@
Debug
Release
+Logs/
*.log
*.nbt
diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp
index 70dd6acd8..e985c2ff6 100644
--- a/Tools/ProtoProxy/Connection.cpp
+++ b/Tools/ProtoProxy/Connection.cpp
@@ -8,6 +8,9 @@
#include "Server.h"
#include <iostream>
+#ifdef _WIN32
+ #include <direct.h> // For _mkdir()
+#endif
@@ -232,6 +235,18 @@ enum
+AString PrintableAbsIntTriplet(int a_X, int a_Y, int a_Z, double a_Divisor = 32)
+{
+ return Printf("<%d, %d, %d> ~ {%.02f, %.02f, %.02f}",
+ a_X, a_Y, a_Z,
+ (double)a_X / a_Divisor, (double)a_Y / a_Divisor, (double)a_Z / a_Divisor
+ );
+}
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cConnection:
@@ -249,7 +264,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");
@@ -1481,7 +1503,7 @@ bool cConnection::HandleServerEntityRelativeMove(void)
HANDLE_SERVER_PACKET_READ(ReadByte, Byte, dz);
Log("Received a PACKET_ENTITY_RELATIVE_MOVE from the server:");
Log(" EntityID = %d", EntityID);
- Log(" RelMove = <%d, %d, %d>", dx, dy, dz);
+ Log(" RelMove = %s", PrintableAbsIntTriplet(dx, dy, dz).c_str());
COPY_TO_CLIENT();
return true;
}
@@ -1500,7 +1522,7 @@ bool cConnection::HandleServerEntityRelativeMoveLook(void)
HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Pitch);
Log("Received a PACKET_ENTITY_RELATIVE_MOVE_LOOK from the server:");
Log(" EntityID = %d", EntityID);
- Log(" RelMove = <%d, %d, %d>", dx, dy, dz);
+ Log(" RelMove = %s", PrintableAbsIntTriplet(dx, dy, dz).c_str());
Log(" Yaw = %d", Yaw);
Log(" Pitch = %d", Pitch);
COPY_TO_CLIENT();
@@ -1529,14 +1551,14 @@ bool cConnection::HandleServerEntityStatus(void)
bool cConnection::HandleServerEntityTeleport(void)
{
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BlockX);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BlockY);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BlockZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt, int, AbsX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt, int, AbsY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt, int, AbsZ);
HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Yaw);
HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Pitch);
Log("Received a PACKET_ENTITY_TELEPORT from the server:");
Log(" EntityID = %d", EntityID);
- Log(" Pos = {%d, %d, %d}", BlockX, BlockY, BlockZ);
+ Log(" Pos = (%d, %d, %d) ~ {%.02f, %.02f, %.02f}", AbsX, AbsY, AbsZ, (double)AbsX / 32, (double)AbsY / 32, (double)AbsZ / 32);
Log(" Yaw = %d", Yaw);
Log(" Pitch = %d", Pitch);
COPY_TO_CLIENT();
@@ -1555,7 +1577,7 @@ bool cConnection::HandleServerEntityVelocity(void)
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, VelocityZ);
Log("Received a PACKET_ENTITY_VELOCITY from the server:");
Log(" EntityID = %d", EntityID);
- Log(" Velocity = <%d, %d, %d>", VelocityX, VelocityY, VelocityZ);
+ Log(" Velocity = %s", PrintableAbsIntTriplet(VelocityX, VelocityY, VelocityZ, 8000).c_str());
COPY_TO_CLIENT();
return true;
}
@@ -1624,7 +1646,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)
{
@@ -1632,14 +1655,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
{
@@ -1996,9 +2045,9 @@ bool cConnection::HandleServerSpawnMob(void)
Log("Received a PACKET_SPAWN_MOB from the server:");
Log(" EntityID = %d", EntityID);
Log(" MobType = %d", MobType);
- Log(" Pos = <%d, %d, %d> ~ {%d, %d, %d}", PosX, PosY, PosZ, PosX / 32, PosY / 32, PosZ / 32);
+ Log(" Pos = %s", PrintableAbsIntTriplet(PosX, PosY, PosZ).c_str());
Log(" Angles = [%d, %d, %d]", Yaw, Pitch, HeadYaw);
- Log(" Velocity = <%d, %d, %d>", VelocityX, VelocityY, VelocityZ);
+ Log(" Velocity = %s", PrintableAbsIntTriplet(VelocityX, VelocityY, VelocityZ, 8000).c_str());
Log(" Metadata, length = %d (0x%x):\n%s", Metadata.length(), Metadata.length(), HexDump.c_str());
LogMetadata(Metadata, 4);
COPY_TO_CLIENT();
@@ -2029,7 +2078,7 @@ bool cConnection::HandleServerSpawnNamedEntity(void)
Log("Received a PACKET_SPAWN_NAMED_ENTITY from the server:");
Log(" EntityID = %d (0x%x)", EntityID, EntityID);
Log(" Name = %s", EntityName.c_str());
- Log(" Pos = <%d, %d, %d> ~ {%d, %d, %d}", PosX, PosY, PosZ, PosX / 32, PosY / 32, PosZ / 32);
+ Log(" Pos = %s", PrintableAbsIntTriplet(PosX, PosY, PosZ).c_str());
Log(" Rotation = <yaw %d, pitch %d>", Yaw, Pitch);
Log(" CurrentItem = %d", CurrentItem);
Log(" Metadata, length = %d (0x%x):\n%s", Metadata.length(), Metadata.length(), HexDump.c_str());
@@ -2102,12 +2151,12 @@ bool cConnection::HandleServerSpawnObjectVehicle(void)
Log("Received a PACKET_SPAWN_OBJECT_VEHICLE from the server:");
Log(" EntityID = %d (0x%x)", EntityID, EntityID);
Log(" ObjType = %d (0x%x)", ObjType, ObjType);
- Log(" Pos = <%d, %d, %d> ~ {%d, %d, %d}", PosX, PosY, PosZ, PosX / 32, PosY / 32, PosZ / 32);
+ Log(" Pos = %s", PrintableAbsIntTriplet(PosX, PosY, PosZ).c_str());
Log(" Rotation = <yaw %d, pitch %d>", Yaw, Pitch);
Log(" DataIndicator = %d (0x%x)", DataIndicator, DataIndicator);
if (DataIndicator != 0)
{
- Log(" Velocity = <%d, %d, %d>", VelocityX, VelocityY, VelocityZ);
+ Log(" Velocity = %s", PrintableAbsIntTriplet(VelocityX, VelocityY, VelocityZ, 8000).c_str());
DataLog(ExtraData.data(), ExtraData.size(), " ExtraData size = %d:", ExtraData.size());
}
COPY_TO_CLIENT();
@@ -2129,7 +2178,7 @@ bool cConnection::HandleServerSpawnPainting(void)
Log("Received a PACKET_SPAWN_PAINTING from the server:");
Log(" EntityID = %d", EntityID);
Log(" ImageName = \"%s\"", ImageName.c_str());
- Log(" Pos = <%d, %d, %d> ~ {%d, %d, %d}", PosX, PosY, PosZ, PosX / 32, PosY / 32, PosZ / 32);
+ Log(" Pos = %s", PrintableAbsIntTriplet(PosX, PosY, PosZ).c_str());
Log(" Direction = %d", Direction);
COPY_TO_CLIENT();
return true;
@@ -2156,7 +2205,7 @@ bool cConnection::HandleServerSpawnPickup(void)
Log("Received a PACKET_SPAWN_PICKUP from the server:");
Log(" EntityID = %d", EntityID);
Log(" Item = %s", ItemDesc.c_str());
- Log(" Pos = <%d, %d, %d> ~ {%d, %d, %d}", PosX, PosY, PosZ, PosX / 32, PosY / 32, PosZ / 32);
+ Log(" Pos = %s", PrintableAbsIntTriplet(PosX, PosY, PosZ).c_str());
Log(" Angles = [%d, %d, %d]", Rotation, Pitch, Roll);
COPY_TO_CLIENT();
return true;