summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Tools/ProtoProxy/Connection.cpp677
-rw-r--r--Tools/ProtoProxy/Globals.h8
-rw-r--r--Tools/ProtoProxy/Server.h4
-rw-r--r--src/ByteBuffer.cpp103
-rw-r--r--src/ByteBuffer.h27
-rw-r--r--src/ClientHandle.cpp24
-rw-r--r--src/ClientHandle.h22
-rw-r--r--src/Endianness.h12
-rw-r--r--src/Globals.h10
-rw-r--r--src/Protocol/ChunkDataSerializer.cpp12
-rw-r--r--src/Protocol/Protocol17x.cpp220
-rw-r--r--src/Protocol/Protocol17x.h15
-rw-r--r--src/Protocol/Protocol18x.cpp138
-rw-r--r--src/Protocol/Protocol18x.h19
-rw-r--r--src/Protocol/ProtocolRecognizer.cpp22
15 files changed, 722 insertions, 591 deletions
diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp
index 6d347e07d..4e890c26a 100644
--- a/Tools/ProtoProxy/Connection.cpp
+++ b/Tools/ProtoProxy/Connection.cpp
@@ -214,7 +214,11 @@ cConnection::cConnection(SOCKET a_ClientSocket, cServer & a_Server) :
Printf(m_LogNameBase, "Logs/Log_%d_%d", (int)time(NULL), a_ClientSocket);
AString fnam(m_LogNameBase);
fnam.append(".log");
- m_LogFile = fopen(fnam.c_str(), "w");
+ #ifdef _WIN32
+ fopen_s(&m_LogFile, fnam.c_str(), "w");
+ #else
+ m_LogFile = fopen(fnam.c_str(), "w");
+ #endif
Log("Log file created");
printf("Connection is logged to file \"%s\"\n", fnam.c_str());
}
@@ -788,14 +792,14 @@ bool cConnection::HandleClientHandshake(void)
// Read the packet from the client:
HANDLE_CLIENT_PACKET_READ(ReadVarInt, UInt32, ProtocolVersion);
HANDLE_CLIENT_PACKET_READ(ReadVarUTF8String, AString, ServerHost);
- HANDLE_CLIENT_PACKET_READ(ReadBEShort, short, ServerPort);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt16, UInt16, ServerPort);
HANDLE_CLIENT_PACKET_READ(ReadVarInt, UInt32, NextState);
m_ClientBuffer.CommitRead();
Log("Received an initial handshake packet from the client:");
Log(" ProtocolVersion = %u", ProtocolVersion);
Log(" ServerHost = \"%s\"", ServerHost.c_str());
- Log(" ServerPort = %d", ServerPort);
+ Log(" ServerPort = %u", ServerPort);
Log(" NextState = %u", NextState);
// Send the same packet to the server, but with our port:
@@ -803,7 +807,7 @@ bool cConnection::HandleClientHandshake(void)
Packet.WriteVarInt(0); // Packet type - initial handshake
Packet.WriteVarInt(ProtocolVersion);
Packet.WriteVarUTF8String(ServerHost);
- Packet.WriteBEShort(m_Server.GetConnectPort());
+ Packet.WriteBEUInt16(m_Server.GetConnectPort());
Packet.WriteVarInt(NextState);
AString Pkt;
Packet.ReadAll(Pkt);
@@ -811,8 +815,8 @@ bool cConnection::HandleClientHandshake(void)
ToServer.WriteVarUTF8String(Pkt);
SERVERSEND(ToServer);
- m_ClientProtocolState = (int)NextState;
- m_ServerProtocolState = (int)NextState;
+ m_ClientProtocolState = static_cast<int>(NextState);
+ m_ServerProtocolState = static_cast<int>(NextState);
return true;
}
@@ -852,10 +856,10 @@ bool cConnection::HandleClientLoginStart(void)
bool cConnection::HandleClientAnimation(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, Animation);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt8, Int8, Animation);
Log("Received a PACKET_ANIMATION from the client:");
- Log(" EntityID: %d", EntityID);
+ Log(" EntityID: %u", EntityID);
Log(" Animation: %d", Animation);
COPY_TO_SERVER();
return true;
@@ -867,15 +871,15 @@ bool cConnection::HandleClientAnimation(void)
bool cConnection::HandleClientBlockDig(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadByte, Byte, Status);
- HANDLE_CLIENT_PACKET_READ(ReadBEInt, int, BlockX);
- HANDLE_CLIENT_PACKET_READ(ReadByte, Byte, BlockY);
- HANDLE_CLIENT_PACKET_READ(ReadBEInt, int, BlockZ);
- HANDLE_CLIENT_PACKET_READ(ReadByte, Byte, BlockFace);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, Status);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt32, Int32, BlockX);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, BlockY);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt32, Int32, BlockZ);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, BlockFace);
Log("Received a PACKET_BLOCK_DIG from the client:");
- Log(" Status = %d", Status);
- Log(" Pos = <%d, %d, %d>", BlockX, BlockY, BlockZ);
- Log(" BlockFace = %d", BlockFace);
+ Log(" Status = %u (0x%02x)", Status, Status);
+ Log(" Pos = <%d, %u, %d>", BlockX, BlockY, BlockZ);
+ Log(" BlockFace = %u (0x%02x)", BlockFace, BlockFace);
COPY_TO_SERVER();
return true;
}
@@ -886,23 +890,23 @@ bool cConnection::HandleClientBlockDig(void)
bool cConnection::HandleClientBlockPlace(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadBEInt, int, BlockX);
- HANDLE_CLIENT_PACKET_READ(ReadByte, Byte, BlockY);
- HANDLE_CLIENT_PACKET_READ(ReadBEInt, int, BlockZ);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, Face);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt32, Int32, BlockX);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, BlockY);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt32, Int32, BlockZ);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, Face);
AString Desc;
if (!ParseSlot(m_ClientBuffer, Desc))
{
return false;
}
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, CursorX);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, CursorY);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, CursorZ);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, CursorX);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, CursorY);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, CursorZ);
Log("Received a PACKET_BLOCK_PLACE from the client:");
- Log(" Block = {%d, %d, %d}", BlockX, BlockY, BlockZ);
- Log(" Face = %d", Face);
+ Log(" Block = {%d, %u, %d}", BlockX, BlockY, BlockZ);
+ Log(" Face = %u (0x%02x)", Face, Face);
Log(" Item = %s", Desc.c_str());
- Log(" Cursor = <%d, %d, %d>", CursorX, CursorY, CursorZ);
+ Log(" Cursor = <%u, %u, %u>", CursorX, CursorY, CursorZ);
COPY_TO_SERVER();
return true;
}
@@ -926,9 +930,9 @@ bool cConnection::HandleClientChatMessage(void)
bool cConnection::HandleClientClientStatuses(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, Statuses);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, Statuses);
Log("Received a PACKET_CLIENT_STATUSES from the CLIENT:");
- Log(" Statuses = %d", Statuses);
+ Log(" Statuses = %u (0x%02x)", Statuses, Statuses);
COPY_TO_SERVER();
return true;
@@ -940,14 +944,14 @@ bool cConnection::HandleClientClientStatuses(void)
bool cConnection::HandleClientCreativeInventoryAction(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadBEShort, short, SlotNum);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt16, UInt16, SlotNum);
AString Item;
if (!ParseSlot(m_ClientBuffer, Item))
{
return false;
}
Log("Received a PACKET_CREATIVE_INVENTORY_ACTION from the client:");
- Log(" SlotNum = %d", SlotNum);
+ Log(" SlotNum = %u", SlotNum);
Log(" Item = %s", Item.c_str());
COPY_TO_SERVER();
return true;
@@ -972,12 +976,12 @@ bool cConnection::HandleClientDisconnect(void)
bool cConnection::HandleClientEntityAction(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadBEInt, int, PlayerID);
- HANDLE_CLIENT_PACKET_READ(ReadByte, Byte, ActionType);
- HANDLE_CLIENT_PACKET_READ(ReadBEInt, int, HorseJumpBoost);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt32, Int32, PlayerID);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, ActionType);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt32, Int32, HorseJumpBoost);
Log("Received a PACKET_ENTITY_ACTION from the client:");
Log(" PlayerID = %d", PlayerID);
- Log(" ActionType = %d", ActionType);
+ Log(" ActionType = %u", ActionType);
Log(" HorseJumpBoost = %d (0x%08x)", HorseJumpBoost, HorseJumpBoost);
COPY_TO_SERVER();
return true;
@@ -989,7 +993,7 @@ bool cConnection::HandleClientEntityAction(void)
bool cConnection::HandleClientKeepAlive(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadBEInt, int, ID);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt32, Int32, ID);
Log("Received a PACKET_KEEPALIVE from the client");
COPY_TO_SERVER();
return true;
@@ -1002,11 +1006,11 @@ bool cConnection::HandleClientKeepAlive(void)
bool cConnection::HandleClientLocaleAndView(void)
{
HANDLE_CLIENT_PACKET_READ(ReadVarUTF8String, AString, Locale);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, ViewDistance);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, ChatFlags);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, Unused);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, Difficulty);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, ShowCape);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt8, Int8, ViewDistance);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt8, Int8, ChatFlags);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt8, Int8, Unused);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt8, Int8, Difficulty);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt8, Int8, ShowCape);
Log("Received a PACKET_LOCALE_AND_VIEW from the client");
COPY_TO_SERVER();
return true;
@@ -1031,11 +1035,11 @@ bool cConnection::HandleClientPing(void)
bool cConnection::HandleClientPlayerAbilities(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, Flags);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, Flags);
HANDLE_CLIENT_PACKET_READ(ReadBEFloat, float, FlyingSpeed);
HANDLE_CLIENT_PACKET_READ(ReadBEFloat, float, WalkingSpeed);
Log("Receives a PACKET_PLAYER_ABILITIES from the client:");
- Log(" Flags = %d (0x%02x)", Flags, Flags);
+ Log(" Flags = %u (0x%02x)", Flags, Flags);
Log(" FlyingSpeed = %f", FlyingSpeed);
Log(" WalkingSpeed = %f", WalkingSpeed);
COPY_TO_SERVER();
@@ -1050,7 +1054,7 @@ bool cConnection::HandleClientPlayerLook(void)
{
HANDLE_CLIENT_PACKET_READ(ReadBEFloat, float, Yaw);
HANDLE_CLIENT_PACKET_READ(ReadBEFloat, float, Pitch);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, OnGround);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, OnGround);
Log("Received a PACKET_PLAYER_LOOK from the client");
COPY_TO_SERVER();
return true;
@@ -1062,7 +1066,7 @@ bool cConnection::HandleClientPlayerLook(void)
bool cConnection::HandleClientPlayerOnGround(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, OnGround);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, OnGround);
Log("Received a PACKET_PLAYER_ON_GROUND from the client");
COPY_TO_SERVER();
return true;
@@ -1078,7 +1082,7 @@ bool cConnection::HandleClientPlayerPosition(void)
HANDLE_CLIENT_PACKET_READ(ReadBEDouble, double, PosY);
HANDLE_CLIENT_PACKET_READ(ReadBEDouble, double, Stance);
HANDLE_CLIENT_PACKET_READ(ReadBEDouble, double, PosZ);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, IsOnGround);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, IsOnGround);
Log("Received a PACKET_PLAYER_POSITION from the client");
// TODO: list packet contents
@@ -1099,7 +1103,7 @@ bool cConnection::HandleClientPlayerPositionLook(void)
HANDLE_CLIENT_PACKET_READ(ReadBEDouble, double, PosZ);
HANDLE_CLIENT_PACKET_READ(ReadBEFloat, float, Yaw);
HANDLE_CLIENT_PACKET_READ(ReadBEFloat, float, Pitch);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, IsOnGround);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, IsOnGround);
Log("Received a PACKET_PLAYER_POSITION_LOOK from the client");
Log(" Pos = {%.03f, %.03f, %.03f}", PosX, PosY, PosZ);
Log(" Stance = %.03f", Stance);
@@ -1117,7 +1121,7 @@ bool cConnection::HandleClientPlayerPositionLook(void)
bool cConnection::HandleClientPluginMessage(void)
{
HANDLE_CLIENT_PACKET_READ(ReadVarUTF8String, AString, ChannelName);
- HANDLE_CLIENT_PACKET_READ(ReadBEUInt16, UInt16, Length);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt16, UInt16, Length);
AString Data;
if (!m_ClientBuffer.ReadString(Data, Length))
{
@@ -1136,7 +1140,7 @@ bool cConnection::HandleClientPluginMessage(void)
bool cConnection::HandleClientSlotSelect(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadBEShort, short, SlotNum);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt16, Int16, SlotNum);
Log("Received a PACKET_SLOT_SELECT from the client");
Log(" SlotNum = %d", SlotNum);
COPY_TO_SERVER();
@@ -1186,9 +1190,9 @@ bool cConnection::HandleClientTabCompletion(void)
bool cConnection::HandleClientUpdateSign(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadBEInt, int, BlockX);
- HANDLE_CLIENT_PACKET_READ(ReadBEShort, short, BlockY);
- HANDLE_CLIENT_PACKET_READ(ReadBEInt, int, BlockZ);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt32, Int32, BlockX);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt16, Int16, BlockY);
+ HANDLE_CLIENT_PACKET_READ(ReadBEInt32, Int32, BlockZ);
HANDLE_CLIENT_PACKET_READ(ReadVarUTF8String, AString, Line1);
HANDLE_CLIENT_PACKET_READ(ReadVarUTF8String, AString, Line2);
HANDLE_CLIENT_PACKET_READ(ReadVarUTF8String, AString, Line3);
@@ -1206,11 +1210,11 @@ bool cConnection::HandleClientUpdateSign(void)
bool cConnection::HandleClientUseEntity(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, MouseButton);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, MouseButton);
Log("Received a PACKET_USE_ENTITY from the client:");
Log(" EntityID = %d", EntityID);
- Log(" MouseButton = %d", MouseButton);
+ Log(" MouseButton = %u", MouseButton);
COPY_TO_SERVER();
return true;
}
@@ -1221,20 +1225,20 @@ bool cConnection::HandleClientUseEntity(void)
bool cConnection::HandleClientWindowClick(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, WindowID);
- HANDLE_CLIENT_PACKET_READ(ReadBEShort, short, SlotNum);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, Button);
- HANDLE_CLIENT_PACKET_READ(ReadBEShort, short, TransactionID);
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, Mode);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, WindowID);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt16, UInt16, SlotNum);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, Button);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt16, UInt16, TransactionID);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, Mode);
AString Item;
if (!ParseSlot(m_ClientBuffer, Item))
{
return false;
}
Log("Received a PACKET_WINDOW_CLICK from the client");
- Log(" WindowID = %d", WindowID);
- Log(" SlotNum = %d", SlotNum);
- Log(" Button = %d, Mode = %d", Button, Mode);
+ Log(" WindowID = %u", WindowID);
+ Log(" SlotNum = %u", SlotNum);
+ Log(" Button = %u, Mode = %u", Button, Mode);
Log(" TransactionID = 0x%x", TransactionID);
Log(" ClickedItem = %s", Item.c_str());
COPY_TO_SERVER();
@@ -1247,9 +1251,9 @@ bool cConnection::HandleClientWindowClick(void)
bool cConnection::HandleClientWindowClose(void)
{
- HANDLE_CLIENT_PACKET_READ(ReadChar, char, WindowID);
+ HANDLE_CLIENT_PACKET_READ(ReadBEUInt8, UInt8, WindowID);
Log("Received a PACKET_WINDOW_CLOSE from the client:");
- Log(" WindowID = %d", WindowID);
+ Log(" WindowID = %u", WindowID);
COPY_TO_SERVER();
return true;
}
@@ -1355,13 +1359,13 @@ bool cConnection::HandleServerLoginSuccess(void)
bool cConnection::HandleServerAttachEntity(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, VehicleID);
- HANDLE_SERVER_PACKET_READ(ReadBool, bool, Leash);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, VehicleID);
+ HANDLE_SERVER_PACKET_READ(ReadBool, bool, IsOnLeash);
Log("Received a PACKET_ATTACH_ENTITY from the server:");
- Log(" EntityID = %d (0x%x)", EntityID, EntityID);
- Log(" VehicleID = %d (0x%x)", VehicleID, VehicleID);
- Log(" Leash = %s", Leash ? "true" : "false");
+ Log(" EntityID = %u (0x%x)", EntityID, EntityID);
+ Log(" VehicleID = %u (0x%x)", VehicleID, VehicleID);
+ Log(" IsOnLeash = %s", IsOnLeash ? "true" : "false");
COPY_TO_CLIENT();
return true;
}
@@ -1372,15 +1376,15 @@ bool cConnection::HandleServerAttachEntity(void)
bool cConnection::HandleServerBlockAction(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, Byte1);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Byte2);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, BlockX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, BlockY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, BlockZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Byte1);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Byte2);
HANDLE_SERVER_PACKET_READ(ReadVarInt, UInt32, BlockID);
Log("Received a PACKET_BLOCK_ACTION from the server:");
Log(" Pos = {%d, %d, %d}", BlockX, BlockY, BlockZ);
- Log(" Bytes = (%d, %d) == (0x%x, 0x%x)", Byte1, Byte2, Byte1, Byte2);
+ Log(" Bytes = (%u, %u) == (0x%x, 0x%x)", Byte1, Byte2, Byte1, Byte2);
Log(" BlockID = %u", BlockID);
COPY_TO_CLIENT();
return true;
@@ -1392,15 +1396,15 @@ bool cConnection::HandleServerBlockAction(void)
bool cConnection::HandleServerBlockChange(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BlockX);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, BlockY);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BlockZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, BlockX);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, BlockY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, BlockZ);
HANDLE_SERVER_PACKET_READ(ReadVarInt, UInt32, BlockType);
- HANDLE_SERVER_PACKET_READ(ReadChar, char, BlockMeta);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, 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);
+ Log(" Pos = {%d, %u, %d}", BlockX, BlockY, BlockZ);
+ Log(" BlockType = %u (0x%x", BlockType, BlockType);
+ Log(" BlockMeta = %u", BlockMeta);
COPY_TO_CLIENT();
return true;
}
@@ -1411,10 +1415,10 @@ bool cConnection::HandleServerBlockChange(void)
bool cConnection::HandleServerChangeGameState(void)
{
- HANDLE_SERVER_PACKET_READ(ReadChar, char, Reason);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Reason);
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, Data);
Log("Received a PACKET_CHANGE_GAME_STATE from the server:");
- Log(" Reason = %d", Reason);
+ Log(" Reason = %u", Reason);
Log(" Data = %f", Data);
COPY_TO_CLIENT();
return true;
@@ -1439,11 +1443,11 @@ bool cConnection::HandleServerChatMessage(void)
bool cConnection::HandleServerCollectPickup(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, CollectedID);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, CollectorID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, CollectedID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, CollectorID);
Log("Received a PACKET_COLLECT_PICKUP from the server:");
- Log(" CollectedID = %d", CollectedID);
- Log(" CollectorID = %d", CollectorID);
+ Log(" CollectedID = %u", CollectedID);
+ Log(" CollectorID = %u", CollectorID);
COPY_TO_CLIENT();
return true;
}
@@ -1454,9 +1458,9 @@ bool cConnection::HandleServerCollectPickup(void)
bool cConnection::HandleServerCompass(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, SpawnX);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, SpawnY);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, SpawnZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, SpawnX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, SpawnY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, SpawnZ);
Log("Received PACKET_COMPASS from the server:");
Log(" Spawn = {%d, %d, %d}", SpawnX, SpawnY, SpawnZ);
COPY_TO_CLIENT();
@@ -1469,7 +1473,7 @@ bool cConnection::HandleServerCompass(void)
bool cConnection::HandleServerDestroyEntities(void)
{
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, NumEntities);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, NumEntities);
if (!m_ServerBuffer.SkipRead(static_cast<size_t>(NumEntities) * 4))
{
return false;
@@ -1486,9 +1490,9 @@ bool cConnection::HandleServerDestroyEntities(void)
bool cConnection::HandleServerEntity(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
Log("Received a PACKET_ENTITY from the server:");
- Log(" EntityID = %d", EntityID);
+ Log(" EntityID = %u", EntityID);
COPY_TO_CLIENT();
return true;
}
@@ -1499,16 +1503,16 @@ bool cConnection::HandleServerEntity(void)
bool cConnection::HandleServerEntityEquipment(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, SlotNum);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, SlotNum);
AString Item;
if (!ParseSlot(m_ServerBuffer, Item))
{
return false;
}
Log("Received a PACKET_ENTITY_EQUIPMENT from the server:");
- Log(" EntityID = %d", EntityID);
- Log(" SlotNum = %d", SlotNum);
+ Log(" EntityID = %u", EntityID);
+ Log(" SlotNum = %u", SlotNum);
Log(" Item = %s", Item.c_str());
COPY_TO_CLIENT();
return true;
@@ -1520,11 +1524,11 @@ bool cConnection::HandleServerEntityEquipment(void)
bool cConnection::HandleServerEntityHeadLook(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, HeadYaw);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, HeadYaw);
Log("Received a PACKET_ENTITY_HEAD_LOOK from the server:");
- Log(" EntityID = %d", EntityID);
- Log(" HeadYaw = %d", HeadYaw);
+ Log(" EntityID = %u", EntityID);
+ Log(" HeadYaw = %u", HeadYaw);
COPY_TO_CLIENT();
return true;
}
@@ -1535,13 +1539,13 @@ bool cConnection::HandleServerEntityHeadLook(void)
bool cConnection::HandleServerEntityLook(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Yaw);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Pitch);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Yaw);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Pitch);
Log("Received a PACKET_ENTITY_LOOK from the server:");
- Log(" EntityID = %d", EntityID);
- Log(" Yaw = %d", Yaw);
- Log(" Pitch = %d", Pitch);
+ Log(" EntityID = %u", EntityID);
+ Log(" Yaw = %u", Yaw);
+ Log(" Pitch = %u", Pitch);
COPY_TO_CLIENT();
return true;
}
@@ -1552,7 +1556,7 @@ bool cConnection::HandleServerEntityLook(void)
bool cConnection::HandleServerEntityMetadata(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
AString Metadata;
if (!ParseMetadata(m_ServerBuffer, Metadata))
{
@@ -1561,8 +1565,9 @@ bool cConnection::HandleServerEntityMetadata(void)
AString HexDump;
CreateHexDump(HexDump, Metadata.data(), Metadata.size(), 32);
Log("Received a PACKET_ENTITY_METADATA from the server:");
- Log(" EntityID = %d", EntityID);
- Log(" Metadata, length = %d (0x%x):\n%s", Metadata.length(), Metadata.length(), HexDump.c_str());
+ Log(" EntityID = %u", EntityID);
+ auto len = static_cast<unsigned>(Metadata.length());
+ Log(" Metadata, length = %u (0x%x):\n%s", len, len, HexDump.c_str());
LogMetadata(Metadata, 4);
COPY_TO_CLIENT();
return true;
@@ -1574,24 +1579,24 @@ bool cConnection::HandleServerEntityMetadata(void)
bool cConnection::HandleServerEntityProperties(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, Count);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, Count);
Log("Received a PACKET_ENTITY_PROPERTIES from the server:");
- Log(" EntityID = %d", EntityID);
- Log(" Count = %d", Count);
+ Log(" EntityID = %u", EntityID);
+ Log(" Count = %u", Count);
- for (int i = 0; i < Count; i++)
+ for (UInt32 i = 0; i < Count; i++)
{
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Key);
HANDLE_SERVER_PACKET_READ(ReadBEDouble, double, Value);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, ListLength);
- Log(" \"%s\" = %f; %d modifiers", Key.c_str(), Value, ListLength);
- for (short j = 0; j < ListLength; j++)
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, ListLength);
+ Log(" \"%s\" = %f; %u modifiers", Key.c_str(), Value, ListLength);
+ for (UInt16 j = 0; j < ListLength; j++)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt64, Int64, UUIDHi);
- HANDLE_SERVER_PACKET_READ(ReadBEInt64, Int64, UUIDLo);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt64, UInt64, UUIDHi);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt64, UInt64, UUIDLo);
HANDLE_SERVER_PACKET_READ(ReadBEDouble, double, DblVal);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, ByteVal);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, ByteVal);
Log(" [%d] = {0x%08llx%08llx, %f, %u}", j, UUIDHi, UUIDLo, DblVal, ByteVal);
}
} // for i
@@ -1605,12 +1610,12 @@ bool cConnection::HandleServerEntityProperties(void)
bool cConnection::HandleServerEntityRelativeMove(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, dx);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, dy);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, dz);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt8, Int8, dx);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt8, Int8, dy);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt8, Int8, dz);
Log("Received a PACKET_ENTITY_RELATIVE_MOVE from the server:");
- Log(" EntityID = %d", EntityID);
+ Log(" EntityID = %u", EntityID);
Log(" RelMove = %s", PrintableAbsIntTriplet(dx, dy, dz).c_str());
COPY_TO_CLIENT();
return true;
@@ -1622,17 +1627,17 @@ bool cConnection::HandleServerEntityRelativeMove(void)
bool cConnection::HandleServerEntityRelativeMoveLook(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, dx);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, dy);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, dz);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Yaw);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Pitch);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt8, Int8, dx);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt8, Int8, dy);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt8, Int8, dz);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Yaw);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Pitch);
Log("Received a PACKET_ENTITY_RELATIVE_MOVE_LOOK from the server:");
- Log(" EntityID = %d", EntityID);
+ Log(" EntityID = %u", EntityID);
Log(" RelMove = %s", PrintableAbsIntTriplet(dx, dy, dz).c_str());
- Log(" Yaw = %d", Yaw);
- Log(" Pitch = %d", Pitch);
+ Log(" Yaw = %u", Yaw);
+ Log(" Pitch = %u", Pitch);
COPY_TO_CLIENT();
return true;
}
@@ -1643,11 +1648,11 @@ bool cConnection::HandleServerEntityRelativeMoveLook(void)
bool cConnection::HandleServerEntityStatus(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Status);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Status);
Log("Received a PACKET_ENTITY_STATUS from the server:");
- Log(" EntityID = %d", EntityID);
- Log(" Status = %d", Status);
+ Log(" EntityID = %u", EntityID);
+ Log(" Status = %u (0x%02x)", Status, Status);
COPY_TO_CLIENT();
return true;
}
@@ -1658,17 +1663,17 @@ bool cConnection::HandleServerEntityStatus(void)
bool cConnection::HandleServerEntityTeleport(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
- 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);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, AbsX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, AbsY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, AbsZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Yaw);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Pitch);
Log("Received a PACKET_ENTITY_TELEPORT from the server:");
- Log(" EntityID = %d", EntityID);
+ Log(" EntityID = %u", EntityID);
Log(" Pos = %s", PrintableAbsIntTriplet(AbsX, AbsY, AbsZ).c_str());
- Log(" Yaw = %d", Yaw);
- Log(" Pitch = %d", Pitch);
+ Log(" Yaw = %u", Yaw);
+ Log(" Pitch = %u", Pitch);
COPY_TO_CLIENT();
return true;
}
@@ -1679,12 +1684,12 @@ bool cConnection::HandleServerEntityTeleport(void)
bool cConnection::HandleServerEntityVelocity(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, VelocityX);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, VelocityY);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, VelocityZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, VelocityX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, VelocityY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, VelocityZ);
Log("Received a PACKET_ENTITY_VELOCITY from the server:");
- Log(" EntityID = %d", EntityID);
+ Log(" EntityID = %u", EntityID);
Log(" Velocity = %s", PrintableAbsIntTriplet(VelocityX, VelocityY, VelocityZ, 8000).c_str());
COPY_TO_CLIENT();
return true;
@@ -1703,12 +1708,12 @@ bool cConnection::HandleServerExplosion(void)
HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, NumRecords);
std::vector<sCoords> Records;
Records.reserve(NumRecords);
- int PosXI = (int)PosX, PosYI = (int)PosY, PosZI = (int)PosZ;
+ int PosXI = static_cast<int>(PosX), PosYI = static_cast<int>(PosY), PosZI = static_cast<int>(PosZ);
for (UInt32 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);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt8, Int8, rx);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt8, Int8, ry);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt8, Int8, rz);
Records.push_back(sCoords(PosXI + rx, PosYI + ry, PosZI + rz));
}
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PlayerMotionX);
@@ -1734,10 +1739,10 @@ bool cConnection::HandleServerExplosion(void)
bool cConnection::HandleServerIncrementStatistic(void)
{
// 0xc8
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, StatisticID);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, Amount);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, StatisticID);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, Amount);
Log("Received a PACKET_INCREMENT_STATISTIC from the server:");
- Log(" StatisticID = %d (0x%x)", StatisticID, StatisticID);
+ Log(" StatisticID = %u (0x%x)", StatisticID, StatisticID);
Log(" Amount = %d", Amount);
COPY_TO_CLIENT();
return true;
@@ -1749,18 +1754,18 @@ bool cConnection::HandleServerIncrementStatistic(void)
bool cConnection::HandleServerJoinGame(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadChar, char, GameMode);
- HANDLE_SERVER_PACKET_READ(ReadChar, char, Dimension);
- HANDLE_SERVER_PACKET_READ(ReadChar, char, Difficulty);
- HANDLE_SERVER_PACKET_READ(ReadChar, char, MaxPlayers);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, GameMode);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Dimension);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Difficulty);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, MaxPlayers);
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, LevelType);
Log("Received a PACKET_LOGIN from the server:");
- Log(" EntityID = %d", EntityID);
- Log(" GameMode = %d", GameMode);
- Log(" Dimension = %d", Dimension);
- Log(" Difficulty = %d", Difficulty);
- Log(" MaxPlayers = %d", MaxPlayers);
+ Log(" EntityID = %u", EntityID);
+ Log(" GameMode = %u", GameMode);
+ Log(" Dimension = %u", Dimension);
+ Log(" Difficulty = %u", Difficulty);
+ Log(" MaxPlayers = %u", MaxPlayers);
Log(" LevelType = \"%s\"", LevelType.c_str());
COPY_TO_CLIENT();
return true;
@@ -1772,9 +1777,9 @@ bool cConnection::HandleServerJoinGame(void)
bool cConnection::HandleServerKeepAlive(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PingID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, PingID);
Log("Received a PACKET_KEEP_ALIVE from the server:");
- Log(" ID = %d", PingID);
+ Log(" ID = %u", PingID);
COPY_TO_CLIENT()
return true;
}
@@ -1856,11 +1861,11 @@ 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(ReadBEInt32, Int32, ChunkX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, ChunkZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, IsContiguous);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, PrimaryBitmap);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, AdditionalBitmap);
HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, CompressedSize);
AString CompressedData;
if (!m_ServerBuffer.ReadString(CompressedData, CompressedSize))
@@ -1899,10 +1904,10 @@ bool cConnection::HandleServerMapChunkBulk(void)
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);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, ChunkX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, ChunkZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, PrimaryBitmap);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, AddBitmap);
ChunkMetas.push_back(sChunkMeta(ChunkX, ChunkZ, PrimaryBitmap, AddBitmap));
}
@@ -1932,8 +1937,8 @@ 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(ReadBEInt32, Int32, ChunkX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, ChunkZ);
HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, NumBlocks);
HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, DataSize);
AString BlockChangeData;
@@ -1955,16 +1960,16 @@ bool cConnection::HandleServerMultiBlockChange(void)
bool cConnection::HandleServerNamedSoundEffect(void)
{
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, SoundName);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosX);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosY);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosZ);
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, Volume);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Pitch);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Pitch);
Log("Received a PACKET_NAMED_SOUND_EFFECT from the server:");
Log(" SoundName = \"%s\"", SoundName.c_str());
Log(" Pos = %s", PrintableAbsIntTriplet(PosX, PosY, PosZ, 8).c_str());
Log(" Volume = %f", Volume);
- Log(" Pitch = %d", Pitch);
+ Log(" Pitch = %u", Pitch);
COPY_TO_CLIENT();
return true;
}
@@ -1975,11 +1980,11 @@ bool cConnection::HandleServerNamedSoundEffect(void)
bool cConnection::HandleServerPlayerAbilities(void)
{
- HANDLE_SERVER_PACKET_READ(ReadChar, char, Flags);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Flags);
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, FlyingSpeed);
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, WalkingSpeed);
Log("Received a PACKET_PLAYER_ABILITIES from the server:");
- Log(" Flags = %d (0x%02x)", Flags, Flags);
+ Log(" Flags = %u (0x%02x)", Flags, Flags);
Log(" FlyingSpeed = %f", FlyingSpeed);
Log(" WalkingSpeed = %f", WalkingSpeed);
COPY_TO_CLIENT();
@@ -1992,11 +1997,11 @@ bool cConnection::HandleServerPlayerAbilities(void)
bool cConnection::HandleServerPlayerAnimation(void)
{
- HANDLE_SERVER_PACKET_READ(ReadVarInt, UInt32, PlayerID);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, AnimationID);
+ HANDLE_SERVER_PACKET_READ(ReadVarInt, UInt32, PlayerID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, AnimationID);
Log("Received a PACKET_PLAYER_ANIMATION from the server:");
Log(" PlayerID: %u (0x%x)", PlayerID, PlayerID);
- Log(" Animation: %d", AnimationID);
+ Log(" Animation: %u", AnimationID);
COPY_TO_CLIENT();
return true;
}
@@ -2008,10 +2013,10 @@ bool cConnection::HandleServerPlayerAnimation(void)
bool cConnection::HandleServerPlayerListItem(void)
{
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, PlayerName);
- HANDLE_SERVER_PACKET_READ(ReadChar, char, IsOnline);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, Ping);
+ HANDLE_SERVER_PACKET_READ(ReadBool, bool, IsOnline);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, Ping);
Log("Received a PACKET_PLAYERLIST_ITEM from the server:");
- Log(" PlayerName = \"%s\"", PlayerName.c_str());
+ Log(" PlayerName = \"%s\" (%s)", PlayerName.c_str(), IsOnline ? "online" : "offline");
Log(" Ping = %d", Ping);
COPY_TO_CLIENT();
return true;
@@ -2028,7 +2033,7 @@ bool cConnection::HandleServerPlayerPositionLook(void)
HANDLE_SERVER_PACKET_READ(ReadBEDouble, double, PosZ);
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, Yaw);
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, Pitch);
- HANDLE_SERVER_PACKET_READ(ReadChar, char, IsOnGround);
+ HANDLE_SERVER_PACKET_READ(ReadBool, bool, IsOnGround);
Log("Received a PACKET_PLAYER_POSITION_LOOK from the server");
// TODO: list packet contents
@@ -2063,14 +2068,14 @@ bool cConnection::HandleServerPluginMessage(void)
bool cConnection::HandleServerRespawn(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, Dimension);
- HANDLE_SERVER_PACKET_READ(ReadChar, char, Difficulty);
- HANDLE_SERVER_PACKET_READ(ReadChar, char, GameMode);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, Dimension);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Difficulty);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, GameMode);
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, LevelType);
Log("Received a respawn packet from the server:");
Log(" Dimension = %d", Dimension);
- Log(" Difficulty = %d", Difficulty);
- Log(" GameMode = %d", GameMode);
+ Log(" Difficulty = %u", Difficulty);
+ Log(" GameMode = %u", GameMode);
Log(" LevelType = \"%s\"", LevelType.c_str());
COPY_TO_CLIENT();
return true;
@@ -2082,13 +2087,13 @@ bool cConnection::HandleServerRespawn(void)
bool cConnection::HandleServerSetExperience(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, ExperienceBar);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, Level);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, TotalExperience);
+ HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, ExperienceBar);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, Level);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, TotalExperience);
Log("Received a PACKET_SET_EXPERIENCE from the server:");
Log(" ExperienceBar = %.05f", ExperienceBar);
- Log(" Level = %d", Level);
- Log(" TotalExperience = %d", TotalExperience);
+ Log(" Level = %u", Level);
+ Log(" TotalExperience = %u", TotalExperience);
COPY_TO_CLIENT();
return true;
}
@@ -2099,16 +2104,16 @@ bool cConnection::HandleServerSetExperience(void)
bool cConnection::HandleServerSetSlot(void)
{
- HANDLE_SERVER_PACKET_READ(ReadChar, char, WindowID);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, SlotNum);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, WindowID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, SlotNum);
AString Item;
if (!ParseSlot(m_ServerBuffer, Item))
{
return false;
}
Log("Received a PACKET_SET_SLOT from the server:");
- Log(" WindowID = %d", WindowID);
- Log(" SlotNum = %d", SlotNum);
+ Log(" WindowID = %u", WindowID);
+ Log(" SlotNum = %u", SlotNum);
Log(" Item = %s", Item.c_str());
COPY_TO_CLIENT();
return true;
@@ -2120,9 +2125,9 @@ bool cConnection::HandleServerSetSlot(void)
bool cConnection::HandleServerSlotSelect(void)
{
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, SlotNum);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, SlotNum);
Log("Received a PACKET_SLOT_SELECT from the server:");
- Log(" SlotNum = %d", SlotNum);
+ Log(" SlotNum = %u", SlotNum);
COPY_TO_CLIENT();
return true;
}
@@ -2133,17 +2138,17 @@ bool cConnection::HandleServerSlotSelect(void)
bool cConnection::HandleServerSoundEffect(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EffectID);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosX);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, PosY);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosZ);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, Data);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, NoVolumeDecrease);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, EffectID);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosX);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, PosY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, Data);
+ HANDLE_SERVER_PACKET_READ(ReadBool, bool, NoVolumeDecrease);
Log("Received a PACKET_SOUND_EFFECT from the server:");
Log(" EffectID = %d", EffectID);
Log(" Pos = {%d, %d, %d}", PosX, PosY, PosZ);
Log(" Data = %d", Data);
- Log(" NoVolumeDecrease = %d", NoVolumeDecrease);
+ Log(" NoVolumeDecrease = %s", NoVolumeDecrease ? "true" : "false");
COPY_TO_CLIENT();
return true;
}
@@ -2154,15 +2159,15 @@ bool cConnection::HandleServerSoundEffect(void)
bool cConnection::HandleServerSpawnExperienceOrbs(void)
{
- HANDLE_SERVER_PACKET_READ(ReadVarInt, UInt32, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosX);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosY);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosZ);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, Count);
+ HANDLE_SERVER_PACKET_READ(ReadVarInt, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, Count);
Log("Received a SPAWN_EXPERIENCE_ORBS packet from the server:");
Log(" EntityID = %u (0x%x)", EntityID, EntityID);
Log(" Pos = %s", PrintableAbsIntTriplet(PosX, PosY, PosZ).c_str());
- Log(" Count = %d", Count);
+ Log(" Count = %u", Count);
COPY_TO_CLIENT();
return true;
}
@@ -2174,16 +2179,16 @@ bool cConnection::HandleServerSpawnExperienceOrbs(void)
bool cConnection::HandleServerSpawnMob(void)
{
HANDLE_SERVER_PACKET_READ(ReadVarInt, UInt32, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadChar, char, MobType);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosX);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosY);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosZ);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Yaw);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Pitch);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, HeadYaw);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, VelocityX);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, VelocityY);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, VelocityZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, MobType);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Yaw);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Pitch);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, HeadYaw);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, VelocityX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, VelocityY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, VelocityZ);
AString Metadata;
if (!ParseMetadata(m_ServerBuffer, Metadata))
{
@@ -2193,11 +2198,12 @@ bool cConnection::HandleServerSpawnMob(void)
CreateHexDump(HexDump, Metadata.data(), Metadata.size(), 32);
Log("Received a PACKET_SPAWN_MOB from the server:");
Log(" EntityID = %u (0x%x)", EntityID, EntityID);
- Log(" MobType = %d", MobType);
+ Log(" MobType = %u (0x%x)", MobType, MobType);
Log(" Pos = %s", PrintableAbsIntTriplet(PosX, PosY, PosZ).c_str());
- Log(" Angles = [%d, %d, %d]", Yaw, Pitch, HeadYaw);
+ Log(" Angles = [%u, %u, %u]", Yaw, Pitch, HeadYaw);
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());
+ auto len = static_cast<unsigned>(Metadata.length());
+ Log(" Metadata, length = %u (0x%x):\n%s", len, len, HexDump.c_str());
LogMetadata(Metadata, 4);
COPY_TO_CLIENT();
return true;
@@ -2240,12 +2246,12 @@ bool cConnection::HandleServerSpawnNamedEntity(void)
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Signature)
Data.push_back(sSpawnData(Name, Value, Signature));
}
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosX);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosY);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosZ);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Yaw);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Pitch);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, CurrentItem);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Yaw);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Pitch);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, SelectedItem);
AString Metadata;
if (!ParseMetadata(m_ServerBuffer, Metadata))
{
@@ -2265,9 +2271,10 @@ bool cConnection::HandleServerSpawnNamedEntity(void)
);
} // for itr - Data[]
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());
+ Log(" Rotation = <yaw %u, pitch %u>", Yaw, Pitch);
+ Log(" SelectedItem = %u", SelectedItem);
+ auto len = static_cast<unsigned>(Metadata.length());
+ Log(" Metadata, length = %u (0x%x):\n%s", len, len, HexDump.c_str());
LogMetadata(Metadata, 4);
COPY_TO_CLIENT();
return true;
@@ -2294,26 +2301,26 @@ bool cConnection::HandleServerSpawnObjectVehicle(void)
// Only log up to 128 bytes
Buffer.erase(128, AString::npos);
}
- DataLog(Buffer.data(), Buffer.size(), "Buffer while parsing the PACKET_SPAWN_OBJECT_VEHICLE packet (%d bytes):", Buffer.size());
+ DataLog(Buffer.data(), Buffer.size(), "Buffer while parsing the PACKET_SPAWN_OBJECT_VEHICLE packet (%u bytes):", static_cast<unsigned>(Buffer.size()));
#endif // _DEBUG
- HANDLE_SERVER_PACKET_READ(ReadVarInt, UInt32, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, ObjType);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosX);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosY);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosZ);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Pitch);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Yaw);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, DataIndicator);
+ HANDLE_SERVER_PACKET_READ(ReadVarInt, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, ObjType);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Pitch);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Yaw);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, DataIndicator);
AString ExtraData;
- short VelocityX = 0;
- short VelocityY = 0;
- short VelocityZ = 0;
+ Int16 VelocityX = 0;
+ Int16 VelocityY = 0;
+ Int16 VelocityZ = 0;
if (DataIndicator != 0)
{
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, SpeedX);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, SpeedY);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, SpeedZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, SpeedX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, SpeedY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, SpeedZ);
VelocityX = SpeedX; VelocityY = SpeedY; VelocityZ = SpeedZ; // Speed vars are local to this scope, but we need them available later
/*
// This doesn't seem to work - for a falling block I'm getting no extra data at all
@@ -2340,14 +2347,14 @@ bool cConnection::HandleServerSpawnObjectVehicle(void)
}
Log("Received a PACKET_SPAWN_OBJECT_VEHICLE from the server:");
Log(" EntityID = %u (0x%x)", EntityID, EntityID);
- Log(" ObjType = %d (0x%x)", ObjType, ObjType);
+ Log(" ObjType = %u (0x%x)", ObjType, ObjType);
Log(" Pos = %s", PrintableAbsIntTriplet(PosX, PosY, PosZ).c_str());
- Log(" Rotation = <yaw %d, pitch %d>", Yaw, Pitch);
- Log(" DataIndicator = %d (0x%x)", DataIndicator, DataIndicator);
+ Log(" Rotation = <yaw %u, pitch %u>", Yaw, Pitch);
+ Log(" DataIndicator = %u (0x%x)", DataIndicator, DataIndicator);
if (DataIndicator != 0)
{
Log(" Velocity = %s", PrintableAbsIntTriplet(VelocityX, VelocityY, VelocityZ, 8000).c_str());
- DataLog(ExtraData.data(), ExtraData.size(), " ExtraData size = %d:", ExtraData.size());
+ DataLog(ExtraData.data(), ExtraData.size(), " ExtraData size = %u:", static_cast<unsigned>(ExtraData.size()));
}
COPY_TO_CLIENT();
return true;
@@ -2361,10 +2368,10 @@ bool cConnection::HandleServerSpawnPainting(void)
{
HANDLE_SERVER_PACKET_READ(ReadVarInt, UInt32, EntityID);
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, ImageName);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosX);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosY);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosZ);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, Direction);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, Direction);
Log("Received a PACKET_SPAWN_PAINTING from the server:");
Log(" EntityID = %u", EntityID);
Log(" ImageName = \"%s\"", ImageName.c_str());
@@ -2380,23 +2387,23 @@ bool cConnection::HandleServerSpawnPainting(void)
bool cConnection::HandleServerSpawnPickup(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
AString ItemDesc;
if (!ParseSlot(m_ServerBuffer, ItemDesc))
{
return false;
}
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosX);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosY);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosZ);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Rotation);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Pitch);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Roll);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Yaw);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Pitch);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Roll);
Log("Received a PACKET_SPAWN_PICKUP from the server:");
Log(" EntityID = %d", EntityID);
Log(" Item = %s", ItemDesc.c_str());
Log(" Pos = %s", PrintableAbsIntTriplet(PosX, PosY, PosZ).c_str());
- Log(" Angles = [%d, %d, %d]", Rotation, Pitch, Roll);
+ Log(" Angles = [%u, %u, %u]", Yaw, Pitch, Roll);
COPY_TO_CLIENT();
return true;
}
@@ -2446,6 +2453,10 @@ bool cConnection::HandleServerStatusResponse(void)
{
Response.assign(Response.substr(0, idx + sizeof(DescSearch) - 1) + "ProtoProxy: " + Response.substr(idx + sizeof(DescSearch) - 1));
}
+ else
+ {
+ Log("Cannot find the description json element, ProtoProxy signature not inserted");
+ }
cByteBuffer Packet(Response.size() + 50);
Packet.WriteVarInt(0); // Packet type - status response
Packet.WriteVarUTF8String(Response);
@@ -2492,8 +2503,8 @@ bool cConnection::HandleServerTabCompletion(void)
bool cConnection::HandleServerTimeUpdate(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt64, Int64, WorldAge);
- HANDLE_SERVER_PACKET_READ(ReadBEInt64, Int64, TimeOfDay);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt64, UInt64, WorldAge);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt64, UInt64, TimeOfDay);
Log("Received a PACKET_TIME_UPDATE from the server");
COPY_TO_CLIENT();
return true;
@@ -2506,7 +2517,7 @@ bool cConnection::HandleServerTimeUpdate(void)
bool cConnection::HandleServerUpdateHealth(void)
{
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, Health);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, Food);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, Food);
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, Saturation);
Log("Received a PACKET_UPDATE_HEALTH from the server");
COPY_TO_CLIENT();
@@ -2519,9 +2530,9 @@ bool cConnection::HandleServerUpdateHealth(void)
bool cConnection::HandleServerUpdateSign(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(ReadBEInt32, Int32, BlockX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, BlockY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, BlockZ);
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Line1);
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Line2);
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Line3);
@@ -2539,10 +2550,10 @@ 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(ReadBEInt32, Int32, BlockX);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt16, Int16, BlockY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, BlockZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, Action);
HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, DataLength);
AString Data;
@@ -2552,8 +2563,8 @@ bool cConnection::HandleServerUpdateTileEntity(void)
}
Log("Received a PACKET_UPDATE_TILE_ENTITY from the server:");
Log(" Block = {%d, %d, %d}", BlockX, BlockY, BlockZ);
- Log(" Action = %d", Action);
- DataLog(Data.data(), Data.size(), " Data (%u bytes)", Data.size());
+ Log(" Action = %u", Action);
+ DataLog(Data.data(), Data.size(), " Data (%u bytes)", DataLength);
// Save metadata to a file:
AString fnam;
@@ -2576,13 +2587,13 @@ bool cConnection::HandleServerUpdateTileEntity(void)
bool cConnection::HandleServerUseBed(void)
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, EntityID);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BedX);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, BedY);
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BedZ);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, EntityID);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, BedX);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, BedY);
+ HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, BedZ);
Log("Received a use bed packet from the server:");
- Log(" EntityID = %d", EntityID);
- Log(" Bed = {%d, %d, %d}", BedX, BedY, BedZ);
+ Log(" EntityID = %u", EntityID);
+ Log(" Bed = {%d, %u, %d}", BedX, BedY, BedZ);
COPY_TO_CLIENT();
return true;
}
@@ -2593,9 +2604,9 @@ bool cConnection::HandleServerUseBed(void)
bool cConnection::HandleServerWindowClose(void)
{
- HANDLE_SERVER_PACKET_READ(ReadChar, char, WindowID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, WindowID);
Log("Received a PACKET_WINDOW_CLOSE from the server:");
- Log(" WindowID = %d", WindowID);
+ Log(" WindowID = %u", WindowID);
COPY_TO_CLIENT();
return true;
}
@@ -2606,20 +2617,20 @@ bool cConnection::HandleServerWindowClose(void)
bool cConnection::HandleServerWindowContents(void)
{
- HANDLE_SERVER_PACKET_READ(ReadChar, char, WindowID);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, NumSlots);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, WindowID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, NumSlots);
Log("Received a PACKET_WINDOW_CONTENTS from the server:");
- Log(" WindowID = %d", WindowID);
- Log(" NumSlots = %d", NumSlots);
+ Log(" WindowID = %u", WindowID);
+ Log(" NumSlots = %u", NumSlots);
AStringVector Items;
- for (short i = 0; i < NumSlots; i++)
+ for (UInt16 i = 0; i < NumSlots; i++)
{
AString Item;
if (!ParseSlot(m_ServerBuffer, Item))
{
return false;
}
- Log(" %d: %s", i, Item.c_str());
+ Log(" %u: %s", i, Item.c_str());
}
COPY_TO_CLIENT();
@@ -2632,25 +2643,25 @@ bool cConnection::HandleServerWindowContents(void)
bool cConnection::HandleServerWindowOpen(void)
{
- HANDLE_SERVER_PACKET_READ(ReadChar, char, WindowID);
- HANDLE_SERVER_PACKET_READ(ReadChar, char, WindowType);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, WindowID);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, WindowType);
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Title);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, NumSlots);
- HANDLE_SERVER_PACKET_READ(ReadByte, Byte, UseProvidedTitle);
- int HorseEntityID = 0;
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, NumSlots);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt8, UInt8, UseProvidedTitle);
+ UInt32 HorseEntityID = 0;
if (WindowType == 11) // Horse / Donkey / Mule
{
- HANDLE_SERVER_PACKET_READ(ReadBEInt, int, intHorseInt);
+ HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, intHorseInt);
HorseEntityID = intHorseInt;
}
Log("Received a PACKET_WINDOW_OPEN from the server:");
- Log(" WindowID = %d", WindowID);
- Log(" WindowType = %d", WindowType);
- Log(" Title = \"%s\", Use = %d", Title.c_str(), UseProvidedTitle);
- Log(" NumSlots = %d", NumSlots);
+ Log(" WindowID = %u", WindowID);
+ Log(" WindowType = %u (0x%02x)", WindowType, WindowType);
+ Log(" Title = \"%s\", Use = %u", Title.c_str(), UseProvidedTitle);
+ Log(" NumSlots = %u", NumSlots);
if (WindowType == 11)
{
- Log(" HorseEntityID = %d (0x%08x)", HorseEntityID, HorseEntityID);
+ Log(" HorseEntityID = %u (0x%08x)", HorseEntityID, HorseEntityID);
}
COPY_TO_CLIENT();
return true;
@@ -2680,7 +2691,7 @@ bool cConnection::HandleServerUnknownPacket(UInt32 a_PacketType, UInt32 a_Packet
bool cConnection::ParseSlot(cByteBuffer & a_Buffer, AString & a_ItemDesc)
{
short ItemType;
- if (!a_Buffer.ReadBEShort(ItemType))
+ if (!a_Buffer.ReadBEInt16(ItemType))
{
return false;
}
@@ -2693,11 +2704,11 @@ bool cConnection::ParseSlot(cByteBuffer & a_Buffer, AString & a_ItemDesc)
{
return false;
}
- char ItemCount;
- short ItemDamage;
+ Int8 ItemCount;
+ Int16 ItemDamage;
UInt16 MetadataLength;
- a_Buffer.ReadChar(ItemCount); // We already know we can read these bytes - we checked before.
- a_Buffer.ReadBEShort(ItemDamage);
+ a_Buffer.ReadBEInt8(ItemCount); // We already know we can read these bytes - we checked before.
+ a_Buffer.ReadBEInt16(ItemDamage);
a_Buffer.ReadBEUInt16(MetadataLength);
Printf(a_ItemDesc, "%d:%d * %d", ItemType, ItemDamage, ItemCount);
if (MetadataLength <= 0)
@@ -2734,8 +2745,8 @@ bool cConnection::ParseSlot(cByteBuffer & a_Buffer, AString & a_ItemDesc)
bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata)
{
- Byte x;
- if (!a_Buffer.ReadByte(x))
+ UInt8 x;
+ if (!a_Buffer.ReadBEUInt8(x))
{
return false;
}
@@ -2800,7 +2811,7 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata)
return false;
}
a_Metadata.append(data);
- if (!a_Buffer.ReadByte(x))
+ if (!a_Buffer.ReadBEUInt8(x))
{
return false;
}
@@ -2826,7 +2837,7 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount)
{
case 0:
{
- Log("%sbyte[%u] = %d", Indent.c_str(), Index, a_Metadata[pos + 1]);
+ Log("%sbyte[%u] = %u", Indent.c_str(), Index, static_cast<unsigned char>(a_Metadata[pos + 1]));
pos += 1;
break;
}
@@ -2940,13 +2951,13 @@ void cConnection::SendEncryptionKeyResponse(const AString & a_ServerPublicKey, c
// Send the packet to the server:
Log("Sending PACKET_ENCRYPTION_KEY_RESPONSE to the SERVER");
cByteBuffer ToServer(1024);
- ToServer.WriteByte(0x01); // To server: Encryption key response
- ToServer.WriteBEShort((short)sizeof(EncryptedSecret));
+ ToServer.WriteBEUInt8(0x01); // To server: Encryption key response
+ ToServer.WriteBEUInt16(static_cast<UInt16>(sizeof(EncryptedSecret)));
ToServer.WriteBuf(EncryptedSecret, sizeof(EncryptedSecret));
- ToServer.WriteBEShort((short)sizeof(EncryptedNonce));
+ ToServer.WriteBEUInt16(static_cast<UInt16>(sizeof(EncryptedNonce)));
ToServer.WriteBuf(EncryptedNonce, sizeof(EncryptedNonce));
- DataLog(EncryptedSecret, sizeof(EncryptedSecret), "Encrypted secret (%u bytes)", (unsigned)sizeof(EncryptedSecret));
- DataLog(EncryptedNonce, sizeof(EncryptedNonce), "Encrypted nonce (%u bytes)", (unsigned)sizeof(EncryptedNonce));
+ DataLog(EncryptedSecret, sizeof(EncryptedSecret), "Encrypted secret (%u bytes)", static_cast<unsigned>(sizeof(EncryptedSecret)));
+ DataLog(EncryptedNonce, sizeof(EncryptedNonce), "Encrypted nonce (%u bytes)", static_cast<unsigned>(sizeof(EncryptedNonce)));
cByteBuffer Len(5);
Len.WriteVarInt(static_cast<UInt32>(ToServer.GetReadableSpace()));
SERVERSEND(Len);
diff --git a/Tools/ProtoProxy/Globals.h b/Tools/ProtoProxy/Globals.h
index a9b5aa1b1..23591b675 100644
--- a/Tools/ProtoProxy/Globals.h
+++ b/Tools/ProtoProxy/Globals.h
@@ -73,13 +73,15 @@
// Integral types with predefined sizes:
-typedef long long Int64;
-typedef int Int32;
-typedef short Int16;
+typedef signed long long Int64;
+typedef signed int Int32;
+typedef signed short Int16;
+typedef signed char Int8;
typedef unsigned long long UInt64;
typedef unsigned int UInt32;
typedef unsigned short UInt16;
+typedef unsigned char UInt8;
typedef unsigned char Byte;
diff --git a/Tools/ProtoProxy/Server.h b/Tools/ProtoProxy/Server.h
index 8adc7093d..9782503fb 100644
--- a/Tools/ProtoProxy/Server.h
+++ b/Tools/ProtoProxy/Server.h
@@ -21,7 +21,7 @@ class cServer
SOCKET m_ListenSocket;
cRsaPrivateKey m_PrivateKey;
AString m_PublicKeyDER;
- short m_ConnectPort;
+ UInt16 m_ConnectPort;
public:
cServer(void);
@@ -32,7 +32,7 @@ public:
cRsaPrivateKey & GetPrivateKey(void) { return m_PrivateKey; }
const AString & GetPublicKeyDER (void) { return m_PublicKeyDER; }
- short GetConnectPort(void) const { return m_ConnectPort; }
+ UInt16 GetConnectPort(void) const { return m_ConnectPort; }
} ;
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index f3dc44d91..325b12dd1 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -101,8 +101,8 @@ public:
assert_test(buf.Write("a", 1));
assert_test(buf.CanReadBytes(1));
assert_test(buf.GetReadableSpace() == 1);
- unsigned char v = 0;
- assert_test(buf.ReadByte(v));
+ UInt8 v = 0;
+ assert_test(buf.ReadBEUInt8(v));
assert_test(v == 'a');
assert_test(buf.GetReadableSpace() == 0);
buf.CommitRead();
@@ -317,7 +317,7 @@ bool cByteBuffer::CanWriteBytes(size_t a_Count) const
-bool cByteBuffer::ReadChar(char & a_Value)
+bool cByteBuffer::ReadBEInt8(Int8 & a_Value)
{
CHECK_THREAD
CheckValid();
@@ -330,7 +330,7 @@ bool cByteBuffer::ReadChar(char & a_Value)
-bool cByteBuffer::ReadByte(unsigned char & a_Value)
+bool cByteBuffer::ReadBEUInt8(UInt8 & a_Value)
{
CHECK_THREAD
CheckValid();
@@ -343,15 +343,15 @@ bool cByteBuffer::ReadByte(unsigned char & a_Value)
-bool cByteBuffer::ReadBEShort(short & a_Value)
+bool cByteBuffer::ReadBEInt16(Int16 & a_Value)
{
CHECK_THREAD
CheckValid();
NEEDBYTES(2);
- Int16 val;
+ UInt16 val;
ReadBuf(&val, 2);
val = ntohs(val);
- a_Value = *(reinterpret_cast<short *>(&val));
+ memcpy(&a_Value, &val, 2);
return true;
}
@@ -373,13 +373,15 @@ bool cByteBuffer::ReadBEUInt16(UInt16 & a_Value)
-bool cByteBuffer::ReadBEInt(int & a_Value)
+bool cByteBuffer::ReadBEInt32(Int32 & a_Value)
{
CHECK_THREAD
CheckValid();
NEEDBYTES(4);
- ReadBuf(&a_Value, 4);
- a_Value = (int)ntohl((u_long)a_Value);
+ UInt32 val;
+ ReadBuf(&val, 4);
+ val = ntohl(val);
+ memcpy(&a_Value, &val, 4);
return true;
}
@@ -415,6 +417,20 @@ bool cByteBuffer::ReadBEInt64(Int64 & a_Value)
+bool cByteBuffer::ReadBEUInt64(UInt64 & a_Value)
+{
+ CHECK_THREAD
+ CheckValid();
+ NEEDBYTES(8);
+ ReadBuf(&a_Value, 8);
+ a_Value = NetworkToHostULong8(&a_Value);
+ return true;
+}
+
+
+
+
+
bool cByteBuffer::ReadBEFloat(float & a_Value)
{
CHECK_THREAD
@@ -448,7 +464,7 @@ bool cByteBuffer::ReadBool(bool & a_Value)
CHECK_THREAD
CheckValid();
NEEDBYTES(1);
- char Value = 0;
+ UInt8 Value = 0;
ReadBuf(&Value, 1);
a_Value = (Value != 0);
return true;
@@ -462,17 +478,12 @@ bool cByteBuffer::ReadBEUTF16String16(AString & a_Value)
{
CHECK_THREAD
CheckValid();
- short Length;
- if (!ReadBEShort(Length))
+ UInt16 Length;
+ if (!ReadBEUInt16(Length))
{
return false;
}
- if (Length < 0)
- {
- ASSERT(!"Negative string length? Are you sure?");
- return true;
- }
- return ReadUTF16String(a_Value, (size_t)Length);
+ return ReadUTF16String(a_Value, Length);
}
@@ -565,7 +576,7 @@ bool cByteBuffer::ReadPosition(int & a_BlockX, int & a_BlockY, int & a_BlockZ)
-bool cByteBuffer::WriteChar(char a_Value)
+bool cByteBuffer::WriteBEInt8(Int8 a_Value)
{
CHECK_THREAD
CheckValid();
@@ -577,7 +588,7 @@ bool cByteBuffer::WriteChar(char a_Value)
-bool cByteBuffer::WriteByte(unsigned char a_Value)
+bool cByteBuffer::WriteBEUInt8(UInt8 a_Value)
{
CHECK_THREAD
CheckValid();
@@ -589,33 +600,48 @@ bool cByteBuffer::WriteByte(unsigned char a_Value)
-bool cByteBuffer::WriteBEShort(short a_Value)
+bool cByteBuffer::WriteBEInt16(Int16 a_Value)
{
CHECK_THREAD
CheckValid();
PUTBYTES(2);
- u_short Converted = htons((u_short)a_Value);
- return WriteBuf(&Converted, 2);
+ UInt16 val;
+ memcpy(&val, &a_Value, 2);
+ val = htons(val);
+ return WriteBuf(&val, 2);
}
-bool cByteBuffer::WriteBEUShort(unsigned short a_Value)
+bool cByteBuffer::WriteBEUInt16(UInt16 a_Value)
{
CHECK_THREAD
CheckValid();
PUTBYTES(2);
- u_short Converted = htons((u_short)a_Value);
- return WriteBuf(&Converted, 2);
+ a_Value = htons(a_Value);
+ return WriteBuf(&a_Value, 2);
+}
+
+
+
+
+
+bool cByteBuffer::WriteBEInt32(Int32 a_Value)
+{
+ CHECK_THREAD
+ CheckValid();
+ PUTBYTES(4);
+ UInt32 Converted = HostToNetwork4(&a_Value);
+ return WriteBuf(&Converted, 4);
}
-bool cByteBuffer::WriteBEInt(int a_Value)
+bool cByteBuffer::WriteBEUInt32(UInt32 a_Value)
{
CHECK_THREAD
CheckValid();
@@ -641,6 +667,19 @@ bool cByteBuffer::WriteBEInt64(Int64 a_Value)
+bool cByteBuffer::WriteBEUInt64(UInt64 a_Value)
+{
+ CHECK_THREAD
+ CheckValid();
+ PUTBYTES(8);
+ UInt64 Converted = HostToNetwork8(&a_Value);
+ return WriteBuf(&Converted, 8);
+}
+
+
+
+
+
bool cByteBuffer::WriteBEFloat(float a_Value)
{
CHECK_THREAD
@@ -672,7 +711,8 @@ bool cByteBuffer::WriteBool(bool a_Value)
{
CHECK_THREAD
CheckValid();
- return WriteChar(a_Value ? 1 : 0);
+ UInt8 val = a_Value ? 1 : 0;
+ return Write(&val, 1);
}
@@ -717,7 +757,7 @@ bool cByteBuffer::WriteVarUTF8String(const AString & a_Value)
-bool cByteBuffer::WriteLEInt(int a_Value)
+bool cByteBuffer::WriteLEInt32(Int32 a_Value)
{
CHECK_THREAD
CheckValid();
@@ -733,9 +773,10 @@ bool cByteBuffer::WriteLEInt(int a_Value)
-bool cByteBuffer::WritePosition(int a_BlockX, int a_BlockY, int a_BlockZ)
+bool cByteBuffer::WritePosition(Int32 a_BlockX, Int32 a_BlockY, Int32 a_BlockZ)
{
CHECK_THREAD
+ CheckValid();
return WriteBEInt64(((Int64)a_BlockX & 0x3FFFFFF) << 38 | ((Int64)a_BlockY & 0xFFF) << 26 | ((Int64)a_BlockZ & 0x3FFFFFF));
}
diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h
index f480ad557..0e50c948a 100644
--- a/src/ByteBuffer.h
+++ b/src/ByteBuffer.h
@@ -52,13 +52,14 @@ public:
bool CanWriteBytes(size_t a_Count) const;
// Read the specified datatype and advance the read pointer; return true if successfully read:
- bool ReadChar (char & a_Value);
- bool ReadByte (unsigned char & a_Value);
- bool ReadBEShort (short & a_Value);
+ bool ReadBEInt8 (Int8 & a_Value);
+ bool ReadBEInt16 (Int16 & a_Value);
+ bool ReadBEInt32 (Int32 & a_Value);
+ bool ReadBEInt64 (Int64 & a_Value);
+ bool ReadBEUInt8 (UInt8 & a_Value);
bool ReadBEUInt16 (UInt16 & a_Value);
- bool ReadBEInt (int & a_Value);
bool ReadBEUInt32 (UInt32 & a_Value);
- bool ReadBEInt64 (Int64 & a_Value);
+ bool ReadBEUInt64 (UInt64 & a_Value);
bool ReadBEFloat (float & a_Value);
bool ReadBEDouble (double & a_Value);
bool ReadBool (bool & a_Value);
@@ -81,19 +82,21 @@ public:
}
// Write the specified datatype; return true if successfully written
- bool WriteChar (char a_Value);
- bool WriteByte (unsigned char a_Value);
- bool WriteBEShort (short a_Value);
- bool WriteBEUShort (unsigned short a_Value);
- bool WriteBEInt (int a_Value);
+ bool WriteBEInt8 (Int8 a_Value);
+ bool WriteBEInt16 (Int16 a_Value);
+ bool WriteBEInt32 (Int32 a_Value);
bool WriteBEInt64 (Int64 a_Value);
+ bool WriteBEUInt8 (UInt8 a_Value);
+ bool WriteBEUInt16 (UInt16 a_Value);
+ bool WriteBEUInt32 (UInt32 a_Value);
+ bool WriteBEUInt64 (UInt64 a_Value);
bool WriteBEFloat (float a_Value);
bool WriteBEDouble (double a_Value);
bool WriteBool (bool a_Value);
bool WriteVarInt (UInt32 a_Value);
bool WriteVarUTF8String (const AString & a_Value); // string length as VarInt, then string as UTF-8
- bool WriteLEInt (int a_Value);
- bool WritePosition (int a_BlockX, int a_BlockY, int a_BlockZ);
+ bool WriteLEInt32 (Int32 a_Value);
+ bool WritePosition (Int32 a_BlockX, Int32 a_BlockY, Int32 a_BlockZ);
/** Reads a_Count bytes into a_Buffer; returns true if successful */
bool ReadBuf(void * a_Buffer, size_t a_Count);
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index ec10ac521..c0ba551d4 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -676,7 +676,7 @@ bool cClientHandle::HandleLogin(int a_ProtocolVersion, const AString & a_Usernam
-void cClientHandle::HandleCreativeInventory(short a_SlotNum, const cItem & a_HeldItem)
+void cClientHandle::HandleCreativeInventory(Int16 a_SlotNum, const cItem & a_HeldItem, eClickAction a_ClickAction)
{
// This is for creative Inventory changes
if (!m_Player->IsGameModeCreative())
@@ -690,18 +690,18 @@ void cClientHandle::HandleCreativeInventory(short a_SlotNum, const cItem & a_Hel
return;
}
- m_Player->GetWindow()->Clicked(*m_Player, 0, a_SlotNum, (a_SlotNum >= 0) ? caLeftClick : caLeftClickOutside, a_HeldItem);
+ m_Player->GetWindow()->Clicked(*m_Player, 0, a_SlotNum, a_ClickAction, a_HeldItem);
}
-void cClientHandle::HandleEnchantItem(Byte a_WindowID, Byte a_Enchantment)
+void cClientHandle::HandleEnchantItem(UInt8 a_WindowID, UInt8 a_Enchantment)
{
if (a_Enchantment > 2)
{
- LOGWARNING("%s attempt to crash the server with invalid enchanting selection!", GetUsername().c_str());
+ LOGWARNING("%s attempt to crash the server with invalid enchanting selection (%u)!", GetUsername().c_str(), a_Enchantment);
Kick("Invalid enchanting!");
return;
}
@@ -951,7 +951,7 @@ void cClientHandle::HandleCommandBlockBlockChange(int a_BlockX, int a_BlockY, in
-void cClientHandle::HandleCommandBlockEntityChange(int a_EntityID, const AString & a_NewCommand)
+void cClientHandle::HandleCommandBlockEntityChange(UInt32 a_EntityID, const AString & a_NewCommand)
{
// TODO
LOGWARNING("%s: Not implemented yet", __FUNCTION__);
@@ -1509,7 +1509,7 @@ void cClientHandle::HandleAnimation(int a_Animation)
-void cClientHandle::HandleSlotSelected(short a_SlotNum)
+void cClientHandle::HandleSlotSelected(Int16 a_SlotNum)
{
m_Player->GetInventory().SetEquippedSlotNum(a_SlotNum);
m_Player->GetWorld()->BroadcastEntityEquipment(*m_Player, 0, m_Player->GetInventory().GetEquippedItem(), this);
@@ -1528,7 +1528,7 @@ void cClientHandle::HandleSteerVehicle(float a_Forward, float a_Sideways)
-void cClientHandle::HandleWindowClose(char a_WindowID)
+void cClientHandle::HandleWindowClose(UInt8 a_WindowID)
{
m_Player->CloseWindowIfID(a_WindowID);
}
@@ -1537,7 +1537,7 @@ void cClientHandle::HandleWindowClose(char a_WindowID)
-void cClientHandle::HandleWindowClick(char a_WindowID, short a_SlotNum, eClickAction a_ClickAction, const cItem & a_HeldItem)
+void cClientHandle::HandleWindowClick(UInt8 a_WindowID, Int16 a_SlotNum, eClickAction a_ClickAction, const cItem & a_HeldItem)
{
LOGD("WindowClick: WinID %d, SlotNum %d, action: %s, Item %s x %d",
a_WindowID, a_SlotNum, ClickActionToString(a_ClickAction),
@@ -1575,7 +1575,7 @@ void cClientHandle::HandleUpdateSign(
-void cClientHandle::HandleUseEntity(int a_TargetEntityID, bool a_IsLeftClick)
+void cClientHandle::HandleUseEntity(UInt32 a_TargetEntityID, bool a_IsLeftClick)
{
// TODO: Let plugins interfere via a hook
@@ -1720,7 +1720,7 @@ bool cClientHandle::HandleHandshake(const AString & a_Username)
-void cClientHandle::HandleEntityCrouch(int a_EntityID, bool a_IsCrouching)
+void cClientHandle::HandleEntityCrouch(UInt32 a_EntityID, bool a_IsCrouching)
{
if (a_EntityID != m_Player->GetUniqueID())
{
@@ -1735,7 +1735,7 @@ void cClientHandle::HandleEntityCrouch(int a_EntityID, bool a_IsCrouching)
-void cClientHandle::HandleEntityLeaveBed(int a_EntityID)
+void cClientHandle::HandleEntityLeaveBed(UInt32 a_EntityID)
{
if (a_EntityID != m_Player->GetUniqueID())
{
@@ -1752,7 +1752,7 @@ void cClientHandle::HandleEntityLeaveBed(int a_EntityID)
-void cClientHandle::HandleEntitySprinting(int a_EntityID, bool a_IsSprinting)
+void cClientHandle::HandleEntitySprinting(UInt32 a_EntityID, bool a_IsSprinting)
{
if (a_EntityID != m_Player->GetUniqueID())
{
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 8129d6a50..e66d0d1b6 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -276,16 +276,18 @@ public: // tolua_export
/** Called when the protocol receives a MC|AdvCdm plugin message, indicating that the player set a new
command in the command block UI, for an entity-based commandblock (minecart?). */
- void HandleCommandBlockEntityChange(int a_EntityID, const AString & a_NewCommand);
+ void HandleCommandBlockEntityChange(UInt32 a_EntityID, const AString & a_NewCommand);
- void HandleCreativeInventory (short a_SlotNum, const cItem & a_HeldItem);
+ /** Called when the client clicks the creative inventory window.
+ a_ClickAction specifies whether the click was inside the window or not (caLeftClick or caLeftClickOutside). */
+ void HandleCreativeInventory(Int16 a_SlotNum, const cItem & a_HeldItem, eClickAction a_ClickAction);
/** Called when the player enchants an Item in the Enchanting table UI. */
- void HandleEnchantItem(Byte a_WindowID, Byte a_Enchantment);
+ void HandleEnchantItem(UInt8 a_WindowID, UInt8 a_Enchantment);
- void HandleEntityCrouch (int a_EntityID, bool a_IsCrouching);
- void HandleEntityLeaveBed (int a_EntityID);
- void HandleEntitySprinting (int a_EntityID, bool a_IsSprinting);
+ void HandleEntityCrouch (UInt32 a_EntityID, bool a_IsCrouching);
+ void HandleEntityLeaveBed (UInt32 a_EntityID);
+ void HandleEntitySprinting (UInt32 a_EntityID, bool a_IsSprinting);
/** Kicks the client if the same username is already logged in.
Returns false if the client has been kicked, true otherwise. */
@@ -312,7 +314,7 @@ public: // tolua_export
void HandlePluginMessage (const AString & a_Channel, const AString & a_Message);
void HandleRespawn (void);
void HandleRightClick (int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, const cItem & a_HeldItem);
- void HandleSlotSelected (short a_SlotNum);
+ void HandleSlotSelected (Int16 a_SlotNum);
void HandleSteerVehicle (float Forward, float Sideways);
void HandleTabCompletion (const AString & a_Text);
void HandleUpdateSign (
@@ -321,9 +323,9 @@ public: // tolua_export
const AString & a_Line3, const AString & a_Line4
);
void HandleUnmount (void);
- void HandleUseEntity (int a_TargetEntityID, bool a_IsLeftClick);
- void HandleWindowClick (char a_WindowID, short a_SlotNum, eClickAction a_ClickAction, const cItem & a_HeldItem);
- void HandleWindowClose (char a_WindowID);
+ void HandleUseEntity (UInt32 a_TargetEntityID, bool a_IsLeftClick);
+ void HandleWindowClick (UInt8 a_WindowID, Int16 a_SlotNum, eClickAction a_ClickAction, const cItem & a_HeldItem);
+ void HandleWindowClose (UInt8 a_WindowID);
/** Called when the protocol has finished logging the user in.
Return true to allow the user in; false to kick them.
diff --git a/src/Endianness.h b/src/Endianness.h
index 5692b3811..ed9637fcc 100644
--- a/src/Endianness.h
+++ b/src/Endianness.h
@@ -59,6 +59,18 @@ inline Int64 NetworkToHostLong8(const void * a_Value)
+inline UInt64 NetworkToHostULong8(const void * a_Value)
+{
+ UInt64 buf;
+ memcpy(&buf, a_Value, 8);
+ buf = ntohll(buf);
+ return buf;
+}
+
+
+
+
+
inline float NetworkToHostFloat4(const void * a_Value)
{
UInt32 buf;
diff --git a/src/Globals.h b/src/Globals.h
index 7c2ab38d8..bd180c08f 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -132,13 +132,15 @@
// Integral types with predefined sizes:
-typedef long long Int64;
-typedef int Int32;
-typedef short Int16;
+typedef signed long long Int64;
+typedef signed int Int32;
+typedef signed short Int16;
+typedef signed char Int8;
typedef unsigned long long UInt64;
typedef unsigned int UInt32;
typedef unsigned short UInt16;
+typedef unsigned char UInt8;
typedef unsigned char Byte;
@@ -156,10 +158,12 @@ class SizeChecker<T, Size, true>
template class SizeChecker<Int64, 8>;
template class SizeChecker<Int32, 4>;
template class SizeChecker<Int16, 2>;
+template class SizeChecker<Int8, 1>;
template class SizeChecker<UInt64, 8>;
template class SizeChecker<UInt32, 4>;
template class SizeChecker<UInt16, 2>;
+template class SizeChecker<UInt8, 1>;
// A macro to disallow the copy constructor and operator = functions
// This should be used in the private: declarations for any class that shouldn't allow copying itself
diff --git a/src/Protocol/ChunkDataSerializer.cpp b/src/Protocol/ChunkDataSerializer.cpp
index 5d080656d..e850ceaec 100644
--- a/src/Protocol/ChunkDataSerializer.cpp
+++ b/src/Protocol/ChunkDataSerializer.cpp
@@ -188,10 +188,10 @@ void cChunkDataSerializer::Serialize47(AString & a_Data, int a_ChunkX, int a_Chu
// Create the packet:
cByteBuffer Packet(512 KiB);
Packet.WriteVarInt(0x21); // Packet id (Chunk Data packet)
- Packet.WriteBEInt(a_ChunkX);
- Packet.WriteBEInt(a_ChunkZ);
- Packet.WriteBool(true); // "Ground-up continuous", or rather, "biome data present" flag
- Packet.WriteBEUShort(0xffff); // We're aways sending the full chunk with no additional data, so the bitmap is 0xffff
+ Packet.WriteBEInt32(a_ChunkX);
+ Packet.WriteBEInt32(a_ChunkZ);
+ Packet.WriteBool(true); // "Ground-up continuous", or rather, "biome data present" flag
+ Packet.WriteBEUInt16(0xffff); // We're aways sending the full chunk with no additional data, so the bitmap is 0xffff
// Write the chunk size:
const int BiomeDataSize = cChunkDef::Width * cChunkDef::Width;
@@ -208,8 +208,8 @@ void cChunkDataSerializer::Serialize47(AString & a_Data, int a_ChunkX, int a_Chu
{
BLOCKTYPE BlockType = m_BlockTypes[Index] & 0xFF;
NIBBLETYPE BlockMeta = m_BlockMetas[Index / 2] >> ((Index & 1) * 4) & 0x0f;
- Packet.WriteByte((unsigned char)(BlockType << 4) | BlockMeta);
- Packet.WriteByte((unsigned char)(BlockType >> 4));
+ Packet.WriteBEUInt8(static_cast<unsigned char>(BlockType << 4) | BlockMeta);
+ Packet.WriteBEUInt8(static_cast<unsigned char>(BlockType >> 4));
}
// Write the rest:
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 9abe81238..797e32a75 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -50,6 +50,13 @@ Implements the 1.7.x protocol classes:
+/** The slot number that the client uses to indicate "outside the window". */
+static const Int16 SLOT_NUM_OUTSIDE = -999;
+
+
+
+
+
#define HANDLE_READ(ByteBuf, Proc, Type, Var) \
Type Var; \
if (!ByteBuf.Proc(Var))\
@@ -1006,8 +1013,8 @@ void cProtocol172::SendExperience (void)
cPacketizer Pkt(*this, 0x1f); // Experience Packet
cPlayer * Player = m_Client->GetPlayer();
Pkt.WriteFloat(Player->GetXpPercentage());
- Pkt.WriteShort(Player->GetXpLevel());
- Pkt.WriteShort(Player->GetCurrentXp());
+ Pkt.WriteShort(static_cast<UInt16>(std::max<int>(Player->GetXpLevel(), std::numeric_limits<UInt16>::max())));
+ Pkt.WriteShort(static_cast<UInt16>(std::max<int>(Player->GetCurrentXp(), std::numeric_limits<UInt16>::max())));
}
@@ -1198,9 +1205,9 @@ void cProtocol172::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp
Pkt.WriteInt(a_VehicleSubType);
if (a_VehicleSubType != 0)
{
- Pkt.WriteShort(static_cast<short>(a_Vehicle.GetSpeedX() * 400));
- Pkt.WriteShort(static_cast<short>(a_Vehicle.GetSpeedY() * 400));
- Pkt.WriteShort(static_cast<short>(a_Vehicle.GetSpeedZ() * 400));
+ Pkt.WriteShort(static_cast<Int16>(a_Vehicle.GetSpeedX() * 400));
+ Pkt.WriteShort(static_cast<Int16>(a_Vehicle.GetSpeedY() * 400));
+ Pkt.WriteShort(static_cast<Int16>(a_Vehicle.GetSpeedZ() * 400));
}
}
@@ -1756,34 +1763,34 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer)
{
- short EncKeyLength, EncNonceLength;
- if (!a_ByteBuffer.ReadBEShort(EncKeyLength))
+ UInt16 EncKeyLength, EncNonceLength;
+ if (!a_ByteBuffer.ReadBEUInt16(EncKeyLength))
{
return;
}
- if ((EncKeyLength < 0) || (EncKeyLength > MAX_ENC_LEN))
+ if (EncKeyLength > MAX_ENC_LEN)
{
- LOGD("Invalid Encryption Key length: %d. Kicking client.", EncKeyLength);
+ LOGD("Invalid Encryption Key length: %u (0x%04x). Kicking client.", EncKeyLength, EncKeyLength);
m_Client->Kick("Invalid EncKeyLength");
return;
}
AString EncKey;
- if (!a_ByteBuffer.ReadString(EncKey, static_cast<size_t>(EncKeyLength)))
+ if (!a_ByteBuffer.ReadString(EncKey, EncKeyLength))
{
return;
}
- if (!a_ByteBuffer.ReadBEShort(EncNonceLength))
+ if (!a_ByteBuffer.ReadBEUInt16(EncNonceLength))
{
return;
}
- if ((EncNonceLength < 0) || (EncNonceLength > MAX_ENC_LEN))
+ if (EncNonceLength > MAX_ENC_LEN)
{
- LOGD("Invalid Encryption Nonce length: %d. Kicking client.", EncNonceLength);
+ LOGD("Invalid Encryption Nonce length: %u (0x%04x). Kicking client.", EncNonceLength, EncNonceLength);
m_Client->Kick("Invalid EncNonceLength");
return;
}
AString EncNonce;
- if (!a_ByteBuffer.ReadString(EncNonce, static_cast<size_t>(EncNonceLength)))
+ if (!a_ByteBuffer.ReadString(EncNonce, EncNonceLength))
{
return;
}
@@ -1791,7 +1798,10 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe
// Decrypt EncNonce using privkey
cRsaPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey();
Int32 DecryptedNonce[MAX_ENC_LEN / sizeof(Int32)];
- int res = rsaDecryptor.Decrypt((const Byte *)EncNonce.data(), EncNonce.size(), (Byte *)DecryptedNonce, sizeof(DecryptedNonce));
+ int res = rsaDecryptor.Decrypt(
+ reinterpret_cast<const Byte *>(EncNonce.data()), EncNonce.size(),
+ reinterpret_cast<Byte *>(DecryptedNonce), sizeof(DecryptedNonce)
+ );
if (res != 4)
{
LOGD("Bad nonce length: got %d, exp %d", res, 4);
@@ -1862,8 +1872,8 @@ void cProtocol172::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketAnimation(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, EntityID);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Animation);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt32, UInt32, EntityID);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Animation);
m_Client->HandleAnimation(Animation);
}
@@ -1873,12 +1883,12 @@ void cProtocol172::HandlePacketAnimation(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadChar, char, Status);
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, BlockY);
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ);
- HANDLE_READ(a_ByteBuffer, ReadChar, char, Face);
- m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, static_cast<eBlockFace>(Face), Status);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Status);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, BlockY);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt8, Int8, Face);
+ m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), Status);
}
@@ -1887,17 +1897,17 @@ void cProtocol172::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, BlockY);
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ);
- HANDLE_READ(a_ByteBuffer, ReadChar, char, Face);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, BlockY);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Face);
cItem Item;
ReadItem(a_ByteBuffer, Item);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorX);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorY);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorZ);
- m_Client->HandleRightClick(BlockX, BlockY, BlockZ, static_cast<eBlockFace>(Face), CursorX, CursorY, CursorZ, m_Client->GetPlayer()->GetEquippedItem());
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorX);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorY);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorZ);
+ m_Client->HandleRightClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), CursorX, CursorY, CursorZ, m_Client->GetPlayer()->GetEquippedItem());
}
@@ -1917,11 +1927,11 @@ void cProtocol172::HandlePacketChatMessage(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Locale);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ViewDistance);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ChatFlags);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ChatColors);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Difficulty);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ShowCape);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ViewDistance);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ChatFlags);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ChatColors);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Difficulty);
+ HANDLE_READ(a_ByteBuffer, ReadBool, bool, ShowCape);
m_Client->SetLocale(Locale);
m_Client->SetViewDistance(ViewDistance);
@@ -1934,7 +1944,7 @@ void cProtocol172::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketClientStatus(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ActionID);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ActionID);
switch (ActionID)
{
case 0:
@@ -1966,13 +1976,13 @@ void cProtocol172::HandlePacketClientStatus(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadBEShort, short, SlotNum);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum);
cItem Item;
if (!ReadItem(a_ByteBuffer, Item))
{
return;
}
- m_Client->HandleCreativeInventory(SlotNum, Item);
+ m_Client->HandleCreativeInventory(SlotNum, Item, (SlotNum < 0) ? caLeftClick : caLeftClickOutside);
}
@@ -1981,9 +1991,9 @@ void cProtocol172::HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffe
void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, PlayerID);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Action);
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, JumpBoost);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt32, UInt32, PlayerID);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Action);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, JumpBoost);
switch (Action)
{
@@ -2001,7 +2011,7 @@ void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketKeepAlive(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, KeepAliveID);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, KeepAliveID);
m_Client->HandleKeepAlive(KeepAliveID);
}
@@ -2021,10 +2031,11 @@ void cProtocol172::HandlePacketPlayer(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketPlayerAbilities(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Flags);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Flags);
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, FlyingSpeed);
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, WalkingSpeed);
+ // Convert flags bitfield into individual bool flags:
bool IsFlying = false, CanFly = false;
if ((Flags & 2) != 0)
{
@@ -2087,11 +2098,11 @@ void cProtocol172::HandlePacketPlayerPosLook(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel);
- HANDLE_READ(a_ByteBuffer, ReadBEShort, short, Length);
- if (Length + 1 != (int)a_ByteBuffer.GetReadableSpace())
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt16, UInt16, Length);
+ if (Length != a_ByteBuffer.GetReadableSpace() - 1)
{
- LOGD("Invalid plugin message packet, payload length doesn't match packet length (exp %d, got %d)",
- static_cast<int>(a_ByteBuffer.GetReadableSpace()) - 1, Length
+ LOGD("Invalid plugin message packet, payload length doesn't match packet length (exp %u, got %u)",
+ a_ByteBuffer.GetReadableSpace() - 1, Length
);
return;
}
@@ -2105,7 +2116,7 @@ void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
// Read the plugin message and relay to clienthandle:
AString Data;
- if (!a_ByteBuffer.ReadString(Data, static_cast<size_t>(Length)))
+ if (!a_ByteBuffer.ReadString(Data, Length))
{
return;
}
@@ -2118,7 +2129,7 @@ void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketSlotSelect(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadBEShort, short, SlotNum);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt16, UInt16, SlotNum);
m_Client->HandleSlotSelected(SlotNum);
}
@@ -2158,9 +2169,9 @@ void cProtocol172::HandlePacketTabComplete(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX);
- HANDLE_READ(a_ByteBuffer, ReadBEShort, short, BlockY);
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, BlockY);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ);
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line1);
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line2);
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line3);
@@ -2174,8 +2185,8 @@ void cProtocol172::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, EntityID);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, MouseButton);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt32, UInt32, EntityID);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, MouseButton);
m_Client->HandleUseEntity(EntityID, (MouseButton == 1));
}
@@ -2185,8 +2196,8 @@ void cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Enchantment);
m_Client->HandleEnchantItem(WindowID, Enchantment);
}
@@ -2197,11 +2208,11 @@ void cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadChar, char, WindowID);
- HANDLE_READ(a_ByteBuffer, ReadBEShort, short, SlotNum);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Button);
- HANDLE_READ(a_ByteBuffer, ReadBEShort, short, TransactionID);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Mode);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Button);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt16, UInt16, TransactionID);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Mode);
cItem Item;
ReadItem(a_ByteBuffer, Item);
@@ -2209,8 +2220,8 @@ void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
eClickAction Action;
switch ((Mode << 8) | Button)
{
- case 0x0000: Action = (SlotNum != -999) ? caLeftClick : caLeftClickOutside; break;
- case 0x0001: Action = (SlotNum != -999) ? caRightClick : caRightClickOutside; break;
+ case 0x0000: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caLeftClick : caLeftClickOutside; break;
+ case 0x0001: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caRightClick : caRightClickOutside; break;
case 0x0100: Action = caShiftLeftClick; break;
case 0x0101: Action = caShiftRightClick; break;
case 0x0200: Action = caNumber1; break;
@@ -2223,14 +2234,14 @@ void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
case 0x0207: Action = caNumber8; break;
case 0x0208: Action = caNumber9; break;
case 0x0300: Action = caMiddleClick; break;
- case 0x0400: Action = (SlotNum == -999) ? caLeftClickOutsideHoldNothing : caDropKey; break;
- case 0x0401: Action = (SlotNum == -999) ? caRightClickOutsideHoldNothing : caCtrlDropKey; break;
- case 0x0500: Action = (SlotNum == -999) ? caLeftPaintBegin : caUnknown; break;
- case 0x0501: Action = (SlotNum != -999) ? caLeftPaintProgress : caUnknown; break;
- case 0x0502: Action = (SlotNum == -999) ? caLeftPaintEnd : caUnknown; break;
- case 0x0504: Action = (SlotNum == -999) ? caRightPaintBegin : caUnknown; break;
- case 0x0505: Action = (SlotNum != -999) ? caRightPaintProgress : caUnknown; break;
- case 0x0506: Action = (SlotNum == -999) ? caRightPaintEnd : caUnknown; break;
+ case 0x0400: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftClickOutsideHoldNothing : caDropKey; break;
+ case 0x0401: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightClickOutsideHoldNothing : caCtrlDropKey; break;
+ case 0x0500: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftPaintBegin : caUnknown; break;
+ case 0x0501: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caLeftPaintProgress : caUnknown; break;
+ case 0x0502: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftPaintEnd : caUnknown; break;
+ case 0x0504: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintBegin : caUnknown; break;
+ case 0x0505: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caRightPaintProgress : caUnknown; break;
+ case 0x0506: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintEnd : caUnknown; break;
case 0x0600: Action = caDblClick; break;
default:
{
@@ -2249,7 +2260,7 @@ void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketWindowClose(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadChar, char, WindowID);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
m_Client->HandleWindowClose(WindowID);
}
@@ -2257,20 +2268,20 @@ void cProtocol172::HandlePacketWindowClose(cByteBuffer & a_ByteBuffer)
-void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const AString & a_Channel, short a_PayloadLength)
+void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const AString & a_Channel, UInt16 a_PayloadLength)
{
if (a_Channel == "MC|AdvCdm")
{
size_t BeginningSpace = a_ByteBuffer.GetReadableSpace();
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Mode);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Mode);
switch (Mode)
{
case 0x00:
{
// Block-based commandblock update:
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX);
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockY);
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockY);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ);
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Command);
m_Client->HandleCommandBlockBlockChange(BlockX, BlockY, BlockZ, Command);
break;
@@ -2288,12 +2299,12 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
// Read the remainder of the packet (Vanilla sometimes sends bogus data at the end of the packet; #1692):
size_t BytesRead = BeginningSpace - a_ByteBuffer.GetReadableSpace();
- if (BytesRead < static_cast<size_t>(a_PayloadLength))
+ if (BytesRead < a_PayloadLength)
{
LOGD("Protocol 1.7: Skipping garbage data at the end of a vanilla MC|AdvCdm packet, %u bytes",
static_cast<unsigned>(a_PayloadLength - BytesRead)
);
- a_ByteBuffer.SkipRead(static_cast<size_t>(a_PayloadLength) - BytesRead);
+ a_ByteBuffer.SkipRead(a_PayloadLength - BytesRead);
}
return;
}
@@ -2301,7 +2312,7 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
{
// Read the client's brand:
AString Brand;
- if (a_ByteBuffer.ReadString(Brand, static_cast<size_t>(a_PayloadLength)))
+ if (a_ByteBuffer.ReadString(Brand, a_PayloadLength))
{
m_Client->SetClientBrand(Brand);
}
@@ -2312,15 +2323,15 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
}
else if (a_Channel == "MC|Beacon")
{
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, Effect1);
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, Effect2);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect1);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect2);
m_Client->HandleBeaconSelection(Effect1, Effect2);
return;
}
else if (a_Channel == "MC|ItemName")
{
AString ItemName;
- if (a_ByteBuffer.ReadString(ItemName, static_cast<size_t>(a_PayloadLength)))
+ if (a_ByteBuffer.ReadString(ItemName, a_PayloadLength))
{
m_Client->HandleAnvilItemName(ItemName);
}
@@ -2328,7 +2339,7 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
}
else if (a_Channel == "MC|TrSel")
{
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, SlotNum);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, SlotNum);
m_Client->HandleNPCTrade(SlotNum);
return;
}
@@ -2336,7 +2347,7 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
// Read the payload and send it through to the clienthandle:
AString Message;
- VERIFY(a_ByteBuffer.ReadString(Message, static_cast<size_t>(a_PayloadLength)));
+ VERIFY(a_ByteBuffer.ReadString(Message, a_PayloadLength));
m_Client->HandlePluginMessage(a_Channel, Message);
}
@@ -2370,7 +2381,7 @@ void cProtocol172::SendData(const char * a_Data, size_t a_Size)
bool cProtocol172::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item)
{
- HANDLE_PACKET_READ(a_ByteBuffer, ReadBEShort, short, ItemType);
+ HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemType);
if (ItemType == -1)
{
// The item is empty, no more data follows
@@ -2379,8 +2390,8 @@ bool cProtocol172::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item)
}
a_Item.m_ItemType = ItemType;
- HANDLE_PACKET_READ(a_ByteBuffer, ReadChar, char, ItemCount);
- HANDLE_PACKET_READ(a_ByteBuffer, ReadBEShort, short, ItemDamage);
+ HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt8, Int8, ItemCount);
+ HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemDamage);
a_Item.m_ItemCount = ItemCount;
a_Item.m_ItemDamage = ItemDamage;
if (ItemCount <= 0)
@@ -2388,15 +2399,10 @@ bool cProtocol172::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item)
a_Item.Empty();
}
- HANDLE_PACKET_READ(a_ByteBuffer, ReadBEShort, short, MetadataLength);
- if (MetadataLength <= 0)
- {
- return true;
- }
-
// Read the metadata
+ HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt16, UInt16, MetadataLength);
AString Metadata;
- if (!a_ByteBuffer.ReadString(Metadata, static_cast<size_t>(MetadataLength)))
+ if (!a_ByteBuffer.ReadString(Metadata, MetadataLength))
{
return false;
}
@@ -2512,6 +2518,26 @@ void cProtocol172::StartEncryption(const Byte * a_Key)
+eBlockFace cProtocol172::FaceIntToBlockFace(Int8 a_BlockFace)
+{
+ // Normalize the blockface values returned from the protocol
+ // Anything known gets mapped 1:1, everything else returns BLOCK_FACE_NONE
+ switch (a_BlockFace)
+ {
+ case BLOCK_FACE_XM: return BLOCK_FACE_XM;
+ case BLOCK_FACE_XP: return BLOCK_FACE_XP;
+ case BLOCK_FACE_YM: return BLOCK_FACE_YM;
+ case BLOCK_FACE_YP: return BLOCK_FACE_YP;
+ case BLOCK_FACE_ZM: return BLOCK_FACE_ZM;
+ case BLOCK_FACE_ZP: return BLOCK_FACE_ZP;
+ default: return BLOCK_FACE_NONE;
+ }
+}
+
+
+
+
+
////////////////////////////////////////////////////////////////////////////////
// cProtocol172::cPacketizer:
@@ -2520,7 +2546,7 @@ cProtocol172::cPacketizer::~cPacketizer()
AString DataToSend;
// Send the packet length
- UInt32 PacketLen = (UInt32)m_Out.GetUsedSpace();
+ UInt32 PacketLen = static_cast<UInt32>(m_Out.GetUsedSpace());
m_Protocol.m_OutPacketLenBuffer.WriteVarInt(PacketLen);
m_Protocol.m_OutPacketLenBuffer.ReadAll(DataToSend);
diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h
index f939bfb5e..2ee247330 100644
--- a/src/Protocol/Protocol17x.h
+++ b/src/Protocol/Protocol17x.h
@@ -161,22 +161,22 @@ protected:
void WriteByte(Byte a_Value)
{
- m_Out.WriteByte(a_Value);
+ m_Out.WriteBEUInt8(a_Value);
}
void WriteChar(char a_Value)
{
- m_Out.WriteChar(a_Value);
+ m_Out.WriteBEInt8(a_Value);
}
void WriteShort(short a_Value)
{
- m_Out.WriteBEShort(a_Value);
+ m_Out.WriteBEInt16(a_Value);
}
- void WriteInt(int a_Value)
+ void WriteInt(Int32 a_Value)
{
- m_Out.WriteBEInt(a_Value);
+ m_Out.WriteBEInt32(a_Value);
}
void WriteInt64(Int64 a_Value)
@@ -297,7 +297,7 @@ protected:
/** Parses Vanilla plugin messages into specific ClientHandle calls.
The message payload is still in the bytebuffer, to be read by this function. */
- void HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const AString & a_Channel, short a_PayloadLength);
+ void HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const AString & a_Channel, UInt16 a_PayloadLength);
/** Sends the data to the client, encrypting them if needed. */
virtual void SendData(const char * a_Data, size_t a_Size) override;
@@ -312,6 +312,9 @@ protected:
void StartEncryption(const Byte * a_Key);
+ /** Converts the BlockFace received by the protocol into eBlockFace constants.
+ If the received value doesn't match any of our eBlockFace constants, BLOCK_FACE_NONE is returned. */
+ eBlockFace FaceIntToBlockFace(Int8 a_FaceInt);
} ;
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp
index 2d1a473d1..a80edbc22 100644
--- a/src/Protocol/Protocol18x.cpp
+++ b/src/Protocol/Protocol18x.cpp
@@ -49,6 +49,13 @@ Implements the 1.8.x protocol classes:
+/** The slot number that the client uses to indicate "outside the window". */
+static const Int16 SLOT_NUM_OUTSIDE = -999;
+
+
+
+
+
#define HANDLE_READ(ByteBuf, Proc, Type, Var) \
Type Var; \
if (!ByteBuf.Proc(Var))\
@@ -2106,7 +2113,7 @@ void cProtocol180::HandlePacketAnimation(cByteBuffer & a_ByteBuffer)
void cProtocol180::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Status);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Status);
int BlockX, BlockY, BlockZ;
if (!a_ByteBuffer.ReadPosition(BlockX, BlockY, BlockZ))
@@ -2114,8 +2121,8 @@ void cProtocol180::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer)
return;
}
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Face);
- m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, static_cast<eBlockFace>(Face), Status);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt8, Int8, Face);
+ m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), Status);
}
@@ -2130,19 +2137,15 @@ void cProtocol180::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer)
return;
}
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Face);
- if (Face == 255)
- {
- Face = 0;
- }
+ HANDLE_READ(a_ByteBuffer, ReadBEInt8, Int8, Face);
cItem Item;
ReadItem(a_ByteBuffer, Item, 3);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorX);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorY);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorZ);
- m_Client->HandleRightClick(BlockX, BlockY, BlockZ, static_cast<eBlockFace>(Face), CursorX, CursorY, CursorZ, m_Client->GetPlayer()->GetEquippedItem());
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorX);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorY);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorZ);
+ m_Client->HandleRightClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), CursorX, CursorY, CursorZ, m_Client->GetPlayer()->GetEquippedItem());
}
@@ -2162,10 +2165,10 @@ void cProtocol180::HandlePacketChatMessage(cByteBuffer & a_ByteBuffer)
void cProtocol180::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Locale);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ViewDistance);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ChatFlags);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ViewDistance);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ChatFlags);
HANDLE_READ(a_ByteBuffer, ReadBool, bool, ChatColors);
- HANDLE_READ(a_ByteBuffer, ReadChar, char, SkinFlags);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, SkinFlags);
m_Client->SetLocale(Locale);
m_Client->SetViewDistance(ViewDistance);
@@ -2178,7 +2181,7 @@ void cProtocol180::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer)
void cProtocol180::HandlePacketClientStatus(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadChar, char, ActionID);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ActionID);
switch (ActionID)
{
case 0:
@@ -2210,13 +2213,13 @@ void cProtocol180::HandlePacketClientStatus(cByteBuffer & a_ByteBuffer)
void cProtocol180::HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadBEShort, short, SlotNum);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum);
cItem Item;
if (!ReadItem(a_ByteBuffer, Item))
{
return;
}
- m_Client->HandleCreativeInventory(SlotNum, Item);
+ m_Client->HandleCreativeInventory(SlotNum, Item, (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftClickOutside : caLeftClick);
}
@@ -2225,9 +2228,9 @@ void cProtocol180::HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffe
void cProtocol180::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, PlayerID);
- HANDLE_READ(a_ByteBuffer, ReadChar, char, Action);
- HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, JumpBoost);
+ HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, PlayerID);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Action);
+ HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, JumpBoost);
switch (Action)
{
@@ -2246,7 +2249,7 @@ void cProtocol180::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
void cProtocol180::HandlePacketKeepAlive(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, KeepAliveID);
- m_Client->HandleKeepAlive((int)KeepAliveID);
+ m_Client->HandleKeepAlive(static_cast<int>(KeepAliveID));
}
@@ -2265,10 +2268,11 @@ void cProtocol180::HandlePacketPlayer(cByteBuffer & a_ByteBuffer)
void cProtocol180::HandlePacketPlayerAbilities(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Flags);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Flags);
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, FlyingSpeed);
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, WalkingSpeed);
+ // COnvert the bitfield into individual boolean flags:
bool IsFlying = false, CanFly = false;
if ((Flags & 2) != 0)
{
@@ -2359,7 +2363,7 @@ void cProtocol180::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
void cProtocol180::HandlePacketSlotSelect(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadBEShort, short, SlotNum);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum);
m_Client->HandleSlotSelected(SlotNum);
}
@@ -2371,7 +2375,7 @@ void cProtocol180::HandlePacketSteerVehicle(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Forward);
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Sideways);
- HANDLE_READ(a_ByteBuffer, ReadChar, char, Flags);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Flags);
if ((Flags & 0x2) != 0)
{
@@ -2390,7 +2394,7 @@ void cProtocol180::HandlePacketSteerVehicle(cByteBuffer & a_ByteBuffer)
void cProtocol180::HandlePacketTabComplete(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Text);
- HANDLE_READ(a_ByteBuffer, ReadBool, bool, HasPosition);
+ HANDLE_READ(a_ByteBuffer, ReadBool, bool, HasPosition);
if (HasPosition)
{
@@ -2435,12 +2439,12 @@ void cProtocol180::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)
{
case 0:
{
- m_Client->HandleUseEntity((int)EntityID, false);
+ m_Client->HandleUseEntity(EntityID, false);
break;
}
case 1:
{
- m_Client->HandleUseEntity((int)EntityID, true);
+ m_Client->HandleUseEntity(EntityID, true);
break;
}
case 2:
@@ -2466,8 +2470,8 @@ void cProtocol180::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)
void cProtocol180::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Enchantment);
m_Client->HandleEnchantItem(WindowID, Enchantment);
}
@@ -2478,11 +2482,11 @@ void cProtocol180::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer)
void cProtocol180::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadChar, char, WindowID);
- HANDLE_READ(a_ByteBuffer, ReadBEShort, short, SlotNum);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Button);
- HANDLE_READ(a_ByteBuffer, ReadBEShort, short, TransactionID);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Mode);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Button);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt16, UInt16, TransactionID);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Mode);
cItem Item;
ReadItem(a_ByteBuffer, Item);
@@ -2490,8 +2494,8 @@ void cProtocol180::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
eClickAction Action;
switch ((Mode << 8) | Button)
{
- case 0x0000: Action = (SlotNum != -999) ? caLeftClick : caLeftClickOutside; break;
- case 0x0001: Action = (SlotNum != -999) ? caRightClick : caRightClickOutside; break;
+ case 0x0000: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caLeftClick : caLeftClickOutside; break;
+ case 0x0001: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caRightClick : caRightClickOutside; break;
case 0x0100: Action = caShiftLeftClick; break;
case 0x0101: Action = caShiftRightClick; break;
case 0x0200: Action = caNumber1; break;
@@ -2504,14 +2508,14 @@ void cProtocol180::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
case 0x0207: Action = caNumber8; break;
case 0x0208: Action = caNumber9; break;
case 0x0300: Action = caMiddleClick; break;
- case 0x0400: Action = (SlotNum == -999) ? caLeftClickOutsideHoldNothing : caDropKey; break;
- case 0x0401: Action = (SlotNum == -999) ? caRightClickOutsideHoldNothing : caCtrlDropKey; break;
- case 0x0500: Action = (SlotNum == -999) ? caLeftPaintBegin : caUnknown; break;
- case 0x0501: Action = (SlotNum != -999) ? caLeftPaintProgress : caUnknown; break;
- case 0x0502: Action = (SlotNum == -999) ? caLeftPaintEnd : caUnknown; break;
- case 0x0504: Action = (SlotNum == -999) ? caRightPaintBegin : caUnknown; break;
- case 0x0505: Action = (SlotNum != -999) ? caRightPaintProgress : caUnknown; break;
- case 0x0506: Action = (SlotNum == -999) ? caRightPaintEnd : caUnknown; break;
+ case 0x0400: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftClickOutsideHoldNothing : caDropKey; break;
+ case 0x0401: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightClickOutsideHoldNothing : caCtrlDropKey; break;
+ case 0x0500: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftPaintBegin : caUnknown; break;
+ case 0x0501: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caLeftPaintProgress : caUnknown; break;
+ case 0x0502: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftPaintEnd : caUnknown; break;
+ case 0x0504: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintBegin : caUnknown; break;
+ case 0x0505: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caRightPaintProgress : caUnknown; break;
+ case 0x0506: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintEnd : caUnknown; break;
case 0x0600: Action = caDblClick; break;
default:
{
@@ -2530,7 +2534,7 @@ void cProtocol180::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
void cProtocol180::HandlePacketWindowClose(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadChar, char, WindowID);
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
m_Client->HandleWindowClose(WindowID);
}
@@ -2542,14 +2546,14 @@ void cProtocol180::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
{
if (a_Channel == "MC|AdvCdm")
{
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Mode)
+ HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Mode)
switch (Mode)
{
case 0x00:
{
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX);
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockY);
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockY);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ);
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Command);
m_Client->HandleCommandBlockBlockChange(BlockX, BlockY, BlockZ, Command);
break;
@@ -2557,7 +2561,7 @@ void cProtocol180::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
default:
{
- m_Client->SendChat(Printf("Failure setting command block command; unhandled mode %d", Mode), mtFailure);
+ m_Client->SendChat(Printf("Failure setting command block command; unhandled mode %u (0x%02x)", Mode, Mode), mtFailure);
LOG("Unhandled MC|AdvCdm packet mode.");
return;
}
@@ -2574,8 +2578,8 @@ void cProtocol180::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
}
else if (a_Channel == "MC|Beacon")
{
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, Effect1);
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, Effect2);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect1);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect2);
m_Client->HandleBeaconSelection(Effect1, Effect2);
return;
}
@@ -2587,7 +2591,7 @@ void cProtocol180::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
}
else if (a_Channel == "MC|TrSel")
{
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, SlotNum);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, SlotNum);
m_Client->HandleNPCTrade(SlotNum);
return;
}
@@ -2629,7 +2633,7 @@ void cProtocol180::SendData(const char * a_Data, size_t a_Size)
bool cProtocol180::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes)
{
- HANDLE_PACKET_READ(a_ByteBuffer, ReadBEShort, short, ItemType);
+ HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemType);
if (ItemType == -1)
{
// The item is empty, no more data follows
@@ -2638,8 +2642,8 @@ bool cProtocol180::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a
}
a_Item.m_ItemType = ItemType;
- HANDLE_PACKET_READ(a_ByteBuffer, ReadChar, char, ItemCount);
- HANDLE_PACKET_READ(a_ByteBuffer, ReadBEShort, short, ItemDamage);
+ HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt8, Int8, ItemCount);
+ HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemDamage);
a_Item.m_ItemCount = ItemCount;
a_Item.m_ItemDamage = ItemDamage;
if (ItemCount <= 0)
@@ -2755,6 +2759,26 @@ void cProtocol180::StartEncryption(const Byte * a_Key)
+eBlockFace cProtocol180::FaceIntToBlockFace(Int8 a_BlockFace)
+{
+ // Normalize the blockface values returned from the protocol
+ // Anything known gets mapped 1:1, everything else returns BLOCK_FACE_NONE
+ switch (a_BlockFace)
+ {
+ case BLOCK_FACE_XM: return BLOCK_FACE_XM;
+ case BLOCK_FACE_XP: return BLOCK_FACE_XP;
+ case BLOCK_FACE_YM: return BLOCK_FACE_YM;
+ case BLOCK_FACE_YP: return BLOCK_FACE_YP;
+ case BLOCK_FACE_ZM: return BLOCK_FACE_ZM;
+ case BLOCK_FACE_ZP: return BLOCK_FACE_ZP;
+ default: return BLOCK_FACE_NONE;
+ }
+}
+
+
+
+
+
////////////////////////////////////////////////////////////////////////////////
// cProtocol180::cPacketizer:
diff --git a/src/Protocol/Protocol18x.h b/src/Protocol/Protocol18x.h
index 92d9825ef..d7365c44f 100644
--- a/src/Protocol/Protocol18x.h
+++ b/src/Protocol/Protocol18x.h
@@ -169,24 +169,24 @@ protected:
m_Out.WriteBool(a_Value);
}
- void WriteByte(Byte a_Value)
+ void WriteByte(UInt8 a_Value)
{
- m_Out.WriteByte(a_Value);
+ m_Out.WriteBEUInt8(a_Value);
}
- void WriteChar(char a_Value)
+ void WriteChar(Int8 a_Value)
{
- m_Out.WriteChar(a_Value);
+ m_Out.WriteBEInt8(a_Value);
}
- void WriteShort(short a_Value)
+ void WriteShort(Int16 a_Value)
{
- m_Out.WriteBEShort(a_Value);
+ m_Out.WriteBEInt16(a_Value);
}
- void WriteInt(int a_Value)
+ void WriteInt(Int32 a_Value)
{
- m_Out.WriteBEInt(a_Value);
+ m_Out.WriteBEInt32(a_Value);
}
void WriteInt64(Int64 a_Value)
@@ -332,6 +332,9 @@ protected:
void StartEncryption(const Byte * a_Key);
+ /** Converts the BlockFace received by the protocol into eBlockFace constants.
+ If the received value doesn't match any of our eBlockFace constants, BLOCK_FACE_NONE is returned. */
+ eBlockFace FaceIntToBlockFace(Int8 a_FaceInt);
} ;
diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp
index af9e0d1bc..167a309a0 100644
--- a/src/Protocol/ProtocolRecognizer.cpp
+++ b/src/Protocol/ProtocolRecognizer.cpp
@@ -911,13 +911,13 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema
case PROTO_VERSION_1_7_2:
{
AString ServerAddress;
- short ServerPort;
+ UInt16 ServerPort;
UInt32 NextState;
if (!m_Buffer.ReadVarUTF8String(ServerAddress))
{
break;
}
- if (!m_Buffer.ReadBEShort(ServerPort))
+ if (!m_Buffer.ReadBEUInt16(ServerPort))
{
break;
}
@@ -926,19 +926,19 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema
break;
}
m_Buffer.CommitRead();
- m_Protocol = new cProtocol172(m_Client, ServerAddress, (UInt16)ServerPort, NextState);
+ m_Protocol = new cProtocol172(m_Client, ServerAddress, ServerPort, NextState);
return true;
}
case PROTO_VERSION_1_7_6:
{
AString ServerAddress;
- short ServerPort;
+ UInt16 ServerPort;
UInt32 NextState;
if (!m_Buffer.ReadVarUTF8String(ServerAddress))
{
break;
}
- if (!m_Buffer.ReadBEShort(ServerPort))
+ if (!m_Buffer.ReadBEUInt16(ServerPort))
{
break;
}
@@ -947,19 +947,19 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema
break;
}
m_Buffer.CommitRead();
- m_Protocol = new cProtocol176(m_Client, ServerAddress, (UInt16)ServerPort, NextState);
+ m_Protocol = new cProtocol176(m_Client, ServerAddress, ServerPort, NextState);
return true;
}
case PROTO_VERSION_1_8_0:
{
AString ServerAddress;
- short ServerPort;
+ UInt16 ServerPort;
UInt32 NextState;
if (!m_Buffer.ReadVarUTF8String(ServerAddress))
{
break;
}
- if (!m_Buffer.ReadBEShort(ServerPort))
+ if (!m_Buffer.ReadBEUInt16(ServerPort))
{
break;
}
@@ -968,12 +968,12 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema
break;
}
m_Buffer.CommitRead();
- m_Protocol = new cProtocol180(m_Client, ServerAddress, (UInt16)ServerPort, NextState);
+ m_Protocol = new cProtocol180(m_Client, ServerAddress, ServerPort, NextState);
return true;
}
}
- LOGINFO("Client \"%s\" uses an unsupported protocol (lengthed, version %u)",
- m_Client->GetIPString().c_str(), ProtocolVersion
+ LOGINFO("Client \"%s\" uses an unsupported protocol (lengthed, version %u (0x%x))",
+ m_Client->GetIPString().c_str(), ProtocolVersion, ProtocolVersion
);
m_Client->Kick("Unsupported protocol version");
return false;