1
0
Fork 0

Moved all packet-serializing code into cProtocol125; half the packet classes aren't needed anymore.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@800 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-08-28 21:59:49 +00:00
parent 0425d8c8a5
commit 1651fcd980
94 changed files with 818 additions and 2737 deletions

View File

@ -775,14 +775,6 @@
RelativePath="..\source\packets\cPacket_13.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_AddToInventory.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_AddToInventory.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_ArmAnim.cpp"
>
@ -791,22 +783,6 @@
RelativePath="..\source\packets\cPacket_ArmAnim.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_BlockAction.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_BlockAction.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_BlockChange.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_BlockChange.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_BlockDig.cpp"
>
@ -831,14 +807,6 @@
RelativePath="..\source\packets\cPacket_Chat.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_CollectItem.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_CollectItem.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_CreativeInventoryAction.cpp"
>
@ -847,14 +815,6 @@
RelativePath="..\source\packets\cPacket_CreativeInventoryAction.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_DestroyEntity.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_DestroyEntity.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_Disconnect.cpp"
>
@ -863,30 +823,6 @@
RelativePath="..\source\packets\cPacket_Disconnect.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_EntityEquipment.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_EntityEquipment.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_EntityLook.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_EntityLook.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_EntityStatus.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_EntityStatus.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_Explosion.cpp"
>
@ -911,22 +847,6 @@
RelativePath="..\source\packets\cPacket_Handshake.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_InventoryProgressBar.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_InventoryProgressBar.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_InventorySlot.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_InventorySlot.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_ItemData.cpp"
>
@ -959,54 +879,6 @@
RelativePath="..\source\packets\cPacket_Login.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_MapChunk.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_MapChunk.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_Metadata.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_Metadata.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_MultiBlock.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_MultiBlock.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_NamedEntitySpawn.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_NamedEntitySpawn.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_NewInvalidState.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_NewInvalidState.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_PickupSpawn.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_PickupSpawn.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_Ping.h"
>
@ -1019,30 +891,6 @@
RelativePath="..\source\packets\cPacket_Player.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_PreChunk.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_PreChunk.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_RelativeEntityMove.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_RelativeEntityMove.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_RelativeEntityMoveLook.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_RelativeEntityMoveLook.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_Respawn.cpp"
>
@ -1051,54 +899,6 @@
RelativePath="..\source\packets\cPacket_Respawn.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_SoundEffect.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_SoundEffect.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_SpawnMob.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_SpawnMob.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_TeleportEntity.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_TeleportEntity.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_Thunderbolt.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_Thunderbolt.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_TimeUpdate.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_TimeUpdate.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_UpdateHealth.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_UpdateHealth.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_UpdateSign.cpp"
>
@ -1115,14 +915,6 @@
RelativePath="..\source\packets\cPacket_UseEntity.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_WholeInventory.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_WholeInventory.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_WindowClick.cpp"
>
@ -1139,18 +931,6 @@
RelativePath="..\source\packets\cPacket_WindowClose.h"
>
</File>
<File
RelativePath="..\source\packets\cPacket_WindowOpen.cpp"
>
</File>
<File
RelativePath="..\source\packets\cPacket_WindowOpen.h"
>
</File>
<File
RelativePath="..\source\PacketID.h"
>
</File>
</Filter>
<Filter
Name="Mobs"

View File

@ -11,6 +11,7 @@
#pragma once
#include "Defines.h"
#include "Endianness.h"
@ -40,46 +41,46 @@ public:
virtual void DataReceived(const char * a_Data, int a_Size) = 0;
// Sending stuff to clients:
virtual void SendDisconnect (const AString & a_Reason) = 0;
virtual void SendLogin (const cPlayer & a_Player) = 0;
virtual void SendHandshake (const AString & a_ServerName) = 0;
virtual void SendInventorySlot (int a_WindowID, short a_SlotNum, const cItem & a_Item) = 0;
virtual void SendChat (const AString & a_Message) = 0;
virtual void SendPlayerAnimation (const cPlayer & a_Player, char a_Animation) = 0;
virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) = 0;
virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) = 0;
virtual void SendWindowClose (char a_WindowID) = 0;
virtual void SendWholeInventory (const cInventory & a_Inventory) = 0;
virtual void SendWholeInventory (const cWindow & a_Window) = 0;
virtual void SendTeleportEntity (const cEntity & a_Entity) = 0;
virtual void SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline) = 0;
virtual void SendPlayerPosition (void) = 0;
virtual void SendRelEntMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0;
virtual void SendRelEntMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0;
virtual void SendEntLook (const cEntity & a_Entity) = 0;
virtual void SendEntHeadLook (const cEntity & a_Entity) = 0;
virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2) = 0;
virtual void SendHealth (void) = 0;
virtual void SendRespawn (void) = 0;
virtual void SendGameMode (eGameMode a_GameMode) = 0;
virtual void SendDestroyEntity (const cEntity & a_Entity) = 0;
virtual void SendPlayerMoveLook (void) = 0;
virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) = 0;
virtual void SendMetadata (const cPawn & a_Entity) = 0;
virtual void SendInventoryProgress(char a_WindowID, short a_Progressbar, short a_Value) = 0;
virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0;
virtual void SendPickupSpawn (const cPickup & a_Pickup) = 0;
virtual void SendSpawnMob (const cMonster & a_Mob) = 0;
virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) = 0;
virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) = 0;
virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) = 0;
virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) = 0;
virtual void SendWeather (eWeather a_Weather) = 0;
virtual void SendTimeUpdate (Int64 a_WorldTime) = 0;
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
virtual void SendChat (const AString & a_Message) = 0;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) = 0;
virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) = 0;
virtual void SendDestroyEntity (const cEntity & a_Entity) = 0;
virtual void SendDisconnect (const AString & a_Reason) = 0;
virtual void SendEntHeadLook (const cEntity & a_Entity) = 0;
virtual void SendEntLook (const cEntity & a_Entity) = 0;
virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) = 0;
virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) = 0;
virtual void SendGameMode (eGameMode a_GameMode) = 0;
virtual void SendHandshake (const AString & a_ServerName) = 0;
virtual void SendHealth (void) = 0;
virtual void SendInventoryProgress(char a_WindowID, short a_Progressbar, short a_Value) = 0;
virtual void SendInventorySlot (int a_WindowID, short a_SlotNum, const cItem & a_Item) = 0;
virtual void SendKeepAlive (int a_PingID) = 0;
virtual void SendLogin (const cPlayer & a_Player) = 0;
virtual void SendMetadata (const cEntity & a_Entity) = 0;
virtual void SendPickupSpawn (const cPickup & a_Pickup) = 0;
virtual void SendPlayerAnimation (const cPlayer & a_Player, char a_Animation) = 0;
virtual void SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline) = 0;
virtual void SendPlayerMoveLook (void) = 0;
virtual void SendPlayerPosition (void) = 0;
virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0;
virtual void SendRelEntMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0;
virtual void SendRelEntMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0;
virtual void SendRespawn (void) = 0;
virtual void SendSpawnMob (const cMonster & a_Mob) = 0;
virtual void SendTeleportEntity (const cEntity & a_Entity) = 0;
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
virtual void SendTimeUpdate (Int64 a_WorldTime) = 0;
virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) = 0;
virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) = 0;
virtual void SendWeather (eWeather a_Weather) = 0;
virtual void SendWholeInventory (const cInventory & a_Inventory) = 0;
virtual void SendWholeInventory (const cWindow & a_Window) = 0;
virtual void SendWindowClose (char a_WindowID) = 0;
virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) = 0;
protected:
cClientHandle * m_Client;
@ -87,6 +88,79 @@ protected:
/// A generic data-sending routine, all outgoing packet data needs to be routed through this so that descendants may override it
virtual void SendData(const char * a_Data, int a_Size) = 0;
/// Called after writing each packet, enables descendants to flush their buffers
virtual void Flush(void) {};
// Helpers for writing partial packet data, write using SendData()
void WriteByte(char a_Value)
{
SendData((const char *)&a_Value, 1);
}
void WriteShort(short a_Value)
{
a_Value = htons(a_Value);
SendData((const char *)&a_Value, 2);
}
/*
void WriteShort(unsigned short a_Value)
{
a_Value = htons(a_Value);
SendData((const char *)&a_Value, 2);
}
*/
void WriteInt(int a_Value)
{
a_Value = htonl(a_Value);
SendData((const char *)&a_Value, 4);
}
void WriteInt(unsigned int a_Value)
{
a_Value = htonl(a_Value);
SendData((const char *)&a_Value, 4);
}
void WriteInt64 (Int64 a_Value)
{
a_Value = HostToNetwork8(&a_Value);
SendData((const char *)&a_Value, 8);
}
void WriteFloat (float a_Value)
{
unsigned int val = HostToNetwork4(&a_Value);
SendData((const char *)&val, 4);
}
void WriteDouble(double a_Value)
{
unsigned long long val = HostToNetwork8(&a_Value);
SendData((const char *)&val, 8);
}
void WriteString(const AString & a_Value)
{
AString UTF16;
UTF8ToRawBEUTF16(a_Value.c_str(), a_Value.length(), UTF16);
WriteShort((unsigned short)(UTF16.size() / 2));
SendData(UTF16.data(), UTF16.size());
}
void WriteBool(bool a_Value)
{
WriteByte(a_Value ? 1 : 0);
}
void WriteVectorI(const Vector3i & a_Vector)
{
WriteInt(a_Vector.x);
WriteInt(a_Vector.y);
WriteInt(a_Vector.z);
}
} ;

File diff suppressed because it is too large Load Diff

View File

@ -47,13 +47,13 @@ public:
virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override;
virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override;
virtual void SendGameMode (eGameMode a_GameMode) override;
virtual void SendHandshake (const AString & a_ServerName) override;
virtual void SendHandshake (const AString & a_ConnectionHash) override;
virtual void SendHealth (void) override;
virtual void SendInventoryProgress(char a_WindowID, short a_Progressbar, short a_Value) override;
virtual void SendInventorySlot (int a_WindowID, short a_SlotNum, const cItem & a_Item) override;
virtual void SendKeepAlive (int a_PingID) override;
virtual void SendLogin (const cPlayer & a_Player) override;
virtual void SendMetadata (const cPawn & a_Entity) override;
virtual void SendMetadata (const cEntity & a_Entity) override;
virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
virtual void SendPlayerAnimation (const cPlayer & a_Player, char a_Animation) override;
virtual void SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline) override;
@ -86,39 +86,50 @@ protected:
cByteBuffer m_ReceivedData; //< Buffer for the received data
void Send(const cPacket & a_Packet);
virtual void SendData(const char * a_Data, int a_Size) override;
/// Parse the packet of the specified type from m_ReceivedData (switch into ParseXYZ() )
virtual int ParsePacket(unsigned char a_PacketType);
// Specific packet parsers:
virtual int ParseKeepAlive (void);
virtual int ParseHandshake (void);
virtual int ParseLogin (void);
virtual int ParsePlayerPosition (void);
virtual int ParsePlayerLook (void);
virtual int ParsePlayerMoveLook (void);
virtual int ParsePlayerAbilities (void);
virtual int ParseChat (void);
virtual int ParseArmAnim (void);
virtual int ParseFlying (void);
virtual int ParseBlockDig (void);
virtual int ParseBlockPlace (void);
virtual int ParseDisconnect (void);
virtual int ParseItemSwitch (void);
virtual int ParseEntityEquipment (void);
virtual int ParseChat (void);
virtual int ParseCreativeInventoryAction(void);
virtual int ParseNewInvalidState (void);
virtual int ParsePickupSpawn (void);
virtual int ParseUseEntity (void);
virtual int ParseWindowClose (void);
virtual int ParseWindowClick (void);
virtual int ParseDisconnect (void);
virtual int ParseEntityAction (void);
virtual int ParseUpdateSign (void);
virtual int ParseRespawn (void);
virtual int ParseFlying (void);
virtual int ParseHandshake (void);
virtual int ParseSlotSelected (void);
virtual int ParseKeepAlive (void);
virtual int ParseLogin (void);
virtual int ParsePing (void);
virtual int ParsePlayerAbilities (void);
virtual int ParsePlayerLook (void);
virtual int ParsePlayerMoveLook (void);
virtual int ParsePlayerPosition (void);
virtual int ParseRespawn (void);
virtual int ParseUpdateSign (void);
virtual int ParseUseEntity (void);
virtual int ParseWindowClick (void);
virtual int ParseWindowClose (void);
// Utility functions:
/// Writes a "pre-chunk" packet
void SendPreChunk(int a_ChunkX, int a_ChunkZ, bool a_ShouldLoad);
/// Writes a "whole inventory" packet with the specified params
void SendWholeInventory(char a_WindowID, int a_NumItems, const cItem * a_Items);
/// Writes one item, "slot" as the protocol wiki calls it
virtual void WriteItem(const cItem & a_Item);
/// Returns the entity metadata representation
AString GetEntityMetaData(const cEntity & a_Entity);
/// Returns the entity common metadata, index 0 (generic flags)
char GetEntityMetadataFlags(const cEntity & a_Entity);
} ;

View File

@ -306,3 +306,162 @@ AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8)
// UTF-8 conversion code adapted from:
// http://stackoverflow.com/questions/2867123/convert-utf-16-to-utf-8-under-windows-and-linux-in-c
#define UNI_MAX_BMP 0x0000FFFF
#define UNI_MAX_UTF16 0x0010FFFF
#define UNI_MAX_UTF32 0x7FFFFFFF
#define UNI_MAX_LEGAL_UTF32 0x0010FFFF
#define UNI_SUR_HIGH_START 0xD800
#define UNI_SUR_HIGH_END 0xDBFF
#define UNI_SUR_LOW_START 0xDC00
#define UNI_SUR_LOW_END 0xDFFF
static const char trailingBytesForUTF8[256] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5
};
static const unsigned int offsetsFromUTF8[6] =
{
0x00000000UL, 0x00003080UL, 0x000E2080UL,
0x03C82080UL, 0xFA082080UL, 0x82082080UL
};
static bool isLegalUTF8(const unsigned char * source, int length)
{
unsigned char a;
const unsigned char * srcptr = source + length;
switch (length)
{
default: return false;
// Everything else falls through when "true"...
case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
case 2:
{
if ((a = (*--srcptr)) > 0xBF) return false;
switch (*source)
{
// no fall-through in this inner switch
case 0xE0: if (a < 0xA0) return false; break;
case 0xED: if (a > 0x9F) return false; break;
case 0xF0: if (a < 0x90) return false; break;
case 0xF4: if (a > 0x8F) return false; break;
default: if (a < 0x80) return false;
}
}
case 1: if (*source >= 0x80 && *source < 0xC2) return false;
}
if (*source > 0xF4) return false;
return true;
}
AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16)
{
a_UTF16.clear();
a_UTF16.reserve(a_UTF8Length * 3);
const unsigned char * source = (const unsigned char*)a_UTF8;
const unsigned char * sourceEnd = source + a_UTF8Length;
const int halfShift = 10; // used for shifting by 10 bits
const unsigned int halfBase = 0x0010000UL;
const unsigned int halfMask = 0x3FFUL;
while (source < sourceEnd)
{
unsigned int ch = 0;
unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
if (source + extraBytesToRead >= sourceEnd)
{
return a_UTF16;
}
// Do this check whether lenient or strict
if (!isLegalUTF8(source, extraBytesToRead + 1))
{
return a_UTF16;
break;
}
// The cases all fall through. See "Note A" below.
switch (extraBytesToRead)
{
case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
case 3: ch += *source++; ch <<= 6;
case 2: ch += *source++; ch <<= 6;
case 1: ch += *source++; ch <<= 6;
case 0: ch += *source++;
}
ch -= offsetsFromUTF8[extraBytesToRead];
if (ch <= UNI_MAX_BMP)
{
// Target is a character <= 0xFFFF
if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END)
{
// UTF-16 surrogate values are illegal in UTF-32
ch = ' ';
}
unsigned short v = htons((unsigned short)ch);
a_UTF16.append((const char *)&v, 2);
}
else if (ch > UNI_MAX_UTF16)
{
// Invalid value, replace with a space
unsigned short v = htons(' ');
a_UTF16.append((const char *)&v, 2);
}
else
{
// target is a character in range 0xFFFF - 0x10FFFF.
ch -= halfBase;
unsigned short v1 = htons((ch >> halfShift) + UNI_SUR_HIGH_START);
unsigned short v2 = htons((ch & halfMask) + UNI_SUR_LOW_START);
a_UTF16.append((const char *)&v1, 2);
a_UTF16.append((const char *)&v2, 2);
}
}
return a_UTF16;
}
/* ---------------------------------------------------------------------
Note A.
The fall-through switches in UTF-8 reading code save a
temp variable, some decrements & conditionals. The switches
are equivalent to the following loop:
{
int tmpBytesToRead = extraBytesToRead+1;
do {
ch += *source++;
--tmpBytesToRead;
if (tmpBytesToRead) ch <<= 6;
} while (tmpBytesToRead > 0);
}
--------------------------------------------------------------------- */

View File

@ -54,6 +54,9 @@ extern AStringList GetDirectoryContents(const char * a_Directory);
/// Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8
extern AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8);
/// Converts a UTF-8 string into a UTF-16 BE string, packing that back into AString; return a ref to a_UTF16
extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16);
// If you have any other string helper functions, declare them here

View File

@ -3,7 +3,7 @@
#include "cChatColor.h"
const std::string cChatColor::Color = "\xa7"; // Old color was "\xc2\xa7" or in other words: "§"
const std::string cChatColor::Color = "\xc2\xa7"; // or in other words: "§"
const std::string cChatColor::Delimiter = "\xa7";
const std::string cChatColor::Black = cChatColor::Color + "0";
const std::string cChatColor::Navy = cChatColor::Color + "1";

View File

@ -508,34 +508,6 @@ void cClientHandle::HandleUnexpectedPacket(int a_PacketType)
void cClientHandle::HandleMoveLookConfirm(double a_PosX, double a_PosY, double a_PosZ)
{
Vector3d ReceivedPosition = Vector3d(a_PosX, a_PosY, a_PosZ);
// LOGD("Received MoveLook confirmation: {%0.2f %0.2f %0.2f}", a_PosX, a_PosY, a_PosZ);
// Test the distance between points with a small/large enough value instead of comparing directly. Floating point inaccuracies might screw stuff up
double Dist = (ReceivedPosition - m_ConfirmPosition).SqrLength();
if (Dist < 1.0)
{
// Test
if (ReceivedPosition.Equals(m_ConfirmPosition))
{
LOGINFO("Exact position confirmed by client!");
}
m_State = csPlaying;
}
else
{
LOGWARNING("Player \"%s\" sent a weird position confirmation %.2f blocks away, retrying", m_Username.c_str(), Dist);
m_ConfirmPosition = m_Player->GetPosition();
SendPlayerMoveLook();
}
}
void cClientHandle::HandleCreativeInventory(short a_SlotNum, const cItem & a_HeldItem)
{
// This is for creative Inventory changes
@ -827,18 +799,44 @@ void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_
return;
}
*/
if (m_State != csPlaying)
switch (m_State)
{
// Ignore this packet unles the player is fully in:
return;
case csPlaying:
{
m_Player->MoveTo(Vector3d(a_PosX, a_PosY, a_PosZ));
m_Player->SetStance (a_Stance);
m_Player->SetTouchGround(a_IsOnGround);
m_Player->SetRotation (a_Rotation);
m_Player->SetPitch (a_Pitch);
m_Player->WrapRotation();
break;
}
case csDownloadingWorld:
{
Vector3d ReceivedPosition = Vector3d(a_PosX, a_PosY, a_PosZ);
// LOGD("Received MoveLook confirmation: {%0.2f %0.2f %0.2f}", a_PosX, a_PosY, a_PosZ);
// Test the distance between points with a small/large enough value instead of comparing directly. Floating point inaccuracies might screw stuff up
double Dist = (ReceivedPosition - m_ConfirmPosition).SqrLength();
if (Dist < 1.0)
{
// Test
if (ReceivedPosition.Equals(m_ConfirmPosition))
{
LOGINFO("Exact position confirmed by client!");
}
m_State = csPlaying;
}
else
{
LOGWARNING("Player \"%s\" sent a weird position confirmation %.2f blocks away, retrying", m_Username.c_str(), Dist);
m_ConfirmPosition = m_Player->GetPosition();
SendPlayerMoveLook();
}
break;
}
}
m_Player->MoveTo(Vector3d(a_PosX, a_PosY, a_PosZ));
m_Player->SetStance (a_Stance);
m_Player->SetTouchGround(a_IsOnGround);
m_Player->SetRotation (a_Rotation);
m_Player->SetPitch (a_Pitch);
m_Player->WrapRotation();
}

View File

@ -148,9 +148,6 @@ public:
void HandleLogin (int a_ProtocolVersion, const AString & a_Username);
void HandleUnexpectedPacket(int a_PacketType); // the default case -> kick
// Packets handled while in csConfirmingPos:
void HandleMoveLookConfirm(double a_PosX, double a_PosY, double a_PosZ); // While !m_bPositionConfirmed
// Packets handled while in csPlaying:
void HandleCreativeInventory(short a_SlotNum, const cItem & a_HeldItem);
void HandlePlayerPos (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround);

View File

@ -36,6 +36,8 @@ cEntity::cEntity(const double & a_X, const double & a_Y, const double & a_Z)
, m_EntityType( eEntityType_Entity )
, m_World( 0 )
, m_bRemovedFromChunk( false )
, m_FireDamageInterval(0.f)
, m_BurnPeriod(0.f)
{
cCSLock Lock(m_CSCount);
m_EntityCount++;

View File

@ -121,6 +121,13 @@ public:
virtual void SpawnOn(cClientHandle & a_Client) {ASSERT(!"SpawnOn() unimplemented!"); } // tolua_export
void WrapRotation();
// Metadata flags; descendants may override the defaults:
virtual bool IsOnFire (void) const {return (m_BurnPeriod > 0); }
virtual bool IsCrouched (void) const {return false; }
virtual bool IsRiding (void) const {return false; }
virtual bool IsSprinting(void) const {return false; }
virtual bool IsRclking (void) const {return false; }
protected:
virtual void Destroyed() {} // Called after the entity has been destroyed
@ -154,6 +161,9 @@ protected:
eEntityType m_EntityType;
cWorld* m_World;
float m_FireDamageInterval;
float m_BurnPeriod;
}; //tolua_export
typedef std::list<cEntity *> cEntityList;

View File

@ -29,8 +29,6 @@ cPawn::cPawn()
, m_TimeLastTeleportPacket( 0.f )
, m_bBurnable(true)
, m_MetaData(NORMAL)
, m_FireDamageInterval(0.f)
, m_BurnPeriod(0.f)
{
SetMaxHealth(20);
}

View File

@ -59,10 +59,6 @@ protected:
double m_LastPosX, m_LastPosY, m_LastPosZ;
float m_TimeLastTeleportPacket;
float m_FireDamageInterval;
float m_BurnPeriod;
}; //tolua_export

View File

@ -769,16 +769,16 @@ AString cPlayer::GetColor(void) const
void cPlayer::TossItem(
bool a_bDraggingItem,
int a_Amount /* = 1 */,
int a_CreateType /* = 0 */,
int a_CreateHealth /* = 0 */
char a_Amount /* = 1 */,
short a_CreateType /* = 0 */,
short a_CreateHealth /* = 0 */
)
{
cItems Drops;
if (a_CreateType)
{
// Just create item without touching the inventory (used in creative mode)
Drops.push_back(cItem((ENUM_ITEM_ID)a_CreateType, (char)a_Amount, a_CreateHealth));
Drops.push_back(cItem(a_CreateType, a_Amount, a_CreateHealth));
}
else
{

View File

@ -85,7 +85,7 @@ public:
AString GetColor(void) const; //tolua_export
void TossItem(bool a_bDraggingItem, int a_Amount = 1, int a_CreateType = 0, int a_CreateHealth = 0); //tolua_export
void TossItem(bool a_bDraggingItem, char a_Amount = 1, short a_CreateType = 0, short a_CreateHealth = 0); //tolua_export
void Heal( int a_Health ); //tolua_export

View File

@ -52,15 +52,6 @@ public:
return PACKET_ERROR;
}
/// Called to serialize the packet into a string. Append all packet data to a_Data, including the packet type!
virtual void Serialize(AString & a_Data) const
{
// There are packets that are sent C->S only, those don't have a serializing function
UNUSED(a_Data);
LOGERROR("Packet type 0x%02x has no serializer defined!", m_PacketID);
ASSERT(!"Unserialized packet");
}
virtual cPacket * Clone() const = 0;
unsigned char m_PacketID;

View File

@ -1,20 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_AddToInventory.h"
#include "cPacket_WholeInventory.h"
#include "cPacket_ItemData.h"
void cPacket_AddToInventory::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
cPacket_ItemData::AppendItem(a_Data, m_ItemType, m_Count, m_Life);
}

View File

@ -1,26 +0,0 @@
#pragma once
#include "cPacket.h"
#include "../BlockID.h"
class cPacket_AddToInventory : public cPacket
{
public:
cPacket_AddToInventory()
: m_ItemType( E_ITEM_EMPTY )
, m_Count( 0 )
, m_Life( 0 )
{ m_PacketID = E_ADD_TO_INV; }
virtual cPacket* Clone() const { return new cPacket_AddToInventory(*this); }
// _X: This was unimplemented, do we need it?:
// bool Parse( cSocket & a_Socket );
virtual void Serialize(AString & a_Data) const override;
ENUM_ITEM_ID m_ItemType;
char m_Count;
short m_Life;
static const unsigned int c_Size = 1;
};

View File

@ -18,14 +18,3 @@ int cPacket_ArmAnim::Parse(cByteBuffer & a_Buffer)
void cPacket_ArmAnim::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_EntityID);
AppendByte (a_Data, m_Animation);
}

View File

@ -1,21 +1,30 @@
#pragma once
#include "cPacket.h"
class cPacket_ArmAnim : public cPacket
class cPacket_ArmAnim :
public cPacket
{
public:
cPacket_ArmAnim()
: m_EntityID( 0 )
, m_Animation( 0 )
{ m_PacketID = E_ANIMATION; }
{
m_PacketID = E_ANIMATION;
}
virtual cPacket* Clone() const { return new cPacket_ArmAnim(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
int m_EntityID;
char m_Animation;
static const unsigned int c_Size = 1 + 4 + 1;
};
};

View File

@ -1,36 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_BlockAction.h"
cPacket_BlockAction::cPacket_BlockAction( const cPacket_BlockAction & a_Copy )
{
m_PacketID = E_BLOCK_ACTION;
m_BlockX = a_Copy.m_BlockX;
m_BlockY = a_Copy.m_BlockY;
m_BlockZ = a_Copy.m_BlockZ;
m_Byte1 = a_Copy.m_Byte1;
m_Byte2 = a_Copy.m_Byte2;
}
void cPacket_BlockAction::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_BlockX);
AppendShort (a_Data, m_BlockY);
AppendInteger(a_Data, m_BlockZ);
AppendByte (a_Data, m_Byte1);
AppendByte (a_Data, m_Byte2);
}

View File

@ -1,38 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_BlockAction :
public cPacket
{
public:
cPacket_BlockAction()
: m_BlockX( 0 )
, m_BlockY( 0 )
, m_BlockZ( 0 )
, m_Byte1( 0 )
, m_Byte2( 0 )
{
m_PacketID = E_BLOCK_ACTION;
}
cPacket_BlockAction( const cPacket_BlockAction & a_Copy );
virtual cPacket * Clone() const { return new cPacket_BlockAction(*this); }
virtual void Serialize(AString & a_Data) const override;
int m_BlockX;
short m_BlockY;
int m_BlockZ;
char m_Byte1; // Varies
char m_Byte2; // Varies
};

View File

@ -1,22 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_BlockChange.h"
void cPacket_BlockChange::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_PosX);
AppendByte (a_Data, m_PosY);
AppendInteger(a_Data, m_PosZ);
AppendByte (a_Data, m_BlockType);
AppendByte (a_Data, m_BlockMeta);
}

View File

@ -1,27 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_BlockChange : public cPacket
{
public:
cPacket_BlockChange()
: m_PosX( 0 )
, m_PosY( 0 )
, m_PosZ( 0 )
, m_BlockType( 0 )
, m_BlockMeta( 0 )
{ m_PacketID = E_BLOCK_CHANGE; }
virtual cPacket* Clone() const { return new cPacket_BlockChange(*this); }
virtual void Serialize(AString & a_Data) const override;
int m_PosX;
unsigned char m_PosY;
int m_PosZ;
char m_BlockType;
char m_BlockMeta;
static const unsigned int c_Size = 1 + 4 + 1 + 4 + 1 + 1;
};

View File

@ -7,19 +7,6 @@
void cPacket_BlockDig::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_PosX);
AppendByte (a_Data, m_PosY);
AppendInteger(a_Data, m_PosZ);
AppendByte (a_Data, m_Direction);
}
int cPacket_BlockDig::Parse(cByteBuffer & a_Buffer)
{
int TotalBytes = 0;

View File

@ -24,7 +24,6 @@ public:
virtual cPacket* Clone() const { return new cPacket_BlockDig(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
char m_Status;
int m_PosX;

View File

@ -17,13 +17,3 @@ int cPacket_Chat::Parse(cByteBuffer & a_Buffer)
void cPacket_Chat::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendString16(a_Data, m_Message);
}

View File

@ -1,20 +1,22 @@
#pragma once
#include "cPacket.h"
class cPacket_Chat : public cPacket
class cPacket_Chat :
public cPacket
{
public:
cPacket_Chat() { m_PacketID = E_CHAT; }
cPacket_Chat( const std::string & a_Message ) : m_Message( a_Message) { m_PacketID = E_CHAT; }
virtual cPacket* Clone() const { return new cPacket_Chat(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
AString m_Message;
static const unsigned int c_Size = 3; // Minimum size
};

View File

@ -1,19 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_CollectItem.h"
void cPacket_CollectItem::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_CollectedID);
AppendInteger(a_Data, m_CollectorID);
}

View File

@ -1,27 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_CollectItem : public cPacket
{
public:
cPacket_CollectItem()
: m_CollectedID( 0 )
, m_CollectorID( 0 )
{ m_PacketID = E_COLLECT_ITEM; }
virtual cPacket* Clone() const { return new cPacket_CollectItem(*this); }
virtual void Serialize(AString & a_Data) const override;
int m_CollectedID;
int m_CollectorID;
static const unsigned int c_Size = 1 + 4 + 4;
};

View File

@ -38,14 +38,3 @@ int cPacket_CreativeInventoryAction::Parse(cByteBuffer & a_Buffer)
void cPacket_CreativeInventoryAction::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendShort(a_Data, m_SlotNum);
cPacket_ItemData::AppendItem(a_Data, m_ClickedItem);
}

View File

@ -22,7 +22,6 @@ public:
virtual cPacket* Clone() const { return new cPacket_CreativeInventoryAction(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
short m_SlotNum;
cItem m_ClickedItem;

View File

@ -1,30 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_DestroyEntity.h"
#include "../cEntity.h"
cPacket_DestroyEntity::cPacket_DestroyEntity(cEntity* a_Entity)
{
m_PacketID = E_DESTROY_ENT;
m_UniqueID = a_Entity->GetUniqueID();
}
void cPacket_DestroyEntity::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_UniqueID);
}

View File

@ -1,33 +0,0 @@
#pragma once
#include "cPacket.h"
class cEntity;
class cPacket_DestroyEntity : public cPacket
{
public:
cPacket_DestroyEntity()
: m_UniqueID( 0 )
{ m_PacketID = E_DESTROY_ENT; }
cPacket_DestroyEntity(cEntity* a_Entity);
virtual cPacket* Clone() const { return new cPacket_DestroyEntity(*this); }
virtual void Serialize(AString & a_Data) const override;
int m_UniqueID;
static const unsigned int c_Size = 1 + 4;
};

View File

@ -18,12 +18,3 @@ int cPacket_Disconnect::Parse(cByteBuffer & a_Buffer)
void cPacket_Disconnect::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendString16(a_Data, m_Reason);
}

View File

@ -15,7 +15,6 @@ public:
virtual cPacket* Clone() const { return new cPacket_Disconnect(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
AString m_Reason;
static const unsigned int c_Size = 3; // Minimum size

View File

@ -1,48 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_EntityEquipment.h"
cPacket_EntityEquipment::cPacket_EntityEquipment( const cPacket_EntityEquipment & a_Copy )
{
m_PacketID = E_ENTITY_EQUIPMENT;
m_UniqueID = a_Copy.m_UniqueID;
m_SlotNum = a_Copy.m_SlotNum;
m_ItemType = a_Copy.m_ItemType;
m_ItemDamage = a_Copy.m_ItemDamage;
}
int cPacket_EntityEquipment::Parse(cByteBuffer & a_Buffer)
{
int TotalBytes = 0;
HANDLE_PACKET_READ(ReadBEInt, m_UniqueID, TotalBytes);
HANDLE_PACKET_READ(ReadBEShort, m_SlotNum, TotalBytes);
HANDLE_PACKET_READ(ReadBEShort, m_ItemType, TotalBytes);
HANDLE_PACKET_READ(ReadBEShort, m_ItemDamage, TotalBytes);
return TotalBytes;
}
void cPacket_EntityEquipment::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_UniqueID);
AppendShort (a_Data, m_SlotNum);
AppendShort (a_Data, m_ItemType);
AppendShort (a_Data, m_ItemDamage);
}

View File

@ -1,35 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_EntityEquipment : public cPacket
{
public:
cPacket_EntityEquipment()
: m_UniqueID( 0 )
, m_SlotNum( 0 )
, m_ItemType( 0 )
, m_ItemDamage( 0 )
{
m_PacketID = E_ENTITY_EQUIPMENT;
}
cPacket_EntityEquipment( const cPacket_EntityEquipment & a_Copy );
virtual cPacket * Clone() const { return new cPacket_EntityEquipment(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
int m_UniqueID;
short m_SlotNum; // 0 = hold 1-4 = armor
short m_ItemType;
short m_ItemDamage;
};

View File

@ -1,64 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_EntityLook.h"
#include "../cEntity.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cPacket_EntityLook:
cPacket_EntityLook::cPacket_EntityLook(const cEntity & a_Entity)
{
m_PacketID = E_ENT_LOOK;
m_UniqueID = a_Entity.GetUniqueID();
m_Rotation = (char)((a_Entity.GetRotation() / 360.f) * 256);
m_Pitch = (char)((a_Entity.GetPitch() / 360.f) * 256);
}
void cPacket_EntityLook::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_UniqueID);
AppendByte (a_Data, m_Rotation);
AppendByte (a_Data, m_Pitch);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cPacket_EntityHeadLook:
cPacket_EntityHeadLook::cPacket_EntityHeadLook(const cEntity & a_Entity)
{
m_PacketID = E_ENT_HEAD_LOOK;
m_UniqueID = a_Entity.GetUniqueID();
m_HeadYaw = (char)((a_Entity.GetRotation() / 360.f) * 256);
}
void cPacket_EntityHeadLook::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_UniqueID);
AppendByte (a_Data, m_HeadYaw);
}

View File

@ -1,62 +0,0 @@
#pragma once
#include "cPacket.h"
class cEntity;
class cPacket_EntityLook :
public cPacket
{
public:
cPacket_EntityLook(void)
: m_UniqueID( 0 )
, m_Rotation( 0 )
, m_Pitch( 0 )
{ m_PacketID = E_ENT_LOOK; }
cPacket_EntityLook(const cEntity & a_Entity);
virtual cPacket* Clone(void) const { return new cPacket_EntityLook(*this); }
virtual void Serialize(AString & a_Data) const override;
int m_UniqueID;
char m_Rotation;
char m_Pitch;
};
class cPacket_EntityHeadLook :
public cPacket
{
public:
cPacket_EntityHeadLook(void)
: m_UniqueID( 0 )
, m_HeadYaw( 0 )
{
m_PacketID = E_ENT_LOOK;
}
cPacket_EntityHeadLook(const cEntity & a_Entity);
virtual cPacket * Clone(void) const { return new cPacket_EntityHeadLook(*this); }
virtual void Serialize(AString & a_Data) const override;
int m_UniqueID;
char m_HeadYaw;
};

View File

@ -1,19 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_EntityStatus.h"
void cPacket_EntityStatus::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_UniqueID);
AppendByte (a_Data, m_Status);
}

View File

@ -1,31 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_EntityStatus : public cPacket
{
public:
cPacket_EntityStatus()
: m_UniqueID( 0 )
, m_Status( 0 )
{ m_PacketID = E_ENT_STATUS; }
virtual cPacket* Clone() const { return new cPacket_EntityStatus( *this ); }
virtual void Serialize(AString & a_Data) const override;
static const char STATUS_TAKEDAMAGE = 2;
static const char STATUS_DIE = 3;
int m_UniqueID;
char m_Status;
static const unsigned int c_Size = 1 + 4 + 1;
};

View File

@ -22,7 +22,7 @@ public:
~cPacket_Explosion();
virtual cPacket* Clone() const { return new cPacket_Explosion(*this); }
virtual void Serialize(AString & a_Data) const override;
virtual void Serialize(AString & a_Data) const;
double m_PosX; // The entity ID of the thunderbolt
double m_PosY; // Always true. Might have a meaning in the future...

View File

@ -17,13 +17,3 @@ int cPacket_Handshake::Parse(cByteBuffer & a_Buffer)
void cPacket_Handshake::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendString16(a_Data, m_Username);
}

View File

@ -14,7 +14,6 @@ public:
virtual cPacket* Clone() const { return new cPacket_Handshake(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
std::string m_Username;
};

View File

@ -1,20 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_InventoryProgressBar.h"
void cPacket_InventoryProgressBar::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendByte (a_Data, m_WindowID);
AppendShort(a_Data, m_ProgressBar);
AppendShort(a_Data, m_Value);
}

View File

@ -1,32 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_InventoryProgressBar : public cPacket
{
public:
cPacket_InventoryProgressBar()
: m_WindowID( 0 )
, m_ProgressBar( 0 )
, m_Value( 0 )
{
m_PacketID = E_INVENTORY_PROGRESS;
}
virtual cPacket * Clone() const { return new cPacket_InventoryProgressBar(*this); }
virtual void Serialize(AString & a_Data) const override;
char m_WindowID;
short m_ProgressBar;
short m_Value;
};

View File

@ -1,23 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_InventorySlot.h"
#include "cPacket_WholeInventory.h"
#include "cPacket_ItemData.h"
void cPacket_InventorySlot::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendByte (a_Data, m_WindowID);
AppendShort(a_Data, m_SlotNum);
cPacket_ItemData::AppendItem(a_Data, m_ItemID, m_ItemCount, m_ItemUses);
}

View File

@ -1,44 +0,0 @@
#pragma once
#include "cPacket.h"
#include "../BlockID.h"
class cPacket_InventorySlot : public cPacket // Set item [S -> C] ?
{
public:
cPacket_InventorySlot()
: m_WindowID( 0 )
, m_SlotNum( 0 )
, m_ItemID( E_ITEM_EMPTY )
, m_ItemCount( 0 )
, m_ItemUses( 0 )
{ m_PacketID = E_INVENTORY_SLOT; }
virtual cPacket* Clone() const { return new cPacket_InventorySlot(*this); }
virtual void Serialize(AString & a_Data) const override;
char m_WindowID;
short m_SlotNum; // Slot
// 0 = craft result
// 1-4 = crafting table
// 5-8 = armor
// 9-35 = inventory
// 36-44 = Hot bar
// Below = item
short m_ItemID; // if this is -1 the next stuff dont exist
char m_ItemCount;
short m_ItemUses;
static const unsigned int c_Size = 1 + 1 + 2; // Minimal size ( +1+1 = max)
};

View File

@ -17,13 +17,3 @@ int cPacket_ItemSwitch::Parse(cByteBuffer & a_Buffer)
void cPacket_ItemSwitch::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendShort(a_Data, m_SlotNum);
}

View File

@ -16,11 +16,8 @@ public:
virtual cPacket* Clone() const { return new cPacket_ItemSwitch(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
short m_SlotNum;
static const unsigned int c_Size = 1 + 2;
};

View File

@ -7,16 +7,6 @@
void cPacket_KeepAlive::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_KeepAliveID);
}
int cPacket_KeepAlive::Parse(cByteBuffer & a_Buffer)
{
int TotalBytes = 0;

View File

@ -14,8 +14,7 @@ public:
cPacket_KeepAlive(int a_PingID) { m_KeepAliveID = a_PingID; }
virtual cPacket * Clone() const { return new cPacket_KeepAlive(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
virtual int Parse(cByteBuffer & a_Buffer) override;
int m_KeepAliveID;
};

View File

@ -32,20 +32,3 @@ int cPacket_Login::Parse(cByteBuffer & a_Buffer)
void cPacket_Login::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger (a_Data, m_ProtocolVersion);
AppendString16(a_Data, m_Username);
AppendString16(a_Data, m_LevelType);
AppendInteger (a_Data, m_ServerMode);
AppendInteger (a_Data, m_Dimension);
AppendByte (a_Data, m_Difficulty);
AppendByte (a_Data, m_WorldHeight);
AppendByte (a_Data, m_MaxPlayers);
}

View File

@ -22,7 +22,6 @@ public:
virtual cPacket* Clone() const { return new cPacket_Login(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
int m_ProtocolVersion;
AString m_Username;

View File

@ -1,34 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_MapChunk.h"
#include "../ChunkDef.h"
cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkZ, const AString & a_SerializedData) :
m_PosX(a_ChunkX),
m_PosZ(a_ChunkZ),
m_SerializedData(a_SerializedData)
{
m_PacketID = E_MAP_CHUNK;
}
void cPacket_MapChunk::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_PosX);
AppendInteger(a_Data, m_PosZ);
a_Data.append(m_SerializedData);
}

View File

@ -1,34 +0,0 @@
#pragma once
#include "cPacket.h"
#include "../ChunkDef.h"
class cPacket_MapChunk :
public cPacket
{
public:
cPacket_MapChunk()
: m_PosX( 0 )
, m_PosZ( 0 )
{
m_PacketID = E_MAP_CHUNK;
}
cPacket_MapChunk(int a_ChunkX, int a_ChunkZ, const AString & a_SerializedData);
virtual cPacket* Clone() const { return new cPacket_MapChunk(*this); }
virtual void Serialize(AString & a_Data) const override;
int m_PosX;
int m_PosZ;
AString m_SerializedData;
};

View File

@ -1,110 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_Metadata.h"
cPacket_Metadata::cPacket_Metadata(int s, int id)
: m_EMetaData( (cPawn::MetaData)s )
, m_UniqueID( id )
, m_Type( 0 )
, m_MetaData( 0 )
{
m_PacketID = E_METADATA;
FormPacket();
}
cPacket_Metadata::cPacket_Metadata()
: m_UniqueID( 0 )
, m_Type( 0 )
, m_MetaData( 0 )
{
m_PacketID = E_METADATA;
m_EMetaData = cPawn::NORMAL;
FormPacket();
}
cPacket_Metadata::cPacket_Metadata(const cPacket_Metadata & a_Other)
: m_EMetaData( a_Other.m_EMetaData )
, m_UniqueID( a_Other.m_UniqueID )
, m_Type( a_Other.m_Type )
, m_MetaData( NULL )
{
m_PacketID = E_METADATA;
FormPacket();
}
cPacket_Metadata::~cPacket_Metadata()
{
delete [] m_MetaData;
}
void cPacket_Metadata::FormPacket()
{
delete [] m_MetaData;
m_MetaData = new char[3];
m_MetaDataSize = 3;
// m_UniqueID = GetUniqueID();
m_MetaData[0] = 0x00;
m_MetaData[2] = 0x7f;
switch(m_EMetaData)
{
case cPawn::NORMAL:
m_MetaData[1] = 0x00;
break;
case cPawn::BURNING:
m_MetaData[1] = 0x01;
break;
case cPawn::CROUCHED:
m_MetaData[1] = 0x02;
break;
case cPawn::RIDING:
m_MetaData[1] = 0x04;
break;
case cPawn::SPRINTING:
m_MetaData[1] = 0x08;
break;
case cPawn::EATING:
case cPawn::BLOCKING:
m_MetaData[1] = 0x10;
break;
default:
m_MetaData[1] = 0x00;
break;
}
}
void cPacket_Metadata::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_UniqueID);
AppendData (a_Data, m_MetaData, m_MetaDataSize);
}

View File

@ -1,35 +0,0 @@
#pragma once
#include "cPacket.h"
#include "../cPawn.h"
class cPacket_Metadata : public cPacket
{
public:
cPacket_Metadata(int s, int id);
cPacket_Metadata();
cPacket_Metadata(const cPacket_Metadata & a_Other);
~cPacket_Metadata();
virtual void Serialize(AString & a_Data) const override;
void FormPacket();
virtual cPacket* Clone() const { return new cPacket_Metadata( *this ); }
cPawn::MetaData m_EMetaData;
static const unsigned int c_Size = 4 + 1;
int m_UniqueID;
char m_Type;
unsigned int m_MetaDataSize;
char* m_MetaData;
};

View File

@ -1,34 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_NamedEntitySpawn.h"
void cPacket_NamedEntitySpawn::Serialize(AString & a_Data) const
{
short CurrentItem = m_CurrentItem;
ASSERT(CurrentItem >= 0);
if (CurrentItem <= 0)
{
CurrentItem = 0;
// Fix, to make sure no invalid values are sent.
// WARNING: HERE ITS 0, BUT IN EQUIP PACKET ITS -1 !!
}
AppendByte (a_Data, m_PacketID);
AppendInteger (a_Data, m_UniqueID);
AppendString16(a_Data, m_PlayerName);
AppendInteger (a_Data, m_PosX);
AppendInteger (a_Data, m_PosY);
AppendInteger (a_Data, m_PosZ);
AppendByte (a_Data, m_Rotation);
AppendByte (a_Data, m_Pitch);
AppendShort (a_Data, CurrentItem);
}

View File

@ -1,40 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_NamedEntitySpawn : public cPacket
{
public:
cPacket_NamedEntitySpawn()
: m_UniqueID( 0 )
, m_PosX( 0 )
, m_PosY( 0 )
, m_PosZ( 0 )
, m_Rotation( 0 )
, m_Pitch( 0 )
, m_CurrentItem( 0 )
{ m_PacketID = E_NAMED_ENTITY_SPAWN; }
virtual cPacket* Clone() const { return new cPacket_NamedEntitySpawn(*this); }
virtual void Serialize(AString & a_Data) const override;
int m_UniqueID;
AString m_PlayerName;
int m_PosX; // Pixel position, devide by 32 for block position
int m_PosY;
int m_PosZ;
char m_Rotation;
char m_Pitch;
short m_CurrentItem;
static const unsigned int c_Size = 1 + 4 + 2 + 4 + 4 + 4 + 1 + 1 + 2; // Minimum size
};

View File

@ -1,42 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_NewInvalidState.h"
cPacket_NewInvalidState::cPacket_NewInvalidState( const cPacket_NewInvalidState & a_Copy )
{
m_PacketID = E_NEW_INVALID_STATE;
m_Reason = a_Copy.m_Reason;
m_GameMode = a_Copy.m_GameMode;
}
int cPacket_NewInvalidState::Parse(cByteBuffer & a_Buffer)
{
int TotalBytes = 0;
HANDLE_PACKET_READ(ReadChar, m_Reason, TotalBytes);
HANDLE_PACKET_READ(ReadChar, m_GameMode, TotalBytes);
return TotalBytes;
}
void cPacket_NewInvalidState::Serialize(AString & a_Data) const
{
AppendByte(a_Data, m_PacketID);
AppendByte(a_Data, m_Reason);
AppendByte(a_Data, m_GameMode);
}

View File

@ -1,31 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_NewInvalidState : public cPacket
{
public:
cPacket_NewInvalidState()
: m_Reason( 0 )
, m_GameMode( 0 )
{ m_PacketID = E_NEW_INVALID_STATE;}
cPacket_NewInvalidState( const cPacket_NewInvalidState & a_Copy );
virtual cPacket* Clone() const { return new cPacket_NewInvalidState(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
char m_Reason; // 0 = Invalid Bed, 1 = Begin Raining, 2 End Raining, 3 = Change Gamemode
char m_GameMode; // Used only when reason = 3. 0 is survival, 1 is creative.
static const unsigned int c_Size = 1 + 1 + 1;
};

View File

@ -1,47 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_PickupSpawn.h"
int cPacket_PickupSpawn::Parse(cByteBuffer & a_Buffer)
{
int TotalBytes = 0;
HANDLE_PACKET_READ(ReadBEInt, m_UniqueID, TotalBytes);
HANDLE_PACKET_READ(ReadBEShort, m_ItemType, TotalBytes);
HANDLE_PACKET_READ(ReadChar, m_ItemCount, TotalBytes);
HANDLE_PACKET_READ(ReadBEShort, m_ItemDamage, TotalBytes);
HANDLE_PACKET_READ(ReadBEInt, m_PosX, TotalBytes);
HANDLE_PACKET_READ(ReadBEInt, m_PosY, TotalBytes);
HANDLE_PACKET_READ(ReadBEInt, m_PosZ, TotalBytes);
HANDLE_PACKET_READ(ReadChar, m_Rotation, TotalBytes);
HANDLE_PACKET_READ(ReadChar, m_Pitch, TotalBytes);
HANDLE_PACKET_READ(ReadChar, m_Roll, TotalBytes);
return TotalBytes;
}
void cPacket_PickupSpawn::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_UniqueID);
AppendShort (a_Data, m_ItemType);
AppendByte (a_Data, m_ItemCount);
AppendShort (a_Data, m_ItemDamage);
AppendInteger(a_Data, m_PosX);
AppendInteger(a_Data, m_PosY);
AppendInteger(a_Data, m_PosZ);
AppendByte (a_Data, m_Rotation);
AppendByte (a_Data, m_Pitch);
AppendByte (a_Data, m_Roll);
}

View File

@ -1,47 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_PickupSpawn : public cPacket
{
public:
cPacket_PickupSpawn()
: m_UniqueID( 0 )
, m_ItemType( 0 )
, m_ItemCount( 0 )
, m_ItemDamage( 0 )
, m_PosX( 0 )
, m_PosY( 0 )
, m_PosZ( 0 )
, m_Rotation( 0 )
, m_Pitch( 0 )
, m_Roll( 0 )
{
m_PacketID = E_PICKUP_SPAWN;
}
virtual cPacket* Clone() const { return new cPacket_PickupSpawn(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
int m_UniqueID;
short m_ItemType;
char m_ItemCount;
short m_ItemDamage;
int m_PosX;
int m_PosY;
int m_PosZ;
char m_Rotation;
char m_Pitch;
char m_Roll;
};

View File

@ -36,21 +36,6 @@ int cPacket_PlayerAbilities::Parse(cByteBuffer & a_Buffer)
void cPacket_PlayerAbilities::Serialize(AString & a_Data) const
{
char Data[5];
Data[0] = m_PacketID;
Data[1] = (char)m_Invulnerable;
Data[2] = (char)m_IsFlying;
Data[3] = (char)m_CanFly;
Data[4] = (char)m_InstaMine;
a_Data.append(Data, 5);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cPacket_PlayerListItem:
@ -79,28 +64,6 @@ int cPacket_PlayerListItem::Parse(cByteBuffer & a_Buffer)
void cPacket_PlayerListItem::Serialize(AString & a_Data) const
{
AString PlayerName(m_PlayerName);
if (PlayerName.length() > 16)
{
PlayerName.erase(16);
}
else if (PlayerName.length() <= 14)
{
PlayerName += cChatColor::White;
}
AppendByte (a_Data, m_PacketID);
AppendString16(a_Data, PlayerName);
AppendBool (a_Data, m_Online);
AppendShort (a_Data, m_Ping);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cPacket_PlayerLook:
@ -129,17 +92,6 @@ int cPacket_PlayerLook::Parse(cByteBuffer & a_Buffer)
void cPacket_PlayerLook::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendFloat (a_Data, m_Rotation);
AppendFloat (a_Data, m_Pitch);
AppendBool (a_Data, m_IsOnGround);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cPacket_PlayerMoveLook:
@ -179,26 +131,6 @@ int cPacket_PlayerMoveLook::Parse(cByteBuffer & a_Buffer)
void cPacket_PlayerMoveLook::Serialize(AString & a_Data) const
{
// NOTE that Stance and Y are swapped when sent C->S vs S->C
// This is the S->C case:
// LOGD("Send PML: {%0.2f, %0.2f, %0.2f}, Stance: %0.2f, Gnd: %d", m_PosX, m_PosY, m_PosZ, m_Stance, m_IsOnGround ? 1 : 0);
AppendByte (a_Data, m_PacketID);
AppendDouble(a_Data, m_PosX);
AppendDouble(a_Data, m_Stance);
AppendDouble(a_Data, m_PosY);
AppendDouble(a_Data, m_PosZ);
AppendFloat (a_Data, m_Rotation);
AppendFloat (a_Data, m_Pitch);
AppendBool (a_Data, m_IsOnGround);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cPacket_PlayerPosition:
@ -232,22 +164,3 @@ int cPacket_PlayerPosition::Parse(cByteBuffer & a_Buffer)
void cPacket_PlayerPosition::Serialize(AString & a_Data) const
{
LOGD("Ignore send PlayerPos");
/*
LOGD("Send PlayerPos: {%0.2f %0.2f %0.2f}, Stance %0.2f, Gnd: %d", m_PosX, m_PosY, m_PosZ, m_Stance, m_IsOnGround ? 1 : 0);
// _X: This should not get sent to the client at all - http://wiki.vg/wiki/index.php?title=Protocol&oldid=2513#Player_Position_.280x0B.29
AppendByte (a_Data, m_PacketID);
AppendDouble (a_Data, m_PosX);
AppendDouble (a_Data, m_PosY);
AppendDouble (a_Data, m_Stance);
AppendDouble (a_Data, m_PosZ);
AppendBool (a_Data, m_IsOnGround);
*/
}

View File

@ -34,7 +34,6 @@ public:
cPacket_PlayerAbilities(void) { m_PacketID = E_PLAYER_LIST_ITEM; }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
virtual cPacket * Clone() const { return new cPacket_PlayerAbilities(*this); }
@ -55,7 +54,6 @@ public:
cPacket_PlayerListItem(const AString & a_PlayerName, bool a_Online, short a_Ping);
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
virtual cPacket* Clone() const { return new cPacket_PlayerListItem(*this); }
@ -83,7 +81,6 @@ public:
virtual cPacket* Clone() const { return new cPacket_PlayerLook(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
float m_Rotation;
float m_Pitch;
@ -112,8 +109,7 @@ public:
cPacket_PlayerMoveLook(const cPlayer & a_Player);
virtual cPacket * Clone() const { return new cPacket_PlayerMoveLook(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
virtual int Parse(cByteBuffer & a_Buffer) override;
double m_PosX;
double m_PosY;
@ -142,7 +138,6 @@ public:
virtual cPacket* Clone() const { return new cPacket_PlayerPosition(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
double m_PosX;
double m_PosY;

View File

@ -1,20 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_PreChunk.h"
void cPacket_PreChunk::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_PosX);
AppendInteger(a_Data, m_PosZ);
AppendBool (a_Data, m_bLoad);
}

View File

@ -1,36 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_PreChunk: public cPacket
{
public:
cPacket_PreChunk()
: m_PosX( 0 )
, m_PosZ( 0 )
, m_bLoad( false )
{ m_PacketID = E_PRE_CHUNK; }
cPacket_PreChunk( int a_PosX, int a_PosZ, bool a_bLoad )
: m_PosX( a_PosX )
, m_PosZ( a_PosZ )
, m_bLoad( a_bLoad )
{ m_PacketID = E_PRE_CHUNK; }
virtual cPacket* Clone() const { return new cPacket_PreChunk(*this); }
virtual void Serialize(AString & a_Data) const override;
int m_PosX;
int m_PosZ;
bool m_bLoad;
static const unsigned int c_Size = 10;
};

View File

@ -1,21 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_RelativeEntityMove.h"
void cPacket_RelativeEntityMove::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_UniqueID);
AppendByte (a_Data, m_MoveX);
AppendByte (a_Data, m_MoveY);
AppendByte (a_Data, m_MoveZ);
}

View File

@ -1,33 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_RelativeEntityMove : public cPacket
{
public:
cPacket_RelativeEntityMove()
: m_UniqueID( 0 )
, m_MoveX( 0 )
, m_MoveY( 0 )
, m_MoveZ( 0 )
{ m_PacketID = E_REL_ENT_MOVE; }
virtual cPacket* Clone() const { return new cPacket_RelativeEntityMove(*this); }
virtual void Serialize(AString & a_Data) const override;
int m_UniqueID;
char m_MoveX; // Pixels, devide by 32 for block
char m_MoveY;
char m_MoveZ;
static const unsigned int c_Size = 1 + 4 + 1 + 1 + 1;
};

View File

@ -1,24 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_RelativeEntityMoveLook.h"
void cPacket_RelativeEntityMoveLook::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_UniqueID);
AppendByte (a_Data, m_MoveX);
AppendByte (a_Data, m_MoveY);
AppendByte (a_Data, m_MoveZ);
AppendByte (a_Data, m_Yaw);
AppendByte (a_Data, m_Pitch);
}

View File

@ -1,37 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_RelativeEntityMoveLook : public cPacket
{
public:
cPacket_RelativeEntityMoveLook()
: m_UniqueID( 0 )
, m_MoveX( 0 )
, m_MoveY( 0 )
, m_MoveZ( 0 )
, m_Yaw( 0 )
, m_Pitch( 0 )
{ m_PacketID = E_REL_ENT_MOVE_LOOK; }
virtual cPacket* Clone() const { return new cPacket_RelativeEntityMoveLook(*this); }
virtual void Serialize(AString & a_Data) const override;
int m_UniqueID;
char m_MoveX; // Pixels, divide by 32 for block
char m_MoveY;
char m_MoveZ;
char m_Yaw;
char m_Pitch;
static const unsigned int c_Size = 1 + 4 + 1 + 1 + 1 + 1 + 1;
};

View File

@ -7,21 +7,6 @@
void cPacket_Respawn::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger (a_Data, m_Dimension);
AppendByte (a_Data, m_Difficulty);
AppendByte (a_Data, m_CreativeMode);
AppendShort (a_Data, m_WorldHeight);
AppendString16(a_Data, m_LevelType);
}
int cPacket_Respawn::Parse(cByteBuffer & a_Buffer)
{
int TotalBytes = 0;

View File

@ -2,7 +2,6 @@
#pragma once
#include "cPacket.h"
#include "cPacket_Login.h"
@ -25,8 +24,7 @@ public:
virtual cPacket * Clone() const { return new cPacket_Respawn( *this ); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
virtual int Parse(cByteBuffer & a_Buffer) override;
int m_Dimension;
char m_Difficulty;

View File

@ -1,71 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_SpawnMob.h"
#include "../Vector3i.h"
cPacket_SpawnMob::~cPacket_SpawnMob()
{
if( m_MetaData ) delete [] m_MetaData;
}
cPacket_SpawnMob::cPacket_SpawnMob()
: m_UniqueID( 0 )
, m_Type( 0 )
, m_Yaw( 0 )
, m_Pitch( 0 )
, m_MetaDataSize( 0 )
, m_MetaData( 0 )
, m_HeadYaw(0)
{
m_PacketID = E_SPAWN_MOB;
}
cPacket_SpawnMob::cPacket_SpawnMob( const cPacket_SpawnMob & a_Clone )
{
m_PacketID = E_SPAWN_MOB;
m_UniqueID = a_Clone.m_UniqueID;
m_Type = a_Clone.m_Type;
m_Pos = a_Clone.m_Pos;
m_Yaw = a_Clone.m_Yaw;
m_Pitch = a_Clone.m_Pitch;
m_HeadYaw = a_Clone.m_HeadYaw;
m_MetaDataSize = a_Clone.m_MetaDataSize;
m_MetaData = new char[m_MetaDataSize];
memcpy( m_MetaData, a_Clone.m_MetaData, sizeof( char ) * m_MetaDataSize );
}
void cPacket_SpawnMob::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger (a_Data, m_UniqueID);
AppendByte (a_Data, m_Type);
AppendInteger (a_Data, m_Pos.x);
AppendInteger (a_Data, m_Pos.y);
AppendInteger (a_Data, m_Pos.z);
AppendByte (a_Data, m_Yaw);
AppendByte (a_Data, m_Pitch);
AppendByte (a_Data, m_HeadYaw);
AppendData (a_Data, m_MetaData, m_MetaDataSize);
}

View File

@ -1,35 +0,0 @@
#pragma once
#include "cPacket.h"
#include "../Vector3i.h"
class cPacket_SpawnMob :
public cPacket
{
public:
cPacket_SpawnMob();
cPacket_SpawnMob( const cPacket_SpawnMob & a_Clone );
virtual cPacket* Clone() const { return new cPacket_SpawnMob( *this ); }
~cPacket_SpawnMob();
virtual void Serialize(AString & a_Data) const override;
int m_UniqueID;
char m_Type;
Vector3i m_Pos;
char m_Yaw;
char m_Pitch;
char m_HeadYaw;
unsigned int m_MetaDataSize;
char * m_MetaData;
};

View File

@ -1,41 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_TeleportEntity.h"
#include "../cEntity.h"
cPacket_TeleportEntity::cPacket_TeleportEntity(const cEntity & a_Entity)
{
m_PacketID = E_ENT_TELEPORT;
m_UniqueID = a_Entity.GetUniqueID();
m_PosX = (int)(a_Entity.GetPosX() * 32);
m_PosY = (int)(a_Entity.GetPosY() * 32);
m_PosZ = (int)(a_Entity.GetPosZ() * 32);
m_Rotation = (char)((a_Entity.GetRotation() / 360.f) * 256);
m_Pitch = (char)((a_Entity.GetPitch() / 360.f) * 256);
}
void cPacket_TeleportEntity::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger(a_Data, m_UniqueID);
AppendInteger(a_Data, m_PosX);
AppendInteger(a_Data, m_PosY);
AppendInteger(a_Data, m_PosZ);
AppendByte (a_Data, m_Rotation);
AppendByte (a_Data, m_Pitch);
}

View File

@ -1,42 +0,0 @@
#pragma once
#include "cPacket.h"
class cEntity;
class cPacket_TeleportEntity : public cPacket
{
public:
cPacket_TeleportEntity()
: m_UniqueID( 0 )
, m_PosX( 0 )
, m_PosY( 0 )
, m_PosZ( 0 )
, m_Rotation( 0 )
, m_Pitch( 0 )
{
m_PacketID = E_ENT_TELEPORT;
}
virtual cPacket * Clone() const { return new cPacket_TeleportEntity(*this); }
cPacket_TeleportEntity(const cEntity & a_Entity);
virtual void Serialize(AString & a_Data) const override;
int m_UniqueID;
int m_PosX; // Pixel position, divide by 32 for block position
int m_PosY;
int m_PosZ;
char m_Rotation;
char m_Pitch;
static const unsigned int c_Size = 1 + 4 + 4 + 4 + 4 + 1 + 1;
};

View File

@ -1,36 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_Thunderbolt.h"
cPacket_Thunderbolt::cPacket_Thunderbolt( const cPacket_Thunderbolt & a_Copy )
{
m_PacketID = E_THUNDERBOLT;
m_UniqueID = 237183; //just a random Ent ID. I don't think this matters at all.
m_Unknown = true;
m_xLBPos = a_Copy.m_xLBPos;
m_yLBPos = a_Copy.m_yLBPos;
m_zLBPos = a_Copy.m_zLBPos;
}
void cPacket_Thunderbolt::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger (a_Data, m_UniqueID);
AppendBool (a_Data, m_Unknown);
AppendInteger (a_Data, m_xLBPos * 32);
AppendInteger (a_Data, m_yLBPos * 32);
AppendInteger (a_Data, m_zLBPos * 32);
}

View File

@ -1,36 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_Thunderbolt : public cPacket
{
public:
cPacket_Thunderbolt()
: m_UniqueID( 0 )
, m_Unknown( 0 )
, m_xLBPos( 0 )
, m_yLBPos( 0 )
, m_zLBPos( 0 )
{ m_PacketID = E_THUNDERBOLT; m_Unknown = true; }
cPacket_Thunderbolt( const cPacket_Thunderbolt & a_Copy );
virtual cPacket* Clone() const { return new cPacket_Thunderbolt(*this); }
virtual void Serialize(AString & a_Data) const override;
int m_UniqueID; // The entity ID of the thunderbolt
bool m_Unknown; // Always true. Might have a meaning in the future...
int m_xLBPos; // Thunderbolt X as Absolute Integer
int m_yLBPos; // Thunderbolt Y as Absolute Integer
int m_zLBPos; // Thunderbolt Z as Absolute Integer
static const unsigned int c_Size = 1 + 4 + 1 + 4 + 4 + 4;
};

View File

@ -1,29 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_TimeUpdate.h"
int cPacket_TimeUpdate::Parse(cByteBuffer & a_Buffer)
{
int TotalBytes = 0;
HANDLE_PACKET_READ(ReadBEInt64, m_Time, TotalBytes);
return TotalBytes;
}
void cPacket_TimeUpdate::Serialize(AString & a_Data) const
{
AppendByte(a_Data, m_PacketID);
AppendLong(a_Data, m_Time);
}

View File

@ -1,29 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_TimeUpdate : public cPacket
{
public:
cPacket_TimeUpdate()
: m_Time( 0 )
{ m_PacketID = E_UPDATE_TIME; }
cPacket_TimeUpdate( long long a_Time ) { m_PacketID = E_UPDATE_TIME; m_Time = a_Time; }
virtual cPacket* Clone() const { return new cPacket_TimeUpdate(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
long long m_Time;
static const unsigned int c_Size = 1 + 8;
};

View File

@ -1,20 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_UpdateHealth.h"
void cPacket_UpdateHealth::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendShort(a_Data, m_Health);
AppendShort(a_Data, m_Food);
AppendFloat(a_Data, m_Saturation);
}

View File

@ -1,32 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_UpdateHealth : public cPacket
{
public:
cPacket_UpdateHealth()
: m_Health( 0 )
, m_Food( 0 )
, m_Saturation( 0.f )
{ m_PacketID = E_UPDATE_HEALTH; }
cPacket_UpdateHealth( short a_Health ) { m_Health = a_Health; m_PacketID = E_UPDATE_HEALTH; }
virtual cPacket* Clone() const { return new cPacket_UpdateHealth( *this ); }
virtual void Serialize(AString & a_Data) const override;
short m_Health;
short m_Food;
float m_Saturation;
static const unsigned int c_Size = 1 + 2 + 2 + 4;
};

View File

@ -23,19 +23,3 @@ int cPacket_UpdateSign::Parse(cByteBuffer & a_Buffer)
void cPacket_UpdateSign::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendInteger (a_Data, m_BlockX);
AppendShort (a_Data, m_BlockY);
AppendInteger (a_Data, m_BlockZ);
AppendString16(a_Data, m_Line1);
AppendString16(a_Data, m_Line2);
AppendString16(a_Data, m_Line3);
AppendString16(a_Data, m_Line4);
}

View File

@ -21,7 +21,6 @@ public:
virtual cPacket * Clone() const { return new cPacket_UpdateSign( *this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
int m_BlockX;
short m_BlockY;

View File

@ -1,80 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_WholeInventory.h"
#include "../cItem.h"
#include "../cInventory.h"
#include "../cWindow.h"
#include "cPacket_ItemData.h"
cPacket_WholeInventory::cPacket_WholeInventory( const cPacket_WholeInventory & a_Clone )
{
m_PacketID = E_INVENTORY_WHOLE;
m_WindowID = a_Clone.m_WindowID;
m_Count = a_Clone.m_Count;
m_Items = new cItem[m_Count];
// TODO: copy items one by one, they may have some values that needn't be shallow-copiable
memcpy(m_Items, a_Clone.m_Items, sizeof(cItem) * m_Count);
}
cPacket_WholeInventory::cPacket_WholeInventory(const cInventory & a_Inventory)
{
m_PacketID = E_INVENTORY_WHOLE;
m_WindowID = 0; // Inventory window has a constant ID of 0
m_Count = a_Inventory.c_NumSlots;
m_Items = new cItem[m_Count];
// TODO: copy items one by one, they may have some values that needn't be shallow-copiable
memcpy( m_Items, a_Inventory.GetSlots(), sizeof(cItem) * m_Count);
}
cPacket_WholeInventory::cPacket_WholeInventory(const cWindow & a_Window)
{
m_PacketID = E_INVENTORY_WHOLE;
m_WindowID = (char)a_Window.GetWindowID();
m_Count = (short)a_Window.GetNumSlots();
m_Items = new cItem[m_Count];
// TODO: copy items one by one, they may have some values that needn't be shallow-copiable
memcpy( m_Items, a_Window.GetSlots(), sizeof(cItem) * m_Count);
}
cPacket_WholeInventory::~cPacket_WholeInventory()
{
delete [] m_Items;
}
void cPacket_WholeInventory::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendByte (a_Data, m_WindowID);
AppendShort(a_Data, m_Count);
for (int j = 0; j < m_Count; j++)
{
cPacket_ItemData::AppendItem(a_Data, m_Items[j]);
}
}

View File

@ -1,47 +0,0 @@
#pragma once
#include "cPacket.h"
#include "../BlockID.h"
class cInventory;
class cWindow;
class cItem;
class cPacket_WholeInventory :
public cPacket // full inventory [S -> C] ?
{
public:
cPacket_WholeInventory(const cPacket_WholeInventory & a_Clone);
cPacket_WholeInventory(const cInventory & a_Inventory);
cPacket_WholeInventory(const cWindow & a_Window);
~cPacket_WholeInventory();
cPacket_WholeInventory()
: m_WindowID( 0 )
, m_Count( 0 )
, m_Items( 0 )
{
m_PacketID = E_INVENTORY_WHOLE;
}
virtual cPacket * Clone() const { return new cPacket_WholeInventory(*this); }
virtual void Serialize(AString & a_Data) const override;
char m_WindowID;
short m_Count;
cItem * m_Items;
};

View File

@ -2,7 +2,6 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_WindowClick.h"
#include "cPacket_WholeInventory.h"
#include "cPacket_ItemData.h"

View File

@ -17,13 +17,3 @@ int cPacket_WindowClose::Parse(cByteBuffer & a_Buffer)
void cPacket_WindowClose::Serialize(AString & a_Data) const
{
AppendByte(a_Data, m_PacketID);
AppendByte(a_Data, m_WindowID);
}

View File

@ -18,8 +18,7 @@ public:
virtual cPacket* Clone() const { return new cPacket_WindowClose(*this); }
virtual int Parse(cByteBuffer & a_Buffer) override;
virtual void Serialize(AString & a_Data) const override;
virtual int Parse(cByteBuffer & a_Buffer) override;
char m_WindowID;
};

View File

@ -1,21 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPacket_WindowOpen.h"
void cPacket_WindowOpen::Serialize(AString & a_Data) const
{
AppendByte (a_Data, m_PacketID);
AppendByte (a_Data, m_WindowID);
AppendByte (a_Data, m_InventoryType);
AppendString16(a_Data, m_WindowTitle);
AppendByte (a_Data, m_NumSlots);
}

View File

@ -1,32 +0,0 @@
#pragma once
#include "cPacket.h"
class cPacket_WindowOpen : public cPacket
{
public:
cPacket_WindowOpen()
: m_WindowID( 0 )
, m_InventoryType( 0 )
, m_NumSlots( 0 )
{ m_PacketID = E_WINDOW_OPEN; }
virtual cPacket* Clone() const { return new cPacket_WindowOpen(*this); }
virtual void Serialize(AString & a_Data) const override;
char m_WindowID;
char m_InventoryType;
AString m_WindowTitle;
char m_NumSlots;
static const unsigned int c_Size = 1 + 1 + 1 + 2 + 1; // + sizeof(string)
};