Unified cByteBuffer types.
cByteBuffer now reads and writes any of the [U]Int<N> types.
This commit is contained in:
parent
abd3f06a76
commit
b1d4b3bb96
File diff suppressed because it is too large
Load Diff
@ -73,13 +73,15 @@
|
|||||||
|
|
||||||
|
|
||||||
// Integral types with predefined sizes:
|
// Integral types with predefined sizes:
|
||||||
typedef long long Int64;
|
typedef signed long long Int64;
|
||||||
typedef int Int32;
|
typedef signed int Int32;
|
||||||
typedef short Int16;
|
typedef signed short Int16;
|
||||||
|
typedef signed char Int8;
|
||||||
|
|
||||||
typedef unsigned long long UInt64;
|
typedef unsigned long long UInt64;
|
||||||
typedef unsigned int UInt32;
|
typedef unsigned int UInt32;
|
||||||
typedef unsigned short UInt16;
|
typedef unsigned short UInt16;
|
||||||
|
typedef unsigned char UInt8;
|
||||||
|
|
||||||
typedef unsigned char Byte;
|
typedef unsigned char Byte;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class cServer
|
|||||||
SOCKET m_ListenSocket;
|
SOCKET m_ListenSocket;
|
||||||
cRsaPrivateKey m_PrivateKey;
|
cRsaPrivateKey m_PrivateKey;
|
||||||
AString m_PublicKeyDER;
|
AString m_PublicKeyDER;
|
||||||
short m_ConnectPort;
|
UInt16 m_ConnectPort;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
cServer(void);
|
cServer(void);
|
||||||
@ -32,7 +32,7 @@ public:
|
|||||||
cRsaPrivateKey & GetPrivateKey(void) { return m_PrivateKey; }
|
cRsaPrivateKey & GetPrivateKey(void) { return m_PrivateKey; }
|
||||||
const AString & GetPublicKeyDER (void) { return m_PublicKeyDER; }
|
const AString & GetPublicKeyDER (void) { return m_PublicKeyDER; }
|
||||||
|
|
||||||
short GetConnectPort(void) const { return m_ConnectPort; }
|
UInt16 GetConnectPort(void) const { return m_ConnectPort; }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,8 +101,8 @@ public:
|
|||||||
assert_test(buf.Write("a", 1));
|
assert_test(buf.Write("a", 1));
|
||||||
assert_test(buf.CanReadBytes(1));
|
assert_test(buf.CanReadBytes(1));
|
||||||
assert_test(buf.GetReadableSpace() == 1);
|
assert_test(buf.GetReadableSpace() == 1);
|
||||||
unsigned char v = 0;
|
UInt8 v = 0;
|
||||||
assert_test(buf.ReadByte(v));
|
assert_test(buf.ReadBEUInt8(v));
|
||||||
assert_test(v == 'a');
|
assert_test(v == 'a');
|
||||||
assert_test(buf.GetReadableSpace() == 0);
|
assert_test(buf.GetReadableSpace() == 0);
|
||||||
buf.CommitRead();
|
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
|
CHECK_THREAD
|
||||||
CheckValid();
|
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
|
CHECK_THREAD
|
||||||
CheckValid();
|
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
|
CHECK_THREAD
|
||||||
CheckValid();
|
CheckValid();
|
||||||
NEEDBYTES(2);
|
NEEDBYTES(2);
|
||||||
Int16 val;
|
UInt16 val;
|
||||||
ReadBuf(&val, 2);
|
ReadBuf(&val, 2);
|
||||||
val = ntohs(val);
|
val = ntohs(val);
|
||||||
a_Value = *(reinterpret_cast<short *>(&val));
|
memcpy(&a_Value, &val, 2);
|
||||||
return true;
|
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
|
CHECK_THREAD
|
||||||
CheckValid();
|
CheckValid();
|
||||||
NEEDBYTES(4);
|
NEEDBYTES(4);
|
||||||
ReadBuf(&a_Value, 4);
|
UInt32 val;
|
||||||
a_Value = (int)ntohl((u_long)a_Value);
|
ReadBuf(&val, 4);
|
||||||
|
val = ntohl(val);
|
||||||
|
memcpy(&a_Value, &val, 4);
|
||||||
return true;
|
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)
|
bool cByteBuffer::ReadBEFloat(float & a_Value)
|
||||||
{
|
{
|
||||||
CHECK_THREAD
|
CHECK_THREAD
|
||||||
@ -448,7 +464,7 @@ bool cByteBuffer::ReadBool(bool & a_Value)
|
|||||||
CHECK_THREAD
|
CHECK_THREAD
|
||||||
CheckValid();
|
CheckValid();
|
||||||
NEEDBYTES(1);
|
NEEDBYTES(1);
|
||||||
char Value = 0;
|
UInt8 Value = 0;
|
||||||
ReadBuf(&Value, 1);
|
ReadBuf(&Value, 1);
|
||||||
a_Value = (Value != 0);
|
a_Value = (Value != 0);
|
||||||
return true;
|
return true;
|
||||||
@ -462,17 +478,12 @@ bool cByteBuffer::ReadBEUTF16String16(AString & a_Value)
|
|||||||
{
|
{
|
||||||
CHECK_THREAD
|
CHECK_THREAD
|
||||||
CheckValid();
|
CheckValid();
|
||||||
short Length;
|
UInt16 Length;
|
||||||
if (!ReadBEShort(Length))
|
if (!ReadBEUInt16(Length))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Length < 0)
|
return ReadUTF16String(a_Value, Length);
|
||||||
{
|
|
||||||
ASSERT(!"Negative string length? Are you sure?");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return ReadUTF16String(a_Value, (size_t)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
|
CHECK_THREAD
|
||||||
CheckValid();
|
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
|
CHECK_THREAD
|
||||||
CheckValid();
|
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
|
CHECK_THREAD
|
||||||
CheckValid();
|
CheckValid();
|
||||||
PUTBYTES(2);
|
PUTBYTES(2);
|
||||||
u_short Converted = htons((u_short)a_Value);
|
UInt16 val;
|
||||||
return WriteBuf(&Converted, 2);
|
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
|
CHECK_THREAD
|
||||||
CheckValid();
|
CheckValid();
|
||||||
PUTBYTES(2);
|
PUTBYTES(2);
|
||||||
u_short Converted = htons((u_short)a_Value);
|
a_Value = htons(a_Value);
|
||||||
return WriteBuf(&Converted, 2);
|
return WriteBuf(&a_Value, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cByteBuffer::WriteBEInt(int a_Value)
|
bool cByteBuffer::WriteBEInt32(Int32 a_Value)
|
||||||
|
{
|
||||||
|
CHECK_THREAD
|
||||||
|
CheckValid();
|
||||||
|
PUTBYTES(4);
|
||||||
|
UInt32 Converted = HostToNetwork4(&a_Value);
|
||||||
|
return WriteBuf(&Converted, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cByteBuffer::WriteBEUInt32(UInt32 a_Value)
|
||||||
{
|
{
|
||||||
CHECK_THREAD
|
CHECK_THREAD
|
||||||
CheckValid();
|
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)
|
bool cByteBuffer::WriteBEFloat(float a_Value)
|
||||||
{
|
{
|
||||||
CHECK_THREAD
|
CHECK_THREAD
|
||||||
@ -672,7 +711,8 @@ bool cByteBuffer::WriteBool(bool a_Value)
|
|||||||
{
|
{
|
||||||
CHECK_THREAD
|
CHECK_THREAD
|
||||||
CheckValid();
|
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
|
CHECK_THREAD
|
||||||
CheckValid();
|
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
|
CHECK_THREAD
|
||||||
|
CheckValid();
|
||||||
return WriteBEInt64(((Int64)a_BlockX & 0x3FFFFFF) << 38 | ((Int64)a_BlockY & 0xFFF) << 26 | ((Int64)a_BlockZ & 0x3FFFFFF));
|
return WriteBEInt64(((Int64)a_BlockX & 0x3FFFFFF) << 38 | ((Int64)a_BlockY & 0xFFF) << 26 | ((Int64)a_BlockZ & 0x3FFFFFF));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,13 +52,14 @@ public:
|
|||||||
bool CanWriteBytes(size_t a_Count) const;
|
bool CanWriteBytes(size_t a_Count) const;
|
||||||
|
|
||||||
// Read the specified datatype and advance the read pointer; return true if successfully read:
|
// Read the specified datatype and advance the read pointer; return true if successfully read:
|
||||||
bool ReadChar (char & a_Value);
|
bool ReadBEInt8 (Int8 & a_Value);
|
||||||
bool ReadByte (unsigned char & a_Value);
|
bool ReadBEInt16 (Int16 & a_Value);
|
||||||
bool ReadBEShort (short & a_Value);
|
bool ReadBEInt32 (Int32 & a_Value);
|
||||||
bool ReadBEUInt16 (UInt16 & a_Value);
|
|
||||||
bool ReadBEInt (int & a_Value);
|
|
||||||
bool ReadBEUInt32 (UInt32 & a_Value);
|
|
||||||
bool ReadBEInt64 (Int64 & a_Value);
|
bool ReadBEInt64 (Int64 & a_Value);
|
||||||
|
bool ReadBEUInt8 (UInt8 & a_Value);
|
||||||
|
bool ReadBEUInt16 (UInt16 & a_Value);
|
||||||
|
bool ReadBEUInt32 (UInt32 & a_Value);
|
||||||
|
bool ReadBEUInt64 (UInt64 & a_Value);
|
||||||
bool ReadBEFloat (float & a_Value);
|
bool ReadBEFloat (float & a_Value);
|
||||||
bool ReadBEDouble (double & a_Value);
|
bool ReadBEDouble (double & a_Value);
|
||||||
bool ReadBool (bool & a_Value);
|
bool ReadBool (bool & a_Value);
|
||||||
@ -81,19 +82,21 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write the specified datatype; return true if successfully written
|
// Write the specified datatype; return true if successfully written
|
||||||
bool WriteChar (char a_Value);
|
bool WriteBEInt8 (Int8 a_Value);
|
||||||
bool WriteByte (unsigned char a_Value);
|
bool WriteBEInt16 (Int16 a_Value);
|
||||||
bool WriteBEShort (short a_Value);
|
bool WriteBEInt32 (Int32 a_Value);
|
||||||
bool WriteBEUShort (unsigned short a_Value);
|
|
||||||
bool WriteBEInt (int a_Value);
|
|
||||||
bool WriteBEInt64 (Int64 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 WriteBEFloat (float a_Value);
|
||||||
bool WriteBEDouble (double a_Value);
|
bool WriteBEDouble (double a_Value);
|
||||||
bool WriteBool (bool a_Value);
|
bool WriteBool (bool a_Value);
|
||||||
bool WriteVarInt (UInt32 a_Value);
|
bool WriteVarInt (UInt32 a_Value);
|
||||||
bool WriteVarUTF8String (const AString & a_Value); // string length as VarInt, then string as UTF-8
|
bool WriteVarUTF8String (const AString & a_Value); // string length as VarInt, then string as UTF-8
|
||||||
bool WriteLEInt (int a_Value);
|
bool WriteLEInt32 (Int32 a_Value);
|
||||||
bool WritePosition (int a_BlockX, int a_BlockY, int a_BlockZ);
|
bool WritePosition (Int32 a_BlockX, Int32 a_BlockY, Int32 a_BlockZ);
|
||||||
|
|
||||||
/** Reads a_Count bytes into a_Buffer; returns true if successful */
|
/** Reads a_Count bytes into a_Buffer; returns true if successful */
|
||||||
bool ReadBuf(void * a_Buffer, size_t a_Count);
|
bool ReadBuf(void * a_Buffer, size_t a_Count);
|
||||||
|
@ -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
|
// This is for creative Inventory changes
|
||||||
if (!m_Player->IsGameModeCreative())
|
if (!m_Player->IsGameModeCreative())
|
||||||
@ -690,18 +690,18 @@ void cClientHandle::HandleCreativeInventory(short a_SlotNum, const cItem & a_Hel
|
|||||||
return;
|
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)
|
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!");
|
Kick("Invalid enchanting!");
|
||||||
return;
|
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
|
// TODO
|
||||||
LOGWARNING("%s: Not implemented yet", __FUNCTION__);
|
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->GetInventory().SetEquippedSlotNum(a_SlotNum);
|
||||||
m_Player->GetWorld()->BroadcastEntityEquipment(*m_Player, 0, m_Player->GetInventory().GetEquippedItem(), this);
|
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);
|
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",
|
LOGD("WindowClick: WinID %d, SlotNum %d, action: %s, Item %s x %d",
|
||||||
a_WindowID, a_SlotNum, ClickActionToString(a_ClickAction),
|
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
|
// 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())
|
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())
|
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())
|
if (a_EntityID != m_Player->GetUniqueID())
|
||||||
{
|
{
|
||||||
|
@ -276,16 +276,18 @@ public: // tolua_export
|
|||||||
|
|
||||||
/** Called when the protocol receives a MC|AdvCdm plugin message, indicating that the player set a new
|
/** 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?). */
|
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. */
|
/** 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 HandleEntityCrouch (UInt32 a_EntityID, bool a_IsCrouching);
|
||||||
void HandleEntityLeaveBed (int a_EntityID);
|
void HandleEntityLeaveBed (UInt32 a_EntityID);
|
||||||
void HandleEntitySprinting (int a_EntityID, bool a_IsSprinting);
|
void HandleEntitySprinting (UInt32 a_EntityID, bool a_IsSprinting);
|
||||||
|
|
||||||
/** Kicks the client if the same username is already logged in.
|
/** Kicks the client if the same username is already logged in.
|
||||||
Returns false if the client has been kicked, true otherwise. */
|
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 HandlePluginMessage (const AString & a_Channel, const AString & a_Message);
|
||||||
void HandleRespawn (void);
|
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 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 HandleSteerVehicle (float Forward, float Sideways);
|
||||||
void HandleTabCompletion (const AString & a_Text);
|
void HandleTabCompletion (const AString & a_Text);
|
||||||
void HandleUpdateSign (
|
void HandleUpdateSign (
|
||||||
@ -321,9 +323,9 @@ public: // tolua_export
|
|||||||
const AString & a_Line3, const AString & a_Line4
|
const AString & a_Line3, const AString & a_Line4
|
||||||
);
|
);
|
||||||
void HandleUnmount (void);
|
void HandleUnmount (void);
|
||||||
void HandleUseEntity (int a_TargetEntityID, bool a_IsLeftClick);
|
void HandleUseEntity (UInt32 a_TargetEntityID, bool a_IsLeftClick);
|
||||||
void HandleWindowClick (char a_WindowID, short a_SlotNum, eClickAction a_ClickAction, const cItem & a_HeldItem);
|
void HandleWindowClick (UInt8 a_WindowID, Int16 a_SlotNum, eClickAction a_ClickAction, const cItem & a_HeldItem);
|
||||||
void HandleWindowClose (char a_WindowID);
|
void HandleWindowClose (UInt8 a_WindowID);
|
||||||
|
|
||||||
/** Called when the protocol has finished logging the user in.
|
/** Called when the protocol has finished logging the user in.
|
||||||
Return true to allow the user in; false to kick them.
|
Return true to allow the user in; false to kick them.
|
||||||
|
@ -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)
|
inline float NetworkToHostFloat4(const void * a_Value)
|
||||||
{
|
{
|
||||||
UInt32 buf;
|
UInt32 buf;
|
||||||
|
@ -132,13 +132,15 @@
|
|||||||
|
|
||||||
|
|
||||||
// Integral types with predefined sizes:
|
// Integral types with predefined sizes:
|
||||||
typedef long long Int64;
|
typedef signed long long Int64;
|
||||||
typedef int Int32;
|
typedef signed int Int32;
|
||||||
typedef short Int16;
|
typedef signed short Int16;
|
||||||
|
typedef signed char Int8;
|
||||||
|
|
||||||
typedef unsigned long long UInt64;
|
typedef unsigned long long UInt64;
|
||||||
typedef unsigned int UInt32;
|
typedef unsigned int UInt32;
|
||||||
typedef unsigned short UInt16;
|
typedef unsigned short UInt16;
|
||||||
|
typedef unsigned char UInt8;
|
||||||
|
|
||||||
typedef unsigned char Byte;
|
typedef unsigned char Byte;
|
||||||
|
|
||||||
@ -156,10 +158,12 @@ class SizeChecker<T, Size, true>
|
|||||||
template class SizeChecker<Int64, 8>;
|
template class SizeChecker<Int64, 8>;
|
||||||
template class SizeChecker<Int32, 4>;
|
template class SizeChecker<Int32, 4>;
|
||||||
template class SizeChecker<Int16, 2>;
|
template class SizeChecker<Int16, 2>;
|
||||||
|
template class SizeChecker<Int8, 1>;
|
||||||
|
|
||||||
template class SizeChecker<UInt64, 8>;
|
template class SizeChecker<UInt64, 8>;
|
||||||
template class SizeChecker<UInt32, 4>;
|
template class SizeChecker<UInt32, 4>;
|
||||||
template class SizeChecker<UInt16, 2>;
|
template class SizeChecker<UInt16, 2>;
|
||||||
|
template class SizeChecker<UInt8, 1>;
|
||||||
|
|
||||||
// A macro to disallow the copy constructor and operator = functions
|
// 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
|
// This should be used in the private: declarations for any class that shouldn't allow copying itself
|
||||||
|
@ -188,10 +188,10 @@ void cChunkDataSerializer::Serialize47(AString & a_Data, int a_ChunkX, int a_Chu
|
|||||||
// Create the packet:
|
// Create the packet:
|
||||||
cByteBuffer Packet(512 KiB);
|
cByteBuffer Packet(512 KiB);
|
||||||
Packet.WriteVarInt(0x21); // Packet id (Chunk Data packet)
|
Packet.WriteVarInt(0x21); // Packet id (Chunk Data packet)
|
||||||
Packet.WriteBEInt(a_ChunkX);
|
Packet.WriteBEInt32(a_ChunkX);
|
||||||
Packet.WriteBEInt(a_ChunkZ);
|
Packet.WriteBEInt32(a_ChunkZ);
|
||||||
Packet.WriteBool(true); // "Ground-up continuous", or rather, "biome data present" flag
|
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.WriteBEUInt16(0xffff); // We're aways sending the full chunk with no additional data, so the bitmap is 0xffff
|
||||||
|
|
||||||
// Write the chunk size:
|
// Write the chunk size:
|
||||||
const int BiomeDataSize = cChunkDef::Width * cChunkDef::Width;
|
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;
|
BLOCKTYPE BlockType = m_BlockTypes[Index] & 0xFF;
|
||||||
NIBBLETYPE BlockMeta = m_BlockMetas[Index / 2] >> ((Index & 1) * 4) & 0x0f;
|
NIBBLETYPE BlockMeta = m_BlockMetas[Index / 2] >> ((Index & 1) * 4) & 0x0f;
|
||||||
Packet.WriteByte((unsigned char)(BlockType << 4) | BlockMeta);
|
Packet.WriteBEUInt8(static_cast<unsigned char>(BlockType << 4) | BlockMeta);
|
||||||
Packet.WriteByte((unsigned char)(BlockType >> 4));
|
Packet.WriteBEUInt8(static_cast<unsigned char>(BlockType >> 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the rest:
|
// Write the rest:
|
||||||
|
@ -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) \
|
#define HANDLE_READ(ByteBuf, Proc, Type, Var) \
|
||||||
Type Var; \
|
Type Var; \
|
||||||
if (!ByteBuf.Proc(Var))\
|
if (!ByteBuf.Proc(Var))\
|
||||||
@ -1006,8 +1013,8 @@ void cProtocol172::SendExperience (void)
|
|||||||
cPacketizer Pkt(*this, 0x1f); // Experience Packet
|
cPacketizer Pkt(*this, 0x1f); // Experience Packet
|
||||||
cPlayer * Player = m_Client->GetPlayer();
|
cPlayer * Player = m_Client->GetPlayer();
|
||||||
Pkt.WriteFloat(Player->GetXpPercentage());
|
Pkt.WriteFloat(Player->GetXpPercentage());
|
||||||
Pkt.WriteShort(Player->GetXpLevel());
|
Pkt.WriteShort(static_cast<UInt16>(std::max<int>(Player->GetXpLevel(), std::numeric_limits<UInt16>::max())));
|
||||||
Pkt.WriteShort(Player->GetCurrentXp());
|
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);
|
Pkt.WriteInt(a_VehicleSubType);
|
||||||
if (a_VehicleSubType != 0)
|
if (a_VehicleSubType != 0)
|
||||||
{
|
{
|
||||||
Pkt.WriteShort(static_cast<short>(a_Vehicle.GetSpeedX() * 400));
|
Pkt.WriteShort(static_cast<Int16>(a_Vehicle.GetSpeedX() * 400));
|
||||||
Pkt.WriteShort(static_cast<short>(a_Vehicle.GetSpeedY() * 400));
|
Pkt.WriteShort(static_cast<Int16>(a_Vehicle.GetSpeedY() * 400));
|
||||||
Pkt.WriteShort(static_cast<short>(a_Vehicle.GetSpeedZ() * 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)
|
void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
short EncKeyLength, EncNonceLength;
|
UInt16 EncKeyLength, EncNonceLength;
|
||||||
if (!a_ByteBuffer.ReadBEShort(EncKeyLength))
|
if (!a_ByteBuffer.ReadBEUInt16(EncKeyLength))
|
||||||
{
|
{
|
||||||
return;
|
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");
|
m_Client->Kick("Invalid EncKeyLength");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AString EncKey;
|
AString EncKey;
|
||||||
if (!a_ByteBuffer.ReadString(EncKey, static_cast<size_t>(EncKeyLength)))
|
if (!a_ByteBuffer.ReadString(EncKey, EncKeyLength))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!a_ByteBuffer.ReadBEShort(EncNonceLength))
|
if (!a_ByteBuffer.ReadBEUInt16(EncNonceLength))
|
||||||
{
|
{
|
||||||
return;
|
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");
|
m_Client->Kick("Invalid EncNonceLength");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AString EncNonce;
|
AString EncNonce;
|
||||||
if (!a_ByteBuffer.ReadString(EncNonce, static_cast<size_t>(EncNonceLength)))
|
if (!a_ByteBuffer.ReadString(EncNonce, EncNonceLength))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1791,7 +1798,10 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe
|
|||||||
// Decrypt EncNonce using privkey
|
// Decrypt EncNonce using privkey
|
||||||
cRsaPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey();
|
cRsaPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey();
|
||||||
Int32 DecryptedNonce[MAX_ENC_LEN / sizeof(Int32)];
|
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)
|
if (res != 4)
|
||||||
{
|
{
|
||||||
LOGD("Bad nonce length: got %d, exp %d", 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)
|
void cProtocol172::HandlePacketAnimation(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, EntityID);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt32, UInt32, EntityID);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Animation);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Animation);
|
||||||
m_Client->HandleAnimation(Animation);
|
m_Client->HandleAnimation(Animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1873,12 +1883,12 @@ void cProtocol172::HandlePacketAnimation(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol172::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer)
|
void cProtocol172::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadChar, char, Status);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Status);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, BlockY);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, BlockY);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadChar, char, Face);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt8, Int8, Face);
|
||||||
m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, static_cast<eBlockFace>(Face), Status);
|
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)
|
void cProtocol172::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, BlockY);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, BlockY);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadChar, char, Face);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Face);
|
||||||
cItem Item;
|
cItem Item;
|
||||||
ReadItem(a_ByteBuffer, Item);
|
ReadItem(a_ByteBuffer, Item);
|
||||||
|
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorX);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorX);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorY);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorY);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorZ);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorZ);
|
||||||
m_Client->HandleRightClick(BlockX, BlockY, BlockZ, static_cast<eBlockFace>(Face), CursorX, CursorY, CursorZ, m_Client->GetPlayer()->GetEquippedItem());
|
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)
|
void cProtocol172::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Locale);
|
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Locale);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ViewDistance);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ViewDistance);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ChatFlags);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ChatFlags);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ChatColors);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ChatColors);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Difficulty);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Difficulty);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ShowCape);
|
HANDLE_READ(a_ByteBuffer, ReadBool, bool, ShowCape);
|
||||||
|
|
||||||
m_Client->SetLocale(Locale);
|
m_Client->SetLocale(Locale);
|
||||||
m_Client->SetViewDistance(ViewDistance);
|
m_Client->SetViewDistance(ViewDistance);
|
||||||
@ -1934,7 +1944,7 @@ void cProtocol172::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol172::HandlePacketClientStatus(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)
|
switch (ActionID)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@ -1966,13 +1976,13 @@ void cProtocol172::HandlePacketClientStatus(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol172::HandlePacketCreativeInventoryAction(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;
|
cItem Item;
|
||||||
if (!ReadItem(a_ByteBuffer, Item))
|
if (!ReadItem(a_ByteBuffer, Item))
|
||||||
{
|
{
|
||||||
return;
|
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)
|
void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, PlayerID);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt32, UInt32, PlayerID);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Action);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Action);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, JumpBoost);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, JumpBoost);
|
||||||
|
|
||||||
switch (Action)
|
switch (Action)
|
||||||
{
|
{
|
||||||
@ -2001,7 +2011,7 @@ void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol172::HandlePacketKeepAlive(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);
|
m_Client->HandleKeepAlive(KeepAliveID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2021,10 +2031,11 @@ void cProtocol172::HandlePacketPlayer(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol172::HandlePacketPlayerAbilities(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, FlyingSpeed);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, WalkingSpeed);
|
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, WalkingSpeed);
|
||||||
|
|
||||||
|
// Convert flags bitfield into individual bool flags:
|
||||||
bool IsFlying = false, CanFly = false;
|
bool IsFlying = false, CanFly = false;
|
||||||
if ((Flags & 2) != 0)
|
if ((Flags & 2) != 0)
|
||||||
{
|
{
|
||||||
@ -2087,11 +2098,11 @@ void cProtocol172::HandlePacketPlayerPosLook(cByteBuffer & a_ByteBuffer)
|
|||||||
void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
|
void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel);
|
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEShort, short, Length);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt16, UInt16, Length);
|
||||||
if (Length + 1 != (int)a_ByteBuffer.GetReadableSpace())
|
if (Length != a_ByteBuffer.GetReadableSpace() - 1)
|
||||||
{
|
{
|
||||||
LOGD("Invalid plugin message packet, payload length doesn't match packet length (exp %d, got %d)",
|
LOGD("Invalid plugin message packet, payload length doesn't match packet length (exp %u, got %u)",
|
||||||
static_cast<int>(a_ByteBuffer.GetReadableSpace()) - 1, Length
|
a_ByteBuffer.GetReadableSpace() - 1, Length
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2105,7 +2116,7 @@ void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
// Read the plugin message and relay to clienthandle:
|
// Read the plugin message and relay to clienthandle:
|
||||||
AString Data;
|
AString Data;
|
||||||
if (!a_ByteBuffer.ReadString(Data, static_cast<size_t>(Length)))
|
if (!a_ByteBuffer.ReadString(Data, Length))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2118,7 +2129,7 @@ void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol172::HandlePacketSlotSelect(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);
|
m_Client->HandleSlotSelected(SlotNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2158,9 +2169,9 @@ void cProtocol172::HandlePacketTabComplete(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol172::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer)
|
void cProtocol172::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEShort, short, BlockY);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, BlockY);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line1);
|
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line1);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line2);
|
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line2);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line3);
|
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line3);
|
||||||
@ -2174,8 +2185,8 @@ void cProtocol172::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)
|
void cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, EntityID);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt32, UInt32, EntityID);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, MouseButton);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, MouseButton);
|
||||||
m_Client->HandleUseEntity(EntityID, (MouseButton == 1));
|
m_Client->HandleUseEntity(EntityID, (MouseButton == 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2185,8 +2196,8 @@ void cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer)
|
void cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Enchantment);
|
||||||
|
|
||||||
m_Client->HandleEnchantItem(WindowID, Enchantment);
|
m_Client->HandleEnchantItem(WindowID, Enchantment);
|
||||||
}
|
}
|
||||||
@ -2197,11 +2208,11 @@ void cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
|
void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadChar, char, WindowID);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEShort, short, SlotNum);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Button);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Button);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEShort, short, TransactionID);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt16, UInt16, TransactionID);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Mode);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Mode);
|
||||||
cItem Item;
|
cItem Item;
|
||||||
ReadItem(a_ByteBuffer, Item);
|
ReadItem(a_ByteBuffer, Item);
|
||||||
|
|
||||||
@ -2209,8 +2220,8 @@ void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
|
|||||||
eClickAction Action;
|
eClickAction Action;
|
||||||
switch ((Mode << 8) | Button)
|
switch ((Mode << 8) | Button)
|
||||||
{
|
{
|
||||||
case 0x0000: Action = (SlotNum != -999) ? caLeftClick : caLeftClickOutside; break;
|
case 0x0000: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caLeftClick : caLeftClickOutside; break;
|
||||||
case 0x0001: Action = (SlotNum != -999) ? caRightClick : caRightClickOutside; break;
|
case 0x0001: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caRightClick : caRightClickOutside; break;
|
||||||
case 0x0100: Action = caShiftLeftClick; break;
|
case 0x0100: Action = caShiftLeftClick; break;
|
||||||
case 0x0101: Action = caShiftRightClick; break;
|
case 0x0101: Action = caShiftRightClick; break;
|
||||||
case 0x0200: Action = caNumber1; break;
|
case 0x0200: Action = caNumber1; break;
|
||||||
@ -2223,14 +2234,14 @@ void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
|
|||||||
case 0x0207: Action = caNumber8; break;
|
case 0x0207: Action = caNumber8; break;
|
||||||
case 0x0208: Action = caNumber9; break;
|
case 0x0208: Action = caNumber9; break;
|
||||||
case 0x0300: Action = caMiddleClick; break;
|
case 0x0300: Action = caMiddleClick; break;
|
||||||
case 0x0400: Action = (SlotNum == -999) ? caLeftClickOutsideHoldNothing : caDropKey; break;
|
case 0x0400: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftClickOutsideHoldNothing : caDropKey; break;
|
||||||
case 0x0401: Action = (SlotNum == -999) ? caRightClickOutsideHoldNothing : caCtrlDropKey; break;
|
case 0x0401: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightClickOutsideHoldNothing : caCtrlDropKey; break;
|
||||||
case 0x0500: Action = (SlotNum == -999) ? caLeftPaintBegin : caUnknown; break;
|
case 0x0500: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftPaintBegin : caUnknown; break;
|
||||||
case 0x0501: Action = (SlotNum != -999) ? caLeftPaintProgress : caUnknown; break;
|
case 0x0501: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caLeftPaintProgress : caUnknown; break;
|
||||||
case 0x0502: Action = (SlotNum == -999) ? caLeftPaintEnd : caUnknown; break;
|
case 0x0502: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftPaintEnd : caUnknown; break;
|
||||||
case 0x0504: Action = (SlotNum == -999) ? caRightPaintBegin : caUnknown; break;
|
case 0x0504: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintBegin : caUnknown; break;
|
||||||
case 0x0505: Action = (SlotNum != -999) ? caRightPaintProgress : caUnknown; break;
|
case 0x0505: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caRightPaintProgress : caUnknown; break;
|
||||||
case 0x0506: Action = (SlotNum == -999) ? caRightPaintEnd : caUnknown; break;
|
case 0x0506: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintEnd : caUnknown; break;
|
||||||
case 0x0600: Action = caDblClick; break;
|
case 0x0600: Action = caDblClick; break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
@ -2249,7 +2260,7 @@ void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol172::HandlePacketWindowClose(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);
|
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")
|
if (a_Channel == "MC|AdvCdm")
|
||||||
{
|
{
|
||||||
size_t BeginningSpace = a_ByteBuffer.GetReadableSpace();
|
size_t BeginningSpace = a_ByteBuffer.GetReadableSpace();
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Mode);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Mode);
|
||||||
switch (Mode)
|
switch (Mode)
|
||||||
{
|
{
|
||||||
case 0x00:
|
case 0x00:
|
||||||
{
|
{
|
||||||
// Block-based commandblock update:
|
// Block-based commandblock update:
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockY);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockY);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Command);
|
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Command);
|
||||||
m_Client->HandleCommandBlockBlockChange(BlockX, BlockY, BlockZ, Command);
|
m_Client->HandleCommandBlockBlockChange(BlockX, BlockY, BlockZ, Command);
|
||||||
break;
|
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):
|
// 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();
|
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",
|
LOGD("Protocol 1.7: Skipping garbage data at the end of a vanilla MC|AdvCdm packet, %u bytes",
|
||||||
static_cast<unsigned>(a_PayloadLength - BytesRead)
|
static_cast<unsigned>(a_PayloadLength - BytesRead)
|
||||||
);
|
);
|
||||||
a_ByteBuffer.SkipRead(static_cast<size_t>(a_PayloadLength) - BytesRead);
|
a_ByteBuffer.SkipRead(a_PayloadLength - BytesRead);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2301,7 +2312,7 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
|
|||||||
{
|
{
|
||||||
// Read the client's brand:
|
// Read the client's brand:
|
||||||
AString 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);
|
m_Client->SetClientBrand(Brand);
|
||||||
}
|
}
|
||||||
@ -2312,15 +2323,15 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
|
|||||||
}
|
}
|
||||||
else if (a_Channel == "MC|Beacon")
|
else if (a_Channel == "MC|Beacon")
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, Effect1);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect1);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, Effect2);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect2);
|
||||||
m_Client->HandleBeaconSelection(Effect1, Effect2);
|
m_Client->HandleBeaconSelection(Effect1, Effect2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (a_Channel == "MC|ItemName")
|
else if (a_Channel == "MC|ItemName")
|
||||||
{
|
{
|
||||||
AString 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);
|
m_Client->HandleAnvilItemName(ItemName);
|
||||||
}
|
}
|
||||||
@ -2328,7 +2339,7 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
|
|||||||
}
|
}
|
||||||
else if (a_Channel == "MC|TrSel")
|
else if (a_Channel == "MC|TrSel")
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, SlotNum);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, SlotNum);
|
||||||
m_Client->HandleNPCTrade(SlotNum);
|
m_Client->HandleNPCTrade(SlotNum);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2336,7 +2347,7 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
|
|||||||
|
|
||||||
// Read the payload and send it through to the clienthandle:
|
// Read the payload and send it through to the clienthandle:
|
||||||
AString Message;
|
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);
|
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)
|
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)
|
if (ItemType == -1)
|
||||||
{
|
{
|
||||||
// The item is empty, no more data follows
|
// 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;
|
a_Item.m_ItemType = ItemType;
|
||||||
|
|
||||||
HANDLE_PACKET_READ(a_ByteBuffer, ReadChar, char, ItemCount);
|
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt8, Int8, ItemCount);
|
||||||
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEShort, short, ItemDamage);
|
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemDamage);
|
||||||
a_Item.m_ItemCount = ItemCount;
|
a_Item.m_ItemCount = ItemCount;
|
||||||
a_Item.m_ItemDamage = ItemDamage;
|
a_Item.m_ItemDamage = ItemDamage;
|
||||||
if (ItemCount <= 0)
|
if (ItemCount <= 0)
|
||||||
@ -2388,15 +2399,10 @@ bool cProtocol172::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item)
|
|||||||
a_Item.Empty();
|
a_Item.Empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEShort, short, MetadataLength);
|
|
||||||
if (MetadataLength <= 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the metadata
|
// Read the metadata
|
||||||
|
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt16, UInt16, MetadataLength);
|
||||||
AString Metadata;
|
AString Metadata;
|
||||||
if (!a_ByteBuffer.ReadString(Metadata, static_cast<size_t>(MetadataLength)))
|
if (!a_ByteBuffer.ReadString(Metadata, MetadataLength))
|
||||||
{
|
{
|
||||||
return false;
|
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:
|
// cProtocol172::cPacketizer:
|
||||||
|
|
||||||
@ -2520,7 +2546,7 @@ cProtocol172::cPacketizer::~cPacketizer()
|
|||||||
AString DataToSend;
|
AString DataToSend;
|
||||||
|
|
||||||
// Send the packet length
|
// 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.WriteVarInt(PacketLen);
|
||||||
m_Protocol.m_OutPacketLenBuffer.ReadAll(DataToSend);
|
m_Protocol.m_OutPacketLenBuffer.ReadAll(DataToSend);
|
||||||
|
@ -161,22 +161,22 @@ protected:
|
|||||||
|
|
||||||
void WriteByte(Byte a_Value)
|
void WriteByte(Byte a_Value)
|
||||||
{
|
{
|
||||||
m_Out.WriteByte(a_Value);
|
m_Out.WriteBEUInt8(a_Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteChar(char a_Value)
|
void WriteChar(char a_Value)
|
||||||
{
|
{
|
||||||
m_Out.WriteChar(a_Value);
|
m_Out.WriteBEInt8(a_Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteShort(short 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)
|
void WriteInt64(Int64 a_Value)
|
||||||
@ -297,7 +297,7 @@ protected:
|
|||||||
|
|
||||||
/** Parses Vanilla plugin messages into specific ClientHandle calls.
|
/** Parses Vanilla plugin messages into specific ClientHandle calls.
|
||||||
The message payload is still in the bytebuffer, to be read by this function. */
|
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. */
|
/** Sends the data to the client, encrypting them if needed. */
|
||||||
virtual void SendData(const char * a_Data, size_t a_Size) override;
|
virtual void SendData(const char * a_Data, size_t a_Size) override;
|
||||||
@ -312,6 +312,9 @@ protected:
|
|||||||
|
|
||||||
void StartEncryption(const Byte * a_Key);
|
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);
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -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) \
|
#define HANDLE_READ(ByteBuf, Proc, Type, Var) \
|
||||||
Type Var; \
|
Type Var; \
|
||||||
if (!ByteBuf.Proc(Var))\
|
if (!ByteBuf.Proc(Var))\
|
||||||
@ -2106,7 +2113,7 @@ void cProtocol180::HandlePacketAnimation(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol180::HandlePacketBlockDig(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;
|
int BlockX, BlockY, BlockZ;
|
||||||
if (!a_ByteBuffer.ReadPosition(BlockX, BlockY, BlockZ))
|
if (!a_ByteBuffer.ReadPosition(BlockX, BlockY, BlockZ))
|
||||||
@ -2114,8 +2121,8 @@ void cProtocol180::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Face);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt8, Int8, Face);
|
||||||
m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, static_cast<eBlockFace>(Face), Status);
|
m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2130,19 +2137,15 @@ void cProtocol180::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Face);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt8, Int8, Face);
|
||||||
if (Face == 255)
|
|
||||||
{
|
|
||||||
Face = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
cItem Item;
|
cItem Item;
|
||||||
ReadItem(a_ByteBuffer, Item, 3);
|
ReadItem(a_ByteBuffer, Item, 3);
|
||||||
|
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorX);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorX);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorY);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorY);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorZ);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorZ);
|
||||||
m_Client->HandleRightClick(BlockX, BlockY, BlockZ, static_cast<eBlockFace>(Face), CursorX, CursorY, CursorZ, m_Client->GetPlayer()->GetEquippedItem());
|
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)
|
void cProtocol180::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Locale);
|
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Locale);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ViewDistance);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ViewDistance);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ChatFlags);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ChatFlags);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBool, bool, ChatColors);
|
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->SetLocale(Locale);
|
||||||
m_Client->SetViewDistance(ViewDistance);
|
m_Client->SetViewDistance(ViewDistance);
|
||||||
@ -2178,7 +2181,7 @@ void cProtocol180::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol180::HandlePacketClientStatus(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)
|
switch (ActionID)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@ -2210,13 +2213,13 @@ void cProtocol180::HandlePacketClientStatus(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol180::HandlePacketCreativeInventoryAction(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;
|
cItem Item;
|
||||||
if (!ReadItem(a_ByteBuffer, Item))
|
if (!ReadItem(a_ByteBuffer, Item))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_Client->HandleCreativeInventory(SlotNum, Item);
|
m_Client->HandleCreativeInventory(SlotNum, Item, (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftClickOutside : caLeftClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2226,7 +2229,7 @@ void cProtocol180::HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffe
|
|||||||
void cProtocol180::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
|
void cProtocol180::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, PlayerID);
|
HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, PlayerID);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadChar, char, Action);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Action);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, JumpBoost);
|
HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, JumpBoost);
|
||||||
|
|
||||||
switch (Action)
|
switch (Action)
|
||||||
@ -2246,7 +2249,7 @@ void cProtocol180::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
|
|||||||
void cProtocol180::HandlePacketKeepAlive(cByteBuffer & a_ByteBuffer)
|
void cProtocol180::HandlePacketKeepAlive(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, KeepAliveID);
|
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)
|
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, FlyingSpeed);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, WalkingSpeed);
|
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, WalkingSpeed);
|
||||||
|
|
||||||
|
// COnvert the bitfield into individual boolean flags:
|
||||||
bool IsFlying = false, CanFly = false;
|
bool IsFlying = false, CanFly = false;
|
||||||
if ((Flags & 2) != 0)
|
if ((Flags & 2) != 0)
|
||||||
{
|
{
|
||||||
@ -2359,7 +2363,7 @@ void cProtocol180::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol180::HandlePacketSlotSelect(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);
|
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, Forward);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Sideways);
|
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)
|
if ((Flags & 0x2) != 0)
|
||||||
{
|
{
|
||||||
@ -2435,12 +2439,12 @@ void cProtocol180::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)
|
|||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
m_Client->HandleUseEntity((int)EntityID, false);
|
m_Client->HandleUseEntity(EntityID, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
m_Client->HandleUseEntity((int)EntityID, true);
|
m_Client->HandleUseEntity(EntityID, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
@ -2466,8 +2470,8 @@ void cProtocol180::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol180::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer)
|
void cProtocol180::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Enchantment);
|
||||||
|
|
||||||
m_Client->HandleEnchantItem(WindowID, Enchantment);
|
m_Client->HandleEnchantItem(WindowID, Enchantment);
|
||||||
}
|
}
|
||||||
@ -2478,11 +2482,11 @@ void cProtocol180::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol180::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
|
void cProtocol180::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadChar, char, WindowID);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEShort, short, SlotNum);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Button);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Button);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEShort, short, TransactionID);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt16, UInt16, TransactionID);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Mode);
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Mode);
|
||||||
cItem Item;
|
cItem Item;
|
||||||
ReadItem(a_ByteBuffer, Item);
|
ReadItem(a_ByteBuffer, Item);
|
||||||
|
|
||||||
@ -2490,8 +2494,8 @@ void cProtocol180::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
|
|||||||
eClickAction Action;
|
eClickAction Action;
|
||||||
switch ((Mode << 8) | Button)
|
switch ((Mode << 8) | Button)
|
||||||
{
|
{
|
||||||
case 0x0000: Action = (SlotNum != -999) ? caLeftClick : caLeftClickOutside; break;
|
case 0x0000: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caLeftClick : caLeftClickOutside; break;
|
||||||
case 0x0001: Action = (SlotNum != -999) ? caRightClick : caRightClickOutside; break;
|
case 0x0001: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caRightClick : caRightClickOutside; break;
|
||||||
case 0x0100: Action = caShiftLeftClick; break;
|
case 0x0100: Action = caShiftLeftClick; break;
|
||||||
case 0x0101: Action = caShiftRightClick; break;
|
case 0x0101: Action = caShiftRightClick; break;
|
||||||
case 0x0200: Action = caNumber1; break;
|
case 0x0200: Action = caNumber1; break;
|
||||||
@ -2504,14 +2508,14 @@ void cProtocol180::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
|
|||||||
case 0x0207: Action = caNumber8; break;
|
case 0x0207: Action = caNumber8; break;
|
||||||
case 0x0208: Action = caNumber9; break;
|
case 0x0208: Action = caNumber9; break;
|
||||||
case 0x0300: Action = caMiddleClick; break;
|
case 0x0300: Action = caMiddleClick; break;
|
||||||
case 0x0400: Action = (SlotNum == -999) ? caLeftClickOutsideHoldNothing : caDropKey; break;
|
case 0x0400: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftClickOutsideHoldNothing : caDropKey; break;
|
||||||
case 0x0401: Action = (SlotNum == -999) ? caRightClickOutsideHoldNothing : caCtrlDropKey; break;
|
case 0x0401: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightClickOutsideHoldNothing : caCtrlDropKey; break;
|
||||||
case 0x0500: Action = (SlotNum == -999) ? caLeftPaintBegin : caUnknown; break;
|
case 0x0500: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftPaintBegin : caUnknown; break;
|
||||||
case 0x0501: Action = (SlotNum != -999) ? caLeftPaintProgress : caUnknown; break;
|
case 0x0501: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caLeftPaintProgress : caUnknown; break;
|
||||||
case 0x0502: Action = (SlotNum == -999) ? caLeftPaintEnd : caUnknown; break;
|
case 0x0502: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftPaintEnd : caUnknown; break;
|
||||||
case 0x0504: Action = (SlotNum == -999) ? caRightPaintBegin : caUnknown; break;
|
case 0x0504: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintBegin : caUnknown; break;
|
||||||
case 0x0505: Action = (SlotNum != -999) ? caRightPaintProgress : caUnknown; break;
|
case 0x0505: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caRightPaintProgress : caUnknown; break;
|
||||||
case 0x0506: Action = (SlotNum == -999) ? caRightPaintEnd : caUnknown; break;
|
case 0x0506: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintEnd : caUnknown; break;
|
||||||
case 0x0600: Action = caDblClick; break;
|
case 0x0600: Action = caDblClick; break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
@ -2530,7 +2534,7 @@ void cProtocol180::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
|
|||||||
|
|
||||||
void cProtocol180::HandlePacketWindowClose(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);
|
m_Client->HandleWindowClose(WindowID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2542,14 +2546,14 @@ void cProtocol180::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
|
|||||||
{
|
{
|
||||||
if (a_Channel == "MC|AdvCdm")
|
if (a_Channel == "MC|AdvCdm")
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Mode)
|
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Mode)
|
||||||
switch (Mode)
|
switch (Mode)
|
||||||
{
|
{
|
||||||
case 0x00:
|
case 0x00:
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockY);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockY);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Command);
|
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Command);
|
||||||
m_Client->HandleCommandBlockBlockChange(BlockX, BlockY, BlockZ, Command);
|
m_Client->HandleCommandBlockBlockChange(BlockX, BlockY, BlockZ, Command);
|
||||||
break;
|
break;
|
||||||
@ -2557,7 +2561,7 @@ void cProtocol180::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
|
|||||||
|
|
||||||
default:
|
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.");
|
LOG("Unhandled MC|AdvCdm packet mode.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2574,8 +2578,8 @@ void cProtocol180::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
|
|||||||
}
|
}
|
||||||
else if (a_Channel == "MC|Beacon")
|
else if (a_Channel == "MC|Beacon")
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, Effect1);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect1);
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, Effect2);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect2);
|
||||||
m_Client->HandleBeaconSelection(Effect1, Effect2);
|
m_Client->HandleBeaconSelection(Effect1, Effect2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2587,7 +2591,7 @@ void cProtocol180::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
|
|||||||
}
|
}
|
||||||
else if (a_Channel == "MC|TrSel")
|
else if (a_Channel == "MC|TrSel")
|
||||||
{
|
{
|
||||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, SlotNum);
|
HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, SlotNum);
|
||||||
m_Client->HandleNPCTrade(SlotNum);
|
m_Client->HandleNPCTrade(SlotNum);
|
||||||
return;
|
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)
|
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)
|
if (ItemType == -1)
|
||||||
{
|
{
|
||||||
// The item is empty, no more data follows
|
// 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;
|
a_Item.m_ItemType = ItemType;
|
||||||
|
|
||||||
HANDLE_PACKET_READ(a_ByteBuffer, ReadChar, char, ItemCount);
|
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt8, Int8, ItemCount);
|
||||||
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEShort, short, ItemDamage);
|
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemDamage);
|
||||||
a_Item.m_ItemCount = ItemCount;
|
a_Item.m_ItemCount = ItemCount;
|
||||||
a_Item.m_ItemDamage = ItemDamage;
|
a_Item.m_ItemDamage = ItemDamage;
|
||||||
if (ItemCount <= 0)
|
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:
|
// cProtocol180::cPacketizer:
|
||||||
|
|
||||||
|
@ -169,24 +169,24 @@ protected:
|
|||||||
m_Out.WriteBool(a_Value);
|
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)
|
void WriteInt64(Int64 a_Value)
|
||||||
@ -332,6 +332,9 @@ protected:
|
|||||||
|
|
||||||
void StartEncryption(const Byte * a_Key);
|
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);
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -911,13 +911,13 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema
|
|||||||
case PROTO_VERSION_1_7_2:
|
case PROTO_VERSION_1_7_2:
|
||||||
{
|
{
|
||||||
AString ServerAddress;
|
AString ServerAddress;
|
||||||
short ServerPort;
|
UInt16 ServerPort;
|
||||||
UInt32 NextState;
|
UInt32 NextState;
|
||||||
if (!m_Buffer.ReadVarUTF8String(ServerAddress))
|
if (!m_Buffer.ReadVarUTF8String(ServerAddress))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!m_Buffer.ReadBEShort(ServerPort))
|
if (!m_Buffer.ReadBEUInt16(ServerPort))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -926,19 +926,19 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_Buffer.CommitRead();
|
m_Buffer.CommitRead();
|
||||||
m_Protocol = new cProtocol172(m_Client, ServerAddress, (UInt16)ServerPort, NextState);
|
m_Protocol = new cProtocol172(m_Client, ServerAddress, ServerPort, NextState);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case PROTO_VERSION_1_7_6:
|
case PROTO_VERSION_1_7_6:
|
||||||
{
|
{
|
||||||
AString ServerAddress;
|
AString ServerAddress;
|
||||||
short ServerPort;
|
UInt16 ServerPort;
|
||||||
UInt32 NextState;
|
UInt32 NextState;
|
||||||
if (!m_Buffer.ReadVarUTF8String(ServerAddress))
|
if (!m_Buffer.ReadVarUTF8String(ServerAddress))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!m_Buffer.ReadBEShort(ServerPort))
|
if (!m_Buffer.ReadBEUInt16(ServerPort))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -947,19 +947,19 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_Buffer.CommitRead();
|
m_Buffer.CommitRead();
|
||||||
m_Protocol = new cProtocol176(m_Client, ServerAddress, (UInt16)ServerPort, NextState);
|
m_Protocol = new cProtocol176(m_Client, ServerAddress, ServerPort, NextState);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case PROTO_VERSION_1_8_0:
|
case PROTO_VERSION_1_8_0:
|
||||||
{
|
{
|
||||||
AString ServerAddress;
|
AString ServerAddress;
|
||||||
short ServerPort;
|
UInt16 ServerPort;
|
||||||
UInt32 NextState;
|
UInt32 NextState;
|
||||||
if (!m_Buffer.ReadVarUTF8String(ServerAddress))
|
if (!m_Buffer.ReadVarUTF8String(ServerAddress))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!m_Buffer.ReadBEShort(ServerPort))
|
if (!m_Buffer.ReadBEUInt16(ServerPort))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -968,12 +968,12 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_Buffer.CommitRead();
|
m_Buffer.CommitRead();
|
||||||
m_Protocol = new cProtocol180(m_Client, ServerAddress, (UInt16)ServerPort, NextState);
|
m_Protocol = new cProtocol180(m_Client, ServerAddress, ServerPort, NextState);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGINFO("Client \"%s\" uses an unsupported protocol (lengthed, version %u)",
|
LOGINFO("Client \"%s\" uses an unsupported protocol (lengthed, version %u (0x%x))",
|
||||||
m_Client->GetIPString().c_str(), ProtocolVersion
|
m_Client->GetIPString().c_str(), ProtocolVersion, ProtocolVersion
|
||||||
);
|
);
|
||||||
m_Client->Kick("Unsupported protocol version");
|
m_Client->Kick("Unsupported protocol version");
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user