summaryrefslogtreecommitdiffstats
path: root/source/packets
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/packets/cPacket.cpp223
-rw-r--r--source/packets/cPacket.h56
-rw-r--r--source/packets/cPacket_13.cpp10
-rw-r--r--source/packets/cPacket_13.h30
-rw-r--r--source/packets/cPacket_AddToInventory.cpp17
-rw-r--r--source/packets/cPacket_AddToInventory.h23
-rw-r--r--source/packets/cPacket_ArmAnim.cpp24
-rw-r--r--source/packets/cPacket_ArmAnim.h21
-rw-r--r--source/packets/cPacket_BlockChange.cpp19
-rw-r--r--source/packets/cPacket_BlockChange.h26
-rw-r--r--source/packets/cPacket_BlockDig.cpp29
-rw-r--r--source/packets/cPacket_BlockDig.h27
-rw-r--r--source/packets/cPacket_BlockPlace.cpp18
-rw-r--r--source/packets/cPacket_BlockPlace.h32
-rw-r--r--source/packets/cPacket_Chat.cpp23
-rw-r--r--source/packets/cPacket_Chat.h18
-rw-r--r--source/packets/cPacket_CollectItem.cpp16
-rw-r--r--source/packets/cPacket_CollectItem.h20
-rw-r--r--source/packets/cPacket_DestroyEntity.cpp23
-rw-r--r--source/packets/cPacket_DestroyEntity.h20
-rw-r--r--source/packets/cPacket_Disconnect.cpp22
-rw-r--r--source/packets/cPacket_Disconnect.h18
-rw-r--r--source/packets/cPacket_EntityEquipment.cpp42
-rw-r--r--source/packets/cPacket_EntityEquipment.h27
-rw-r--r--source/packets/cPacket_EntityLook.cpp28
-rw-r--r--source/packets/cPacket_EntityLook.h25
-rw-r--r--source/packets/cPacket_EntityStatus.cpp17
-rw-r--r--source/packets/cPacket_EntityStatus.h24
-rw-r--r--source/packets/cPacket_Flying.cpp8
-rw-r--r--source/packets/cPacket_Flying.h19
-rw-r--r--source/packets/cPacket_Handshake.cpp24
-rw-r--r--source/packets/cPacket_Handshake.h17
-rw-r--r--source/packets/cPacket_InventoryProgressBar.cpp18
-rw-r--r--source/packets/cPacket_InventoryProgressBar.h23
-rw-r--r--source/packets/cPacket_InventorySlot.cpp23
-rw-r--r--source/packets/cPacket_InventorySlot.h34
-rw-r--r--source/packets/cPacket_ItemSwitch.cpp23
-rw-r--r--source/packets/cPacket_ItemSwitch.h19
-rw-r--r--source/packets/cPacket_KeepAlive.cpp22
-rw-r--r--source/packets/cPacket_KeepAlive.h18
-rw-r--r--source/packets/cPacket_Login.cpp41
-rw-r--r--source/packets/cPacket_Login.h33
-rw-r--r--source/packets/cPacket_MapChunk.cpp69
-rw-r--r--source/packets/cPacket_MapChunk.h37
-rw-r--r--source/packets/cPacket_Metadata.cpp65
-rw-r--r--source/packets/cPacket_Metadata.h23
-rw-r--r--source/packets/cPacket_MultiBlock.cpp42
-rw-r--r--source/packets/cPacket_MultiBlock.h32
-rw-r--r--source/packets/cPacket_NamedEntitySpawn.cpp26
-rw-r--r--source/packets/cPacket_NamedEntitySpawn.h32
-rw-r--r--source/packets/cPacket_PickupSpawn.cpp40
-rw-r--r--source/packets/cPacket_PickupSpawn.h38
-rw-r--r--source/packets/cPacket_Ping.h16
-rw-r--r--source/packets/cPacket_PlayerLook.cpp36
-rw-r--r--source/packets/cPacket_PlayerLook.h25
-rw-r--r--source/packets/cPacket_PlayerMoveLook.cpp50
-rw-r--r--source/packets/cPacket_PlayerMoveLook.h33
-rw-r--r--source/packets/cPacket_PlayerPosition.cpp42
-rw-r--r--source/packets/cPacket_PlayerPosition.h29
-rw-r--r--source/packets/cPacket_PreChunk.cpp17
-rw-r--r--source/packets/cPacket_PreChunk.h22
-rw-r--r--source/packets/cPacket_RelativeEntityMove.cpp18
-rw-r--r--source/packets/cPacket_RelativeEntityMove.h25
-rw-r--r--source/packets/cPacket_RelativeEntityMoveLook.cpp20
-rw-r--r--source/packets/cPacket_RelativeEntityMoveLook.h29
-rw-r--r--source/packets/cPacket_Respawn.cpp31
-rw-r--r--source/packets/cPacket_Respawn.h28
-rw-r--r--source/packets/cPacket_SpawnMob.cpp60
-rw-r--r--source/packets/cPacket_SpawnMob.h27
-rw-r--r--source/packets/cPacket_TeleportEntity.cpp34
-rw-r--r--source/packets/cPacket_TeleportEntity.h31
-rw-r--r--source/packets/cPacket_TimeUpdate.cpp22
-rw-r--r--source/packets/cPacket_TimeUpdate.h20
-rw-r--r--source/packets/cPacket_UpdateHealth.cpp20
-rw-r--r--source/packets/cPacket_UpdateHealth.h24
-rw-r--r--source/packets/cPacket_UpdateSign.cpp41
-rw-r--r--source/packets/cPacket_UpdateSign.h28
-rw-r--r--source/packets/cPacket_UseEntity.cpp10
-rw-r--r--source/packets/cPacket_UseEntity.h23
-rw-r--r--source/packets/cPacket_WholeInventory.cpp68
-rw-r--r--source/packets/cPacket_WholeInventory.h31
-rw-r--r--source/packets/cPacket_WindowClick.cpp36
-rw-r--r--source/packets/cPacket_WindowClick.h41
-rw-r--r--source/packets/cPacket_WindowClose.cpp27
-rw-r--r--source/packets/cPacket_WindowClose.h20
-rw-r--r--source/packets/cPacket_WindowOpen.cpp18
-rw-r--r--source/packets/cPacket_WindowOpen.h24
87 files changed, 2630 insertions, 0 deletions
diff --git a/source/packets/cPacket.cpp b/source/packets/cPacket.cpp
new file mode 100644
index 000000000..e49c3e016
--- /dev/null
+++ b/source/packets/cPacket.cpp
@@ -0,0 +1,223 @@
+#include "cPacket.h"
+#include "cMCLogger.h"
+#include "Endianness.h"
+
+#ifdef _WIN32
+#define MSG_NOSIGNAL (0)
+#endif
+
+#ifdef __MAC_NA
+#define MSG_NOSIGNAL (0)
+#endif
+
+//*****************************************************************************
+// Blocking receive all function
+//*****************************************************************************
+int cPacket::RecvAll( SOCKET a_Socket, char* a_Data, unsigned int a_Size, int a_Options )
+{
+ unsigned int RequestSize = a_Size;
+ while(a_Size != 0)
+ {
+ int Num = recv(a_Socket, a_Data, a_Size, a_Options);
+ if( cSocket::IsSocketError( Num ) )
+ return Num;
+ a_Size -= Num;
+ a_Data += Num;
+ }
+ return RequestSize - a_Size;
+}
+
+//*****************************************************************************
+// Own implementation of send()
+//*****************************************************************************
+int cPacket::SendData( SOCKET a_Socket, const char* a_Message, unsigned int a_Size, int a_Options )
+{
+ return send(a_Socket, a_Message, a_Size, a_Options | MSG_NOSIGNAL );
+}
+
+
+//*****************************************************************************
+// New packets
+//*****************************************************************************
+
+bool cPacket::ReadString( std::string & a_OutString )
+{
+ short StrLen;
+ if(!ReadShort( StrLen )) return false;
+
+ if( StrLen == 0 )
+ {
+ a_OutString.clear();
+ return true;
+ }
+
+ char* cString = new char[StrLen];
+ if( cSocket::IsSocketError( RecvAll( m_Socket, cString, StrLen, 0 ) ) ) return false;
+
+ a_OutString.assign( cString, StrLen );
+
+ //printf("Discoved string: %s size: %i\n", a_OutString.c_str(), a_OutString.size() );
+ delete [] cString;
+ return true;
+}
+
+bool cPacket::ReadString16( std::string & a_OutString )
+{
+ short StrLen;
+ if(!ReadShort( StrLen )) return false;
+
+ a_OutString.clear();
+ if( StrLen == 0 )
+ {
+ return true;
+ }
+
+ char* UTF16 = new char[StrLen*sizeof( short )];
+ if( cSocket::IsSocketError( RecvAll( m_Socket, UTF16, StrLen * sizeof( short ), 0 ) ) ) return false;
+
+ for( int i = 0; i < StrLen; ++i )
+ a_OutString.push_back( (char)UTF16[i*sizeof( short )+1] );
+
+ //printf("Discoved string: %s size: %i\n", a_OutString.c_str(), a_OutString.size() );
+ delete [] UTF16;
+ return true;
+}
+
+bool cPacket::ReadShort( short & a_OutShort )
+{
+ if( cSocket::IsSocketError( RecvAll( m_Socket, (char*)&a_OutShort, sizeof(short), 0 ) ) ) return false;
+ a_OutShort = ntohs(a_OutShort);
+ return true;
+}
+
+bool cPacket::ReadInteger( int & a_OutInteger )
+{
+ if( cSocket::IsSocketError( RecvAll( m_Socket, (char*)&a_OutInteger, sizeof(int), 0 ) ) ) return false;
+ a_OutInteger = ntohl(a_OutInteger);
+ return true;
+}
+
+bool cPacket::ReadInteger( unsigned int & a_OutInteger )
+{
+ if( cSocket::IsSocketError( RecvAll( m_Socket, (char*)&a_OutInteger, sizeof(unsigned int), 0 ) ) ) return false;
+ a_OutInteger = ntohl(a_OutInteger);
+ return true;
+}
+
+bool cPacket::ReadFloat( float & a_OutFloat )
+{
+ if( cSocket::IsSocketError( RecvAll( m_Socket, (char*)&a_OutFloat, sizeof(float), 0 ) ) ) return false;
+ a_OutFloat = NetworkToHostFloat4( &a_OutFloat );
+ return true;
+}
+
+bool cPacket::ReadDouble( double & a_OutDouble )
+{
+ if( cSocket::IsSocketError( RecvAll( m_Socket, (char*)&a_OutDouble, sizeof(double), 0 ) ) ) return false;
+ a_OutDouble = NetworkToHostDouble8( &a_OutDouble );
+ return true;
+}
+
+bool cPacket::ReadByte( char & a_OutByte )
+{
+ return !cSocket::IsSocketError( RecvAll( m_Socket, (char*)&a_OutByte, sizeof(char), 0 ) );
+}
+
+bool cPacket::ReadByte( unsigned char & a_OutByte )
+{
+ return !cSocket::IsSocketError(RecvAll( m_Socket, (char*)&a_OutByte, sizeof(char), 0 ) );
+}
+
+bool cPacket::ReadLong( long long & a_OutLong )
+{
+ if( cSocket::IsSocketError( RecvAll( m_Socket, (char*)&a_OutLong, sizeof(long long), 0 ) ) ) return false;
+ a_OutLong = NetworkToHostLong8( &a_OutLong );
+ return true;
+}
+
+bool cPacket::ReadBool( bool & a_OutBool )
+{
+ if( cSocket::IsSocketError(RecvAll( m_Socket, (char*)&a_OutBool, sizeof(bool), 0 ) ) ) return false;
+ return true;
+}
+
+//*****************************************************************************
+// Append variables to a c-String
+//*****************************************************************************
+void cPacket::AppendString( std::string & a_String, char* a_Dst, unsigned int & a_Iterator )
+{
+ AppendShort( (unsigned short)a_String.size(), a_Dst, a_Iterator );
+ memcpy( a_Dst + a_Iterator, a_String.c_str(), a_String.size() ); a_Iterator += a_String.size();
+}
+
+void cPacket::AppendString16( std::string & a_String, char* a_Dst, unsigned int & a_Iterator )
+{
+ AppendShort( (unsigned short)a_String.size(), a_Dst, a_Iterator );
+ char* UTF16 = new char[ a_String.size() * sizeof( short ) ];
+ for( unsigned int i = 0; i < a_String.size(); ++i )
+ {
+ UTF16[i*sizeof( short )] = 0x00;//a_String[i];
+ UTF16[i*sizeof( short )+1] = a_String[i];
+ }
+ memcpy( a_Dst + a_Iterator, UTF16, a_String.size() * sizeof( short ) ); a_Iterator += a_String.size() * sizeof( short );
+ delete [] UTF16;
+}
+
+void cPacket::AppendShort( short a_Short, char *a_Dst, unsigned int &a_Iterator )
+{
+ short ConvertedShort = htons( a_Short );
+ memcpy( a_Dst + a_Iterator, &ConvertedShort, sizeof( short ) ); a_Iterator+=sizeof( short );
+}
+
+void cPacket::AppendShort( unsigned short a_Short, char *a_Dst, unsigned int &a_Iterator )
+{
+ short ConvertedShort = htons( a_Short );
+ memcpy( a_Dst + a_Iterator, &ConvertedShort, sizeof( unsigned short ) ); a_Iterator+=sizeof( unsigned short );
+}
+
+
+void cPacket::AppendInteger( int a_Integer, char* a_Dst, unsigned int & a_Iterator )
+{
+ int ConvertedInt = htonl( a_Integer );
+ memcpy( a_Dst + a_Iterator, &ConvertedInt, sizeof( int ) ); a_Iterator+=sizeof( int );
+}
+
+void cPacket::AppendInteger( unsigned int a_Integer, char* a_Dst, unsigned int & a_Iterator )
+{
+ unsigned int ConvertedInt = htonl( a_Integer );
+ memcpy( a_Dst + a_Iterator, &ConvertedInt, sizeof( unsigned int ) ); a_Iterator+=sizeof( unsigned int );
+}
+
+void cPacket::AppendFloat( float a_Float, char* a_Dst, unsigned int & a_Iterator )
+{
+ unsigned int ConvertedFloat = HostToNetwork4(&a_Float);
+ memcpy( a_Dst + a_Iterator, &ConvertedFloat, sizeof(float) ); a_Iterator += sizeof(float);
+}
+
+void cPacket::AppendDouble( double & a_Double, char* a_Dst, unsigned int & a_Iterator )
+{
+ unsigned long long ConvertedDouble = HostToNetwork8(&a_Double);
+ memcpy( a_Dst + a_Iterator, &ConvertedDouble, sizeof(double) ); a_Iterator += sizeof(double);
+}
+
+void cPacket::AppendByte( char a_Byte, char* a_Dst, unsigned int & a_Iterator )
+{
+ a_Dst[a_Iterator] = a_Byte; a_Iterator+=sizeof(char);
+}
+
+void cPacket::AppendLong( long long & a_Long, char* a_Dst, unsigned int & a_Iterator )
+{
+ unsigned long long ConvertedLong = HostToNetwork8(&a_Long);
+ memcpy( a_Dst + a_Iterator, &ConvertedLong, sizeof(long long) );
+ a_Iterator += sizeof( long long );
+}
+
+void cPacket::AppendBool( bool a_Bool, char* a_Dst, unsigned int & a_Iterator )
+{
+ a_Dst[a_Iterator] = (char)a_Bool; a_Iterator+=sizeof(bool);
+}
+
+void cPacket::AppendData( char* a_Data, unsigned int a_Size, char* a_Dst, unsigned int & a_Iterator )
+{
+ memcpy( a_Dst + a_Iterator, a_Data, a_Size ); a_Iterator += a_Size;
+}
diff --git a/source/packets/cPacket.h b/source/packets/cPacket.h
new file mode 100644
index 000000000..3cab5f222
--- /dev/null
+++ b/source/packets/cPacket.h
@@ -0,0 +1,56 @@
+#pragma once
+
+#include "cSocket.h"
+#ifdef _WIN32
+#include <xstring>
+#else
+#include <cstring> // Silly Linux doesn't have xstring...
+#include <string>
+#include <cstdio>
+#endif
+
+class cSocket;
+class cPacket
+{
+public:
+ cPacket()
+ : m_PacketID( 0 )
+ {}
+ virtual ~cPacket() {}
+
+ virtual bool Parse( cSocket & a_Socket) { a_Socket=0; printf("ERROR: Undefined NEW Parse function %x\n", m_PacketID ); return false; }
+ virtual bool Send( cSocket & a_Socket) { a_Socket=0; printf("ERROR: Undefined NEW Send function %x\n", m_PacketID ); return false; }
+ virtual cPacket* Clone() const = 0;
+
+ unsigned char m_PacketID;
+ cSocket m_Socket; // Current socket being used
+protected:
+ bool ReadString ( std::string & a_OutString );
+ bool ReadString16( std::string & a_OutString );
+ bool ReadShort ( short & a_Short );
+ bool ReadInteger(int & a_OutInteger );
+ bool ReadInteger(unsigned int & a_OutInteger );
+ bool ReadFloat ( float & a_OutFloat );
+ bool ReadDouble ( double & a_OutDouble );
+ bool ReadByte ( char & a_OutByte );
+ bool ReadByte ( unsigned char & a_OutByte );
+ bool ReadLong ( long long & a_OutLong );
+ bool ReadBool ( bool & a_OutBool );
+
+ void AppendString ( std::string & a_String, char* a_Dst, unsigned int & a_Iterator );
+ void AppendString16 ( std::string & a_String, char* a_Dst, unsigned int & a_Iterator );
+ void AppendShort ( short a_Short, char* a_Dst, unsigned int & a_Iterator );
+ void AppendShort ( unsigned short a_Short, char* a_Dst, unsigned int & a_Iterator );
+ void AppendInteger ( int a_Integer, char* a_Dst, unsigned int & a_Iterator );
+ void AppendInteger ( unsigned int a_Integer, char* a_Dst, unsigned int & a_Iterator );
+ void AppendFloat ( float a_Float, char* a_Dst, unsigned int & a_Iterator );
+ void AppendDouble ( double & a_Double, char* a_Dst, unsigned int & a_Iterator );
+ void AppendByte ( char a_Byte, char* a_Dst, unsigned int & a_Iterator );
+ void AppendLong ( long long & a_Long, char* a_Dst, unsigned int & a_Iterator );
+ void AppendBool ( bool a_Bool, char* a_Dst, unsigned int & a_Iterator );
+ void AppendData ( char* a_Data, unsigned int a_Size, char* a_Dst, unsigned int & a_Iterator );
+
+public:
+ static int SendData( SOCKET a_Socket, const char* a_Message, unsigned int a_Size, int a_Options );
+ static int RecvAll( SOCKET a_Socket, char* a_Data, unsigned int a_Size, int a_Options );
+};
diff --git a/source/packets/cPacket_13.cpp b/source/packets/cPacket_13.cpp
new file mode 100644
index 000000000..5e649fbd9
--- /dev/null
+++ b/source/packets/cPacket_13.cpp
@@ -0,0 +1,10 @@
+#include "cPacket_13.h"
+
+bool cPacket_13::Parse(cSocket & a_Socket)
+{
+ m_Socket = a_Socket;
+
+ if( !ReadInteger( m_EntityID ) ) return false;
+ if( !ReadByte ( m_ActionID ) ) return false;
+ return true;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_13.h b/source/packets/cPacket_13.h
new file mode 100644
index 000000000..ec9aedc3c
--- /dev/null
+++ b/source/packets/cPacket_13.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_13 : public cPacket
+{
+public:
+ enum ENUM_ACTION
+ {
+ ACTION_CROUCH = 1,
+ ACTION_UNCROUCH = 2,
+ ACTION_LEAVEBED = 3,
+ ACTION_STARTSPRINTING = 4,
+ ACTION_STOPSPRINTING = 5,
+ };
+
+ cPacket_13()
+ : m_EntityID( 0 )
+ , m_ActionID( 0 )
+ { m_PacketID = E_PACKET_13; }
+ virtual cPacket* Clone() const { return new cPacket_13( *this ); }
+
+ bool Parse(cSocket & a_Socket);
+
+ int m_EntityID;
+ char m_ActionID;
+
+ static const unsigned int c_Size = 1;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_AddToInventory.cpp b/source/packets/cPacket_AddToInventory.cpp
new file mode 100644
index 000000000..5d3274229
--- /dev/null
+++ b/source/packets/cPacket_AddToInventory.cpp
@@ -0,0 +1,17 @@
+#include "cPacket_AddToInventory.h"
+
+bool cPacket_AddToInventory::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendShort ( m_ItemType, Message, i );
+ AppendByte ( m_Count, Message, i );
+ AppendShort ( m_Life, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_AddToInventory.h b/source/packets/cPacket_AddToInventory.h
new file mode 100644
index 000000000..8029a53d0
--- /dev/null
+++ b/source/packets/cPacket_AddToInventory.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_AddToInventory : public cPacket
+{
+public:
+ cPacket_AddToInventory()
+ : m_ItemType( 0 )
+ , m_Count( 0 )
+ , m_Life( 0 )
+ { m_PacketID = E_ADD_TO_INV; }
+ virtual cPacket* Clone() const { return new cPacket_AddToInventory(*this); }
+
+ bool Parse( cSocket & a_Socket );
+ bool Send( cSocket & a_Socket );
+
+ short m_ItemType;
+ char m_Count;
+ short m_Life;
+ static const unsigned int c_Size = 1 + 2 + 1 + 2;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_ArmAnim.cpp b/source/packets/cPacket_ArmAnim.cpp
new file mode 100644
index 000000000..f0a662f27
--- /dev/null
+++ b/source/packets/cPacket_ArmAnim.cpp
@@ -0,0 +1,24 @@
+#include "cPacket_ArmAnim.h"
+
+bool cPacket_ArmAnim::Parse( cSocket & a_Socket )
+{
+ m_Socket = a_Socket;
+ if(!ReadInteger(m_EntityID) ) return false;
+ if(!ReadByte(m_Animation) ) return false;
+ return true;
+}
+
+bool cPacket_ArmAnim::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_EntityID, Message, i );
+ AppendByte ( m_Animation, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_ArmAnim.h b/source/packets/cPacket_ArmAnim.h
new file mode 100644
index 000000000..e22d88506
--- /dev/null
+++ b/source/packets/cPacket_ArmAnim.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_ArmAnim : public cPacket
+{
+public:
+ cPacket_ArmAnim()
+ : m_EntityID( 0 )
+ , m_Animation( 0 )
+ { m_PacketID = E_ANIMATION; }
+ virtual cPacket* Clone() const { return new cPacket_ArmAnim(*this); }
+
+ bool Parse(cSocket & a_Socket);
+ bool Send(cSocket & a_Socket);
+
+ int m_EntityID;
+ char m_Animation;
+ static const unsigned int c_Size = 1 + 4 + 1;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_BlockChange.cpp b/source/packets/cPacket_BlockChange.cpp
new file mode 100644
index 000000000..44b389a14
--- /dev/null
+++ b/source/packets/cPacket_BlockChange.cpp
@@ -0,0 +1,19 @@
+#include "cPacket_BlockChange.h"
+
+bool cPacket_BlockChange::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_PosX, Message, i );
+ AppendByte ( m_PosY, Message, i );
+ AppendInteger( m_PosZ, Message, i );
+ AppendByte ( m_BlockType, Message, i );
+ AppendByte ( m_BlockMeta, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_BlockChange.h b/source/packets/cPacket_BlockChange.h
new file mode 100644
index 000000000..0cd6cfb6f
--- /dev/null
+++ b/source/packets/cPacket_BlockChange.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.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); }
+
+ bool Send(cSocket & a_Socket);
+
+ int m_PosX;
+ char m_PosY;
+ int m_PosZ;
+ char m_BlockType;
+ char m_BlockMeta;
+ static const unsigned int c_Size = 1 + 4 + 1 + 4 + 1 + 1;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_BlockDig.cpp b/source/packets/cPacket_BlockDig.cpp
new file mode 100644
index 000000000..c6092f9cd
--- /dev/null
+++ b/source/packets/cPacket_BlockDig.cpp
@@ -0,0 +1,29 @@
+#include "cPacket_BlockDig.h"
+
+bool cPacket_BlockDig::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_PosX, Message, i );
+ AppendByte ( m_PosY, Message, i );
+ AppendInteger( m_PosZ, Message, i );
+ AppendByte ( m_Direction, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
+
+bool cPacket_BlockDig::Parse(cSocket & a_Socket)
+{
+ m_Socket = a_Socket;
+ if( !ReadByte ( m_Status ) ) return false;
+ if( !ReadInteger( m_PosX ) ) return false;
+ if( !ReadByte ( m_PosY ) ) return false;
+ if( !ReadInteger( m_PosZ ) ) return false;
+ if( !ReadByte ( m_Direction ) ) return false;
+ return true;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_BlockDig.h b/source/packets/cPacket_BlockDig.h
new file mode 100644
index 000000000..7ea847aa1
--- /dev/null
+++ b/source/packets/cPacket_BlockDig.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_BlockDig : public cPacket //tolua_export
+{ //tolua_export
+public:
+ cPacket_BlockDig() //tolua_export
+ : m_Status( 0 )
+ , m_PosX( 0 )
+ , m_PosY( 0 )
+ , m_PosZ( 0 )
+ , m_Direction( 0 )
+ { m_PacketID = E_BLOCK_DIG; } //tolua_export
+ virtual cPacket* Clone() const { return new cPacket_BlockDig(*this); } //tolua_export
+
+ bool Parse(cSocket & a_Socket);
+ bool Send(cSocket & a_Socket);
+
+ char m_Status; //tolua_export
+ int m_PosX; //tolua_export
+ char m_PosY; //tolua_export
+ int m_PosZ; //tolua_export
+ char m_Direction; //tolua_export
+ static const unsigned int c_Size = 12;
+}; //tolua_export \ No newline at end of file
diff --git a/source/packets/cPacket_BlockPlace.cpp b/source/packets/cPacket_BlockPlace.cpp
new file mode 100644
index 000000000..08bc1c40c
--- /dev/null
+++ b/source/packets/cPacket_BlockPlace.cpp
@@ -0,0 +1,18 @@
+#include "cPacket_BlockPlace.h"
+
+bool cPacket_BlockPlace::Parse(cSocket & a_Socket)
+{
+ m_Socket = a_Socket;
+ if( !ReadInteger( m_PosX ) ) return false;
+ if( !ReadByte ( m_PosY ) ) return false;
+ if( !ReadInteger( m_PosZ ) ) return false;
+ if( !ReadByte ( m_Direction ) ) return false;
+
+ if( !ReadShort ( m_ItemType ) ) return false;
+ if( m_ItemType > -1 )
+ {
+ if( !ReadByte ( m_Count ) ) return false;
+ if( !ReadShort ( m_Uses ) ) return false;
+ }
+ return true;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_BlockPlace.h b/source/packets/cPacket_BlockPlace.h
new file mode 100644
index 000000000..c7f72bacf
--- /dev/null
+++ b/source/packets/cPacket_BlockPlace.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_BlockPlace : public cPacket //tolua_export
+{ //tolua_export
+public:
+ cPacket_BlockPlace()
+ : m_PosX( 0 )
+ , m_PosY( 0 )
+ , m_PosZ( 0 )
+ , m_Direction( 0 )
+ , m_ItemType( 0 )
+ , m_Count( 0 )
+ , m_Uses( 0 )
+ { m_PacketID = E_BLOCK_PLACE; }
+ virtual cPacket* Clone() const { return new cPacket_BlockPlace(*this); }
+
+ bool Parse(cSocket & a_Socket);
+
+ int m_PosX; //tolua_export
+ char m_PosY; //tolua_export
+ int m_PosZ; //tolua_export
+ char m_Direction; //tolua_export
+
+ short m_ItemType; //tolua_export
+ char m_Count; //tolua_export
+ short m_Uses; //tolua_export
+
+ static const unsigned int c_Size = 1 + 4 + 1 + 4 + 1 + 2;// ( + 2 )
+}; //tolua_export \ No newline at end of file
diff --git a/source/packets/cPacket_Chat.cpp b/source/packets/cPacket_Chat.cpp
new file mode 100644
index 000000000..d948c5deb
--- /dev/null
+++ b/source/packets/cPacket_Chat.cpp
@@ -0,0 +1,23 @@
+#include "cPacket_Chat.h"
+
+
+bool cPacket_Chat::Parse( cSocket & a_Socket )
+{
+ m_Socket = a_Socket;
+ if( !ReadString16( m_Message ) ) return false;
+ return true;
+}
+
+bool cPacket_Chat::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size + m_Message.size() * sizeof( short );
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendString16 ( m_Message, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_Chat.h b/source/packets/cPacket_Chat.h
new file mode 100644
index 000000000..0de5c9343
--- /dev/null
+++ b/source/packets/cPacket_Chat.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+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); }
+
+ bool Parse(cSocket & a_Socket);
+ bool Send(cSocket & a_Socket);
+
+ std::string m_Message;
+ static const unsigned int c_Size = 3; // Minimum size
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_CollectItem.cpp b/source/packets/cPacket_CollectItem.cpp
new file mode 100644
index 000000000..0ad92ddad
--- /dev/null
+++ b/source/packets/cPacket_CollectItem.cpp
@@ -0,0 +1,16 @@
+#include "cPacket_CollectItem.h"
+
+bool cPacket_CollectItem::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_CollectedID, Message, i );
+ AppendInteger( m_CollectorID, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_CollectItem.h b/source/packets/cPacket_CollectItem.h
new file mode 100644
index 000000000..5f11500b5
--- /dev/null
+++ b/source/packets/cPacket_CollectItem.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.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); }
+
+ bool Send( cSocket & a_Socket );
+
+ int m_CollectedID;
+ int m_CollectorID;
+ static const unsigned int c_Size = 1 + 4 + 4;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_DestroyEntity.cpp b/source/packets/cPacket_DestroyEntity.cpp
new file mode 100644
index 000000000..e0ee22c76
--- /dev/null
+++ b/source/packets/cPacket_DestroyEntity.cpp
@@ -0,0 +1,23 @@
+#include "cPacket_DestroyEntity.h"
+#include "cEntity.h"
+
+cPacket_DestroyEntity::cPacket_DestroyEntity(cEntity* a_Entity)
+{
+ m_PacketID = E_DESTROY_ENT;
+
+ m_UniqueID = a_Entity->GetUniqueID();
+}
+
+bool cPacket_DestroyEntity::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_UniqueID, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
diff --git a/source/packets/cPacket_DestroyEntity.h b/source/packets/cPacket_DestroyEntity.h
new file mode 100644
index 000000000..0b852e727
--- /dev/null
+++ b/source/packets/cPacket_DestroyEntity.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.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); }
+
+ bool Send( cSocket & a_Socket );
+
+ int m_UniqueID;
+ static const unsigned int c_Size = 1 + 4;
+};
diff --git a/source/packets/cPacket_Disconnect.cpp b/source/packets/cPacket_Disconnect.cpp
new file mode 100644
index 000000000..c2a0e3be6
--- /dev/null
+++ b/source/packets/cPacket_Disconnect.cpp
@@ -0,0 +1,22 @@
+#include "cPacket_Disconnect.h"
+
+bool cPacket_Disconnect::Parse( cSocket & a_Socket )
+{
+ m_Socket = a_Socket;
+ if( !ReadString16(m_Reason) ) return false;
+ return true;
+}
+
+bool cPacket_Disconnect::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size + m_Reason.size()*sizeof(short);
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendString16 ( m_Reason, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
diff --git a/source/packets/cPacket_Disconnect.h b/source/packets/cPacket_Disconnect.h
new file mode 100644
index 000000000..0711851f4
--- /dev/null
+++ b/source/packets/cPacket_Disconnect.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_Disconnect : public cPacket
+{
+public:
+ cPacket_Disconnect() { m_PacketID = E_DISCONNECT; }
+ cPacket_Disconnect(const std::string & a_Reason) { m_PacketID = E_DISCONNECT; m_Reason = a_Reason; }
+ virtual cPacket* Clone() const { return new cPacket_Disconnect(*this); }
+
+ bool Parse( cSocket & a_Socket );
+ bool Send( cSocket & a_Socket );
+
+ std::string m_Reason;
+ static const unsigned int c_Size = 3; // Minimum size
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_EntityEquipment.cpp b/source/packets/cPacket_EntityEquipment.cpp
new file mode 100644
index 000000000..afd2e7678
--- /dev/null
+++ b/source/packets/cPacket_EntityEquipment.cpp
@@ -0,0 +1,42 @@
+#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_Slot = a_Copy.m_Slot;
+ m_ItemID = a_Copy.m_ItemID;
+ m_Short = 0;
+}
+
+bool cPacket_EntityEquipment::Parse(cSocket & a_Socket)
+{
+ m_Socket = a_Socket;
+ if( !ReadInteger( m_UniqueID ) ) return false;
+ if( !ReadShort ( m_Slot ) ) return false;
+ if( !ReadShort ( m_ItemID ) ) return false;
+ if( !ReadShort ( m_Short ) ) return false;
+ return true;
+}
+
+bool cPacket_EntityEquipment::Send(cSocket & a_Socket)
+{
+ //LOG("InventoryChange:");
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ if( m_ItemID <= 0 ) m_ItemID = -1; // Fix, to make sure no invalid values are sent.
+ // WARNING: HERE ITS -1, BUT IN NAMED ENTITY SPAWN PACKET ITS 0 !!
+ //LOG("cPacket_EntityEquipment: Sending equipped item ID: %i", m_ItemID );
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_UniqueID, Message, i );
+ AppendShort ( m_Slot, Message, i );
+ AppendShort ( m_ItemID, Message, i );
+ AppendShort ( m_Short, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_EntityEquipment.h b/source/packets/cPacket_EntityEquipment.h
new file mode 100644
index 000000000..253786140
--- /dev/null
+++ b/source/packets/cPacket_EntityEquipment.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_EntityEquipment : public cPacket
+{
+public:
+ cPacket_EntityEquipment()
+ : m_UniqueID( 0 )
+ , m_Slot( 0 )
+ , m_ItemID( 0 )
+ , m_Short( 0 )
+ { m_PacketID = E_ENTITY_EQUIPMENT; m_Short = 0; }
+ cPacket_EntityEquipment( const cPacket_EntityEquipment & a_Copy );
+ virtual cPacket* Clone() const { return new cPacket_EntityEquipment(*this); }
+
+ bool Parse(cSocket & a_Socket);
+ bool Send(cSocket & a_Socket);
+
+ int m_UniqueID;
+ short m_Slot; // 0 = hold 1-4 = armor
+ short m_ItemID;
+ short m_Short;
+
+ static const unsigned int c_Size = 1 + 4 + 2 + 2 + 2;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_EntityLook.cpp b/source/packets/cPacket_EntityLook.cpp
new file mode 100644
index 000000000..7dcbf61c2
--- /dev/null
+++ b/source/packets/cPacket_EntityLook.cpp
@@ -0,0 +1,28 @@
+#include "cPacket_EntityLook.h"
+
+#include "cEntity.h"
+
+cPacket_EntityLook::cPacket_EntityLook(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);
+}
+
+bool cPacket_EntityLook::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_UniqueID, Message, i );
+ AppendByte ( m_Rotation, Message, i );
+ AppendByte ( m_Pitch, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
diff --git a/source/packets/cPacket_EntityLook.h b/source/packets/cPacket_EntityLook.h
new file mode 100644
index 000000000..215620f07
--- /dev/null
+++ b/source/packets/cPacket_EntityLook.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cEntity;
+class cPacket_EntityLook : public cPacket
+{
+public:
+ cPacket_EntityLook()
+ : m_UniqueID( 0 )
+ , m_Rotation( 0 )
+ , m_Pitch( 0 )
+ { m_PacketID = E_ENT_LOOK; }
+ cPacket_EntityLook(cEntity* a_Entity);
+ virtual cPacket* Clone() const { return new cPacket_EntityLook(*this); }
+
+ bool Send( cSocket & a_Socket );
+
+ int m_UniqueID;
+ char m_Rotation;
+ char m_Pitch;
+
+ static const unsigned int c_Size = 1 + 4 + 1 + 1;
+};
diff --git a/source/packets/cPacket_EntityStatus.cpp b/source/packets/cPacket_EntityStatus.cpp
new file mode 100644
index 000000000..41d94b6c2
--- /dev/null
+++ b/source/packets/cPacket_EntityStatus.cpp
@@ -0,0 +1,17 @@
+#include "cPacket_EntityStatus.h"
+
+bool cPacket_EntityStatus::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size;
+
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger ( m_UniqueID, Message, i );
+ AppendByte ( m_Status, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_EntityStatus.h b/source/packets/cPacket_EntityStatus.h
new file mode 100644
index 000000000..2511e2935
--- /dev/null
+++ b/source/packets/cPacket_EntityStatus.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.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 ); }
+
+ bool Send(cSocket & a_Socket);
+
+ 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;
+};
diff --git a/source/packets/cPacket_Flying.cpp b/source/packets/cPacket_Flying.cpp
new file mode 100644
index 000000000..b8cab1de1
--- /dev/null
+++ b/source/packets/cPacket_Flying.cpp
@@ -0,0 +1,8 @@
+#include "cPacket_Flying.h"
+
+bool cPacket_Flying::Parse(cSocket & a_Socket)
+{
+ m_Socket = a_Socket;
+ if( !ReadBool( m_bFlying ) ) return false;
+ return true;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_Flying.h b/source/packets/cPacket_Flying.h
new file mode 100644
index 000000000..7e30ebd73
--- /dev/null
+++ b/source/packets/cPacket_Flying.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_Flying : public cPacket
+{
+public:
+ // The BS packet
+ cPacket_Flying()
+ : m_bFlying( false )
+ { m_PacketID = E_FLYING; }
+ virtual cPacket* Clone() const { return new cPacket_Flying(*this); }
+
+ bool Parse(cSocket & a_Socket);
+
+ bool m_bFlying;
+ static const unsigned int c_Size = 2;
+};
diff --git a/source/packets/cPacket_Handshake.cpp b/source/packets/cPacket_Handshake.cpp
new file mode 100644
index 000000000..2513ab33d
--- /dev/null
+++ b/source/packets/cPacket_Handshake.cpp
@@ -0,0 +1,24 @@
+#include "cPacket_Handshake.h"
+
+bool cPacket_Handshake::Parse(cSocket & a_Socket)
+{
+ //printf("Parse: NEW Handshake\n");
+ m_Socket = a_Socket;
+ if( !ReadString16( m_Username ) ) return false;
+ return true;
+}
+
+bool cPacket_Handshake::Send(cSocket & a_Socket)
+{
+ //LOG("Send: NEW Handshake %s", m_Username.c_str() );
+ unsigned int TotalSize = c_Size + m_Username.size() * sizeof(short);
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendString16( m_Username, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( cPacket::SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_Handshake.h b/source/packets/cPacket_Handshake.h
new file mode 100644
index 000000000..b14d829f4
--- /dev/null
+++ b/source/packets/cPacket_Handshake.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_Handshake : public cPacket
+{
+public:
+ cPacket_Handshake() { m_PacketID = E_HANDSHAKE; }
+ virtual cPacket* Clone() const { return new cPacket_Handshake(*this); }
+
+ virtual bool Parse(cSocket & a_Socket);
+ virtual bool Send(cSocket & a_Socket);
+
+ std::string m_Username;
+ static const unsigned int c_Size = 3; // Minimal size
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_InventoryProgressBar.cpp b/source/packets/cPacket_InventoryProgressBar.cpp
new file mode 100644
index 000000000..c8d7b0383
--- /dev/null
+++ b/source/packets/cPacket_InventoryProgressBar.cpp
@@ -0,0 +1,18 @@
+#include "cPacket_InventoryProgressBar.h"
+
+bool cPacket_InventoryProgressBar::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size;
+
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendByte ( m_WindowID, Message, i );
+ AppendShort ( m_ProgressBar, Message, i );
+ AppendShort ( m_Value, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_InventoryProgressBar.h b/source/packets/cPacket_InventoryProgressBar.h
new file mode 100644
index 000000000..c9b5e196e
--- /dev/null
+++ b/source/packets/cPacket_InventoryProgressBar.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.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); }
+
+ bool Send(cSocket & a_Socket);
+
+ char m_WindowID;
+ short m_ProgressBar;
+ short m_Value;
+
+ static const unsigned int c_Size = 1 + 1 + 2 + 2;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_InventorySlot.cpp b/source/packets/cPacket_InventorySlot.cpp
new file mode 100644
index 000000000..13b41b7b1
--- /dev/null
+++ b/source/packets/cPacket_InventorySlot.cpp
@@ -0,0 +1,23 @@
+#include "cPacket_InventorySlot.h"
+
+bool cPacket_InventorySlot::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size;
+ if( m_ItemID > -1 ) TotalSize += 1 + 2;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendByte ( m_WindowID, Message, i );
+ AppendShort ( m_SlotNum, Message, i );
+ AppendShort ( m_ItemID, Message, i );
+ if( m_ItemID > -1 )
+ {
+ AppendByte ( m_ItemCount, Message, i );
+ AppendShort ( m_ItemUses, Message, i );
+ }
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_InventorySlot.h b/source/packets/cPacket_InventorySlot.h
new file mode 100644
index 000000000..95711c98d
--- /dev/null
+++ b/source/packets/cPacket_InventorySlot.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_InventorySlot : public cPacket // Set item [S -> C] ?
+{
+public:
+ cPacket_InventorySlot()
+ : m_WindowID( 0 )
+ , m_SlotNum( 0 )
+ , m_ItemID( 0 )
+ , m_ItemCount( 0 )
+ , m_ItemUses( 0 )
+ { m_PacketID = E_INVENTORY_SLOT; }
+ virtual cPacket* Clone() const { return new cPacket_InventorySlot(*this); }
+
+ bool Send(cSocket & a_Socket);
+
+ 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 + 2; // Minimal size ( +1+1 = max)
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_ItemSwitch.cpp b/source/packets/cPacket_ItemSwitch.cpp
new file mode 100644
index 000000000..39c61833e
--- /dev/null
+++ b/source/packets/cPacket_ItemSwitch.cpp
@@ -0,0 +1,23 @@
+#include "cPacket_ItemSwitch.h"
+
+bool cPacket_ItemSwitch::Parse( cSocket & a_Socket )
+{
+ m_Socket = a_Socket;
+
+ if( !ReadShort ( m_SlotNum ) ) return false;
+ return true;
+}
+
+bool cPacket_ItemSwitch::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendShort ( m_SlotNum, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_ItemSwitch.h b/source/packets/cPacket_ItemSwitch.h
new file mode 100644
index 000000000..8fee397c7
--- /dev/null
+++ b/source/packets/cPacket_ItemSwitch.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_ItemSwitch : public cPacket
+{
+public:
+ cPacket_ItemSwitch()
+ : m_SlotNum( 0 )
+ { m_PacketID = E_ITEM_SWITCH; }
+ virtual cPacket* Clone() const { return new cPacket_ItemSwitch(*this); }
+
+ bool Parse(cSocket & a_Socket);
+ bool Send(cSocket & a_Socket);
+
+ short m_SlotNum;
+ static const unsigned int c_Size = 1 + 2;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_KeepAlive.cpp b/source/packets/cPacket_KeepAlive.cpp
new file mode 100644
index 000000000..8dcd9092f
--- /dev/null
+++ b/source/packets/cPacket_KeepAlive.cpp
@@ -0,0 +1,22 @@
+#include "cPacket_KeepAlive.h"
+
+bool cPacket_KeepAlive::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_KeepAliveID, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
+
+bool cPacket_KeepAlive::Parse(cSocket & a_Socket)
+{
+ m_Socket = a_Socket;
+ if( !ReadInteger( m_KeepAliveID ) ) return false;
+ return true;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_KeepAlive.h b/source/packets/cPacket_KeepAlive.h
new file mode 100644
index 000000000..833947bfb
--- /dev/null
+++ b/source/packets/cPacket_KeepAlive.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_KeepAlive : public cPacket
+{
+public:
+ cPacket_KeepAlive() { m_PacketID = E_KEEP_ALIVE; }
+ virtual cPacket* Clone() const { return new cPacket_KeepAlive(*this); }
+
+ virtual bool Parse(cSocket & a_Socket);
+ virtual bool Send(cSocket & a_Socket);
+
+ int m_KeepAliveID;
+
+ static const unsigned int c_Size = 1 + 4;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_Login.cpp b/source/packets/cPacket_Login.cpp
new file mode 100644
index 000000000..f0a9aaf30
--- /dev/null
+++ b/source/packets/cPacket_Login.cpp
@@ -0,0 +1,41 @@
+#include "cPacket_Login.h"
+
+bool cPacket_Login::Parse( cSocket & a_Socket )
+{
+ //printf("Parse: NEW Login\n");
+ m_Socket = a_Socket;
+
+ m_Username.clear();
+
+ if( !ReadInteger( m_ProtocolVersion ) ) return false;
+ if( !ReadString16( m_Username ) ) return false;
+ if( !ReadLong ( m_MapSeed ) ) return false;
+ if( !ReadInteger( m_ServerMode ) ) return false;
+ if( !ReadByte ( m_Dimension ) ) return false;
+ if( !ReadByte ( m_Difficulty ) ) return false;
+ if( !ReadByte ( m_WorldHeight ) ) return false;
+ if( !ReadByte ( m_MaxPlayers ) ) return false;
+ return true;
+}
+
+bool cPacket_Login::Send( cSocket & a_Socket )
+{
+ //printf("Send: NEW Login\n");
+ unsigned int TotalSize = c_Size + m_Username.size() * sizeof(short);
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_ProtocolVersion, Message, i );
+ AppendString16 ( m_Username, Message, i );
+ AppendLong ( m_MapSeed, Message, i );
+ AppendInteger( m_ServerMode, Message, i );
+ AppendByte ( m_Dimension, Message, i );
+ AppendByte ( m_Difficulty, Message, i );
+ AppendByte ( m_WorldHeight, Message, i );
+ AppendByte ( m_MaxPlayers, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( cPacket::SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_Login.h b/source/packets/cPacket_Login.h
new file mode 100644
index 000000000..91919a799
--- /dev/null
+++ b/source/packets/cPacket_Login.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include "cPacket.h"
+#include <string>
+#include "PacketID.h"
+
+class cPacket_Login : public cPacket //tolua_export
+{ //tolua_export
+public:
+ cPacket_Login()
+ : m_ProtocolVersion( 0 )
+ , m_MapSeed( 0 )
+ , m_ServerMode( 0 )
+ , m_Dimension( 0 )
+ , m_Difficulty( 0 )
+ , m_WorldHeight( 0 )
+ , m_MaxPlayers( 0 )
+ { m_PacketID = E_LOGIN; }
+ virtual cPacket* Clone() const { return new cPacket_Login(*this); }
+
+ virtual bool Parse(cSocket & a_Socket);
+ virtual bool Send(cSocket & a_Socket);
+
+ int m_ProtocolVersion; //tolua_export
+ std::string m_Username; //tolua_export
+ long long m_MapSeed; //tolua_export
+ int m_ServerMode; //tolua_export
+ char m_Dimension; //tolua_export
+ char m_Difficulty; //tolua_export
+ unsigned char m_WorldHeight; //tolua_export
+ unsigned char m_MaxPlayers; //tolua_export
+ static const unsigned int c_Size = 1 + 4 + 2 + 8 + 4 + 1 + 1 + 1 + 1; // Minimal size
+}; //tolua_export
diff --git a/source/packets/cPacket_MapChunk.cpp b/source/packets/cPacket_MapChunk.cpp
new file mode 100644
index 000000000..08681494c
--- /dev/null
+++ b/source/packets/cPacket_MapChunk.cpp
@@ -0,0 +1,69 @@
+#include "cPacket_MapChunk.h"
+#include "../cChunk.h"
+
+#include "zlib.h"
+
+cPacket_MapChunk::~cPacket_MapChunk()
+{
+ if( m_CompressedData )
+ {
+ delete [] m_CompressedData;
+ }
+}
+
+cPacket_MapChunk::cPacket_MapChunk(cChunk* a_Chunk)
+{
+ m_PacketID = E_MAP_CHUNK;
+
+ m_PosX = a_Chunk->GetPosX() * 16; // It has to be block coordinates
+ m_PosY = (short)(a_Chunk->GetPosY() * 128);
+ m_PosZ = a_Chunk->GetPosZ() * 16;
+
+ m_SizeX = 15;
+ m_SizeY = 127;
+ m_SizeZ = 15;
+
+ uLongf CompressedSize = compressBound( cChunk::c_BlockDataSize );
+ char* CompressedBlockData = new char[CompressedSize];
+
+ compress2( (Bytef*)CompressedBlockData, &CompressedSize, (const Bytef*)a_Chunk->pGetBlockData(), cChunk::c_BlockDataSize, Z_DEFAULT_COMPRESSION);
+
+ m_CompressedData = CompressedBlockData;
+ m_CompressedSize = CompressedSize;
+}
+
+cPacket_MapChunk::cPacket_MapChunk( const cPacket_MapChunk & a_Copy )
+{
+ m_PacketID = E_MAP_CHUNK;
+ m_PosX = a_Copy.m_PosX;
+ m_PosY = a_Copy.m_PosY;
+ m_PosZ = a_Copy.m_PosZ;
+ m_SizeX = a_Copy.m_SizeX;
+ m_SizeY = a_Copy.m_SizeY;
+ m_SizeZ = a_Copy.m_SizeZ;
+
+ m_CompressedSize = a_Copy.m_CompressedSize;
+ m_CompressedData = new char[m_CompressedSize];
+ memcpy( m_CompressedData, a_Copy.m_CompressedData, m_CompressedSize );
+}
+
+bool cPacket_MapChunk::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size + m_CompressedSize;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger ( m_PosX, Message, i );
+ AppendShort ( m_PosY, Message, i );
+ AppendInteger ( m_PosZ, Message, i );
+ AppendByte ( m_SizeX, Message, i );
+ AppendByte ( m_SizeY, Message, i );
+ AppendByte ( m_SizeZ, Message, i );
+ AppendInteger ( m_CompressedSize, Message, i );
+ AppendData ( m_CompressedData, m_CompressedSize, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_MapChunk.h b/source/packets/cPacket_MapChunk.h
new file mode 100644
index 000000000..48e2cbf1f
--- /dev/null
+++ b/source/packets/cPacket_MapChunk.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cChunk;
+class cPacket_MapChunk : public cPacket
+{
+public:
+ cPacket_MapChunk()
+ : m_PosX( 0 )
+ , m_PosY( 0 )
+ , m_PosZ( 0 )
+ , m_SizeX( 0 )
+ , m_SizeY( 0 )
+ , m_SizeZ( 0 )
+ , m_CompressedSize( 0 )
+ , m_CompressedData( 0 )
+ { m_PacketID = E_MAP_CHUNK; m_CompressedData = 0; }
+ cPacket_MapChunk(cChunk* a_Chunk);
+ cPacket_MapChunk( const cPacket_MapChunk & a_Copy );
+ ~cPacket_MapChunk();
+ virtual cPacket* Clone() const { return new cPacket_MapChunk(*this); }
+
+ bool Send(cSocket & a_Socket);
+
+ int m_PosX; // In block coordinates
+ short m_PosY;
+ int m_PosZ;
+ char m_SizeX; // Is actually size-1 (when size is 128, this is 127)
+ char m_SizeY;
+ char m_SizeZ;
+ int m_CompressedSize;
+ static const unsigned int c_Size = 1 + 4 + 2 + 4 + 1 + 1 + 1 + 4;
+
+ char* m_CompressedData;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_Metadata.cpp b/source/packets/cPacket_Metadata.cpp
new file mode 100644
index 000000000..3d3df3b9c
--- /dev/null
+++ b/source/packets/cPacket_Metadata.cpp
@@ -0,0 +1,65 @@
+#include "cPacket_Metadata.h"
+
+cPacket_Metadata::cPacket_Metadata(int s, int id)
+ : EMetaState( (MetaState)s )
+ , m_UniqueID( id )
+ , m_Type( 0 )
+ , m_MetaData( 0 )
+{
+ m_PacketID = E_METADATA;
+ FormPacket();
+}
+
+cPacket_Metadata::cPacket_Metadata()
+ : EMetaState(NORMAL)
+ , m_UniqueID( 0 )
+ , m_Type( 0 )
+ , m_MetaData( 0 )
+{
+ m_PacketID = E_METADATA;
+ FormPacket();
+}
+
+cPacket_Metadata::~cPacket_Metadata() {
+ //if( m_MetaData ) delete [] m_MetaData;
+}
+
+void cPacket_Metadata::FormPacket() {
+ if( m_MetaData ) delete [] m_MetaData;
+ m_MetaData = new char[3];
+ m_MetaDataSize = 3;
+ //m_UniqueID = GetUniqueID();
+ m_MetaData[0] = 0x00;
+ //m_MetaData[1] = 0x01; //Burning
+ m_MetaData[2] = 0x7f;
+ switch(EMetaState) {
+ case NORMAL:
+ m_MetaData[1] = 0x00;
+ break;
+ case BURNING:
+ m_MetaData[1] = 0x01;
+ break;
+ case CROUCHED:
+ m_MetaData[1] = 0x02;
+ break;
+ case RIDING:
+ m_MetaData[1] = 0x04;
+ break;
+ default:
+ m_MetaData[1] = 0x00;
+ break;
+ }
+}
+
+bool cPacket_Metadata::Send(cSocket & a_Socket) {
+ unsigned int TotalSize = c_Size + m_MetaDataSize;
+ char* Message = new char[TotalSize];
+ unsigned int i = 0;
+
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger ( m_UniqueID, Message, i );
+ AppendData ( m_MetaData, m_MetaDataSize, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ return RetVal;
+}
diff --git a/source/packets/cPacket_Metadata.h b/source/packets/cPacket_Metadata.h
new file mode 100644
index 000000000..f96178a2c
--- /dev/null
+++ b/source/packets/cPacket_Metadata.h
@@ -0,0 +1,23 @@
+#pragma once
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_Metadata : public cPacket
+{
+public:
+ cPacket_Metadata(int s, int id);
+ cPacket_Metadata();
+ ~cPacket_Metadata();
+
+ bool Send(cSocket & a_Socket);
+ void FormPacket();
+ virtual cPacket* Clone() const { return new cPacket_Metadata( *this ); }
+
+ enum MetaState{NORMAL,BURNING,CROUCHED,RIDING} EMetaState;
+
+ static const unsigned int c_Size = 4 + 1;
+ int m_UniqueID;
+ char m_Type;
+ unsigned int m_MetaDataSize;
+ char* m_MetaData;
+};
diff --git a/source/packets/cPacket_MultiBlock.cpp b/source/packets/cPacket_MultiBlock.cpp
new file mode 100644
index 000000000..ef396874f
--- /dev/null
+++ b/source/packets/cPacket_MultiBlock.cpp
@@ -0,0 +1,42 @@
+#include "cPacket_MultiBlock.h"
+
+cPacket_MultiBlock::cPacket_MultiBlock( const cPacket_MultiBlock & a_Copy )
+{
+ m_PacketID = E_MULTI_BLOCK;
+ m_ChunkX = a_Copy.m_ChunkX;
+ m_ChunkZ = a_Copy.m_ChunkZ;
+ m_NumBlocks = a_Copy.m_NumBlocks;
+ m_BlockCoordinates = new unsigned short[m_NumBlocks];
+ memcpy( m_BlockCoordinates, a_Copy.m_BlockCoordinates, sizeof(short)*m_NumBlocks );
+ m_BlockTypes = new char[m_NumBlocks];
+ memcpy( m_BlockTypes, a_Copy.m_BlockTypes, m_NumBlocks );
+ m_BlockMetas = new char[m_NumBlocks];
+ memcpy( m_BlockMetas, a_Copy.m_BlockMetas, m_NumBlocks );
+}
+
+cPacket_MultiBlock::~cPacket_MultiBlock()
+{
+ if( m_BlockCoordinates ) delete [] m_BlockCoordinates;
+ if( m_BlockTypes ) delete [] m_BlockTypes;
+ if( m_BlockMetas ) delete [] m_BlockMetas;
+}
+
+bool cPacket_MultiBlock::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size + m_NumBlocks * ( sizeof(short) + 2*sizeof(char) );
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger ( m_ChunkX, Message, i );
+ AppendInteger ( m_ChunkZ, Message, i );
+ AppendShort ( m_NumBlocks, Message, i );
+
+ AppendData ( (char*)m_BlockCoordinates,sizeof(short)*m_NumBlocks, Message, i );
+ AppendData ( m_BlockTypes, sizeof(char)*m_NumBlocks, Message, i );
+ AppendData ( m_BlockMetas, sizeof(char)*m_NumBlocks, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_MultiBlock.h b/source/packets/cPacket_MultiBlock.h
new file mode 100644
index 000000000..fb5e50d93
--- /dev/null
+++ b/source/packets/cPacket_MultiBlock.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_MultiBlock : public cPacket
+{
+public:
+ cPacket_MultiBlock()
+ : m_ChunkX( 0 )
+ , m_ChunkZ( 0 )
+ , m_NumBlocks( 0 )
+ , m_BlockCoordinates( 0 )
+ , m_BlockTypes( 0 )
+ , m_BlockMetas( 0 )
+ { m_PacketID = E_MULTI_BLOCK; }
+ cPacket_MultiBlock( const cPacket_MultiBlock & a_Copy );
+ ~cPacket_MultiBlock();
+ virtual cPacket* Clone() const { return new cPacket_MultiBlock(*this); }
+
+ bool Send(cSocket & a_Socket);
+
+ int m_ChunkX;
+ int m_ChunkZ;
+ short m_NumBlocks;
+
+ static const unsigned int c_Size = 1 + 4 + 4 + 2; // Minimum size (when NumBlocks == 0)
+
+ unsigned short* m_BlockCoordinates; // x<<12 | z<<8 | y
+ char* m_BlockTypes;
+ char* m_BlockMetas;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_NamedEntitySpawn.cpp b/source/packets/cPacket_NamedEntitySpawn.cpp
new file mode 100644
index 000000000..222711119
--- /dev/null
+++ b/source/packets/cPacket_NamedEntitySpawn.cpp
@@ -0,0 +1,26 @@
+#include "cPacket_NamedEntitySpawn.h"
+
+
+bool cPacket_NamedEntitySpawn::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size + m_PlayerName.size() * sizeof( short );
+ char* Message = new char[TotalSize];
+
+ if( m_CurrentItem <= 0 ) m_CurrentItem = 0; // Fix, to make sure no invalid values are sent.
+ // WARNING: HERE ITS 0, BUT IN EQUIP PACKET ITS -1 !!
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_UniqueID, Message, i );
+ AppendString16( m_PlayerName, Message, i );
+ AppendInteger( m_PosX, Message, i );
+ AppendInteger( m_PosY, Message, i );
+ AppendInteger( m_PosZ, Message, i );
+ AppendByte ( m_Rotation, Message, i );
+ AppendByte ( m_Pitch, Message, i );
+ AppendShort ( m_CurrentItem, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
diff --git a/source/packets/cPacket_NamedEntitySpawn.h b/source/packets/cPacket_NamedEntitySpawn.h
new file mode 100644
index 000000000..1a404f693
--- /dev/null
+++ b/source/packets/cPacket_NamedEntitySpawn.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.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); }
+
+ bool Send( cSocket & a_Socket );
+
+ int m_UniqueID;
+ std::string 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
+};
diff --git a/source/packets/cPacket_PickupSpawn.cpp b/source/packets/cPacket_PickupSpawn.cpp
new file mode 100644
index 000000000..73f4e3846
--- /dev/null
+++ b/source/packets/cPacket_PickupSpawn.cpp
@@ -0,0 +1,40 @@
+#include "cPacket_PickupSpawn.h"
+
+bool cPacket_PickupSpawn::Parse( cSocket & a_Socket )
+{
+ m_Socket = a_Socket;
+ if( !ReadInteger( m_UniqueID ) ) return false;
+ if( !ReadShort ( m_Item ) ) return false;
+ if( !ReadByte ( m_Count ) ) return false;
+ if( !ReadShort ( m_Health ) ) return false;
+ if( !ReadInteger( m_PosX ) ) return false;
+ if( !ReadInteger( m_PosY ) ) return false;
+ if( !ReadInteger( m_PosZ ) ) return false;
+ if( !ReadByte ( m_Rotation ) ) return false;
+ if( !ReadByte ( m_Pitch ) ) return false;
+ if( !ReadByte ( m_Roll ) ) return false;
+ return true;
+}
+
+bool cPacket_PickupSpawn::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_UniqueID, Message, i );
+ AppendShort ( m_Item, Message, i );
+ AppendByte ( m_Count, Message, i );
+ AppendShort ( m_Health, Message, i );
+ AppendInteger( m_PosX, Message, i );
+ AppendInteger( m_PosY, Message, i );
+ AppendInteger( m_PosZ, Message, i );
+ AppendByte ( m_Rotation, Message, i );
+ AppendByte ( m_Pitch, Message, i );
+ AppendByte ( m_Roll, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_PickupSpawn.h b/source/packets/cPacket_PickupSpawn.h
new file mode 100644
index 000000000..c4152eedd
--- /dev/null
+++ b/source/packets/cPacket_PickupSpawn.h
@@ -0,0 +1,38 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_PickupSpawn : public cPacket
+{
+public:
+ cPacket_PickupSpawn()
+ : m_UniqueID( 0 )
+ , m_Item( 0 )
+ , m_Count( 0 )
+ , m_Health( 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); }
+
+ bool Parse( cSocket & a_Socket );
+ bool Send( cSocket & a_Socket );
+
+ int m_UniqueID;
+ short m_Item;
+ char m_Count;
+ short m_Health;
+ int m_PosX;
+ int m_PosY;
+ int m_PosZ;
+ char m_Rotation;
+ char m_Pitch;
+ char m_Roll;
+
+ static const unsigned int c_Size = 1 + 4 + 2 + 1 + 2 + 4 + 4 + 4 + 1 + 1 + 1;
+};
diff --git a/source/packets/cPacket_Ping.h b/source/packets/cPacket_Ping.h
new file mode 100644
index 000000000..abab822a4
--- /dev/null
+++ b/source/packets/cPacket_Ping.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_Ping : public cPacket
+{
+public:
+ cPacket_Ping()
+ { m_PacketID = E_PING; }
+ virtual cPacket* Clone() const { return new cPacket_Ping(*this); }
+
+ bool Parse(cSocket & a_Socket) { (void)a_Socket; return true; }
+
+ static const unsigned int c_Size = 1;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_PlayerLook.cpp b/source/packets/cPacket_PlayerLook.cpp
new file mode 100644
index 000000000..2660ccf92
--- /dev/null
+++ b/source/packets/cPacket_PlayerLook.cpp
@@ -0,0 +1,36 @@
+#include "cPacket_PlayerLook.h"
+#include "../cPlayer.h"
+
+cPacket_PlayerLook::cPacket_PlayerLook( cPlayer* a_Player )
+{
+ m_PacketID = E_PLAYERLOOK;
+
+ m_Rotation = a_Player->GetRotation();
+ m_Pitch = a_Player->GetPitch();
+ m_bFlying = a_Player->GetFlying();
+}
+
+bool cPacket_PlayerLook::Parse( cSocket & a_Socket )
+{
+ m_Socket = a_Socket;
+ if( !ReadFloat( m_Rotation ) ) return false;
+ if( !ReadFloat( m_Pitch ) ) return false;
+ if( !ReadBool ( m_bFlying ) ) return false;
+ return true;
+}
+
+bool cPacket_PlayerLook::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendFloat ( m_Rotation, Message, i );
+ AppendFloat ( m_Pitch, Message, i );
+ AppendBool ( m_bFlying, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( cPacket::SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_PlayerLook.h b/source/packets/cPacket_PlayerLook.h
new file mode 100644
index 000000000..1f315a78b
--- /dev/null
+++ b/source/packets/cPacket_PlayerLook.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPlayer;
+class cPacket_PlayerLook : public cPacket
+{
+public:
+ cPacket_PlayerLook()
+ : m_Rotation( 0 )
+ , m_Pitch( 0 )
+ , m_bFlying( false )
+ { m_PacketID = E_PLAYERLOOK; }
+ cPacket_PlayerLook( cPlayer* a_Player );
+ virtual cPacket* Clone() const { return new cPacket_PlayerLook(*this); }
+
+ bool Parse( cSocket & a_Socket );
+ bool Send( cSocket & a_Socket );
+
+ float m_Rotation;
+ float m_Pitch;
+ bool m_bFlying; // Yeah.. wtf
+ static const unsigned int c_Size = 10;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_PlayerMoveLook.cpp b/source/packets/cPacket_PlayerMoveLook.cpp
new file mode 100644
index 000000000..f1d67478c
--- /dev/null
+++ b/source/packets/cPacket_PlayerMoveLook.cpp
@@ -0,0 +1,50 @@
+#include "cPacket_PlayerMoveLook.h"
+#include "../cPlayer.h"
+
+cPacket_PlayerMoveLook::cPacket_PlayerMoveLook( cPlayer* a_Player )
+{
+ m_PacketID = E_PLAYERMOVELOOK;
+
+
+ m_PosX = a_Player->GetPosX();
+ m_PosY = a_Player->GetPosY() + 1.65;
+ m_PosZ = a_Player->GetPosZ();
+ m_Stance = a_Player->GetStance();
+ m_Rotation = a_Player->GetRotation();
+ m_Pitch = a_Player->GetPitch();
+ m_bFlying = a_Player->GetFlying();
+}
+
+bool cPacket_PlayerMoveLook::Parse( cSocket & a_Socket )
+{
+ m_Socket = a_Socket;
+
+ if( !ReadDouble( m_PosX ) ) return false;
+ if( !ReadDouble( m_PosY ) ) return false;
+ if( !ReadDouble( m_Stance ) ) return false;
+ if( !ReadDouble( m_PosZ ) ) return false;
+ if( !ReadFloat ( m_Rotation ) ) return false;
+ if( !ReadFloat ( m_Pitch ) ) return false;
+ if( !ReadBool ( m_bFlying ) ) return false;
+ return true;
+}
+
+bool cPacket_PlayerMoveLook::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendDouble( m_PosX, Message, i );
+ AppendDouble( m_PosY, Message, i );
+ AppendDouble( m_Stance, Message, i );
+ AppendDouble( m_PosZ, Message, i );
+ AppendFloat ( m_Rotation, Message, i );
+ AppendFloat ( m_Pitch, Message, i );
+ AppendBool ( m_bFlying, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_PlayerMoveLook.h b/source/packets/cPacket_PlayerMoveLook.h
new file mode 100644
index 000000000..3711e0e58
--- /dev/null
+++ b/source/packets/cPacket_PlayerMoveLook.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPlayer;
+class cPacket_PlayerMoveLook : public cPacket
+{
+public:
+ cPacket_PlayerMoveLook()
+ : m_PosX( 0.0 )
+ , m_PosY( 0.0 )
+ , m_Stance( 0.0 )
+ , m_PosZ( 0.0 )
+ , m_Rotation( 0.f )
+ , m_Pitch( 0.f )
+ , m_bFlying( false )
+ { m_PacketID = E_PLAYERMOVELOOK; }
+ cPacket_PlayerMoveLook( cPlayer* a_Player );
+ virtual cPacket* Clone() const { return new cPacket_PlayerMoveLook(*this); }
+
+ virtual bool Parse(cSocket & a_Socket);
+ virtual bool Send(cSocket & a_Socket);
+
+ double m_PosX;
+ double m_PosY;
+ double m_Stance;
+ double m_PosZ;
+ float m_Rotation;
+ float m_Pitch;
+ bool m_bFlying; // Yeah.. wtf
+ static const unsigned int c_Size = 42;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_PlayerPosition.cpp b/source/packets/cPacket_PlayerPosition.cpp
new file mode 100644
index 000000000..eb17bc7e5
--- /dev/null
+++ b/source/packets/cPacket_PlayerPosition.cpp
@@ -0,0 +1,42 @@
+#include "cPacket_PlayerPosition.h"
+#include "cPlayer.h"
+
+cPacket_PlayerPosition::cPacket_PlayerPosition( cPlayer* a_Player )
+{
+ m_PacketID = E_PLAYERPOS;
+
+ m_PosX = a_Player->GetPosX();
+ m_PosY = a_Player->GetPosY() + 1.65;
+ m_PosZ = a_Player->GetPosZ();
+ m_Stance = a_Player->GetStance();
+ m_bFlying = a_Player->GetFlying();
+}
+
+bool cPacket_PlayerPosition::Parse(cSocket & a_Socket)
+{
+ m_Socket = a_Socket;
+ if( !ReadDouble( m_PosX ) ) return false;
+ if( !ReadDouble( m_PosY ) ) return false;
+ if( !ReadDouble( m_Stance ) ) return false;
+ if( !ReadDouble( m_PosZ ) ) return false;
+ if( !ReadBool( m_bFlying ) ) return false;
+ return true;
+}
+
+bool cPacket_PlayerPosition::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendDouble ( m_PosX, Message, i );
+ AppendDouble ( m_PosY, Message, i );
+ AppendDouble ( m_Stance, Message, i );
+ AppendDouble ( m_PosZ, Message, i );
+ AppendBool ( m_bFlying, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_PlayerPosition.h b/source/packets/cPacket_PlayerPosition.h
new file mode 100644
index 000000000..d9c68a2e6
--- /dev/null
+++ b/source/packets/cPacket_PlayerPosition.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPlayer;
+class cPacket_PlayerPosition : public cPacket
+{
+public:
+ cPacket_PlayerPosition( cPlayer* a_Player );
+ cPacket_PlayerPosition()
+ : m_PosX( 0.0 )
+ , m_PosY( 0.0 )
+ , m_Stance( 0.0 )
+ , m_PosZ( 0.0 )
+ , m_bFlying( false )
+ { m_PacketID = E_PLAYERPOS; }
+ virtual cPacket* Clone() const { return new cPacket_PlayerPosition(*this); }
+
+ virtual bool Parse(cSocket & a_Socket);
+ virtual bool Send(cSocket & a_Socket);
+
+ double m_PosX;
+ double m_PosY;
+ double m_Stance;
+ double m_PosZ;
+ bool m_bFlying; // Yeah.. wtf
+ static const unsigned int c_Size = 34;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_PreChunk.cpp b/source/packets/cPacket_PreChunk.cpp
new file mode 100644
index 000000000..686984a1e
--- /dev/null
+++ b/source/packets/cPacket_PreChunk.cpp
@@ -0,0 +1,17 @@
+#include "cPacket_PreChunk.h"
+
+bool cPacket_PreChunk::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_PosX, Message, i );
+ AppendInteger( m_PosZ, Message, i );
+ AppendBool ( m_bLoad, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
diff --git a/source/packets/cPacket_PreChunk.h b/source/packets/cPacket_PreChunk.h
new file mode 100644
index 000000000..a6bd4897e
--- /dev/null
+++ b/source/packets/cPacket_PreChunk.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_PreChunk: public cPacket
+{
+public:
+ cPacket_PreChunk()
+ : m_PosX( 0 )
+ , m_PosZ( 0 )
+ , m_bLoad( false )
+ { m_PacketID = E_PRE_CHUNK; }
+ virtual cPacket* Clone() const { return new cPacket_PreChunk(*this); }
+
+ bool Send(cSocket & a_Socket);
+
+ int m_PosX;
+ int m_PosZ;
+ bool m_bLoad;
+ static const unsigned int c_Size = 10;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_RelativeEntityMove.cpp b/source/packets/cPacket_RelativeEntityMove.cpp
new file mode 100644
index 000000000..4a1dc56b2
--- /dev/null
+++ b/source/packets/cPacket_RelativeEntityMove.cpp
@@ -0,0 +1,18 @@
+#include "cPacket_RelativeEntityMove.h"
+
+bool cPacket_RelativeEntityMove::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_UniqueID, Message, i );
+ AppendByte ( m_MoveX, Message, i );
+ AppendByte ( m_MoveY, Message, i );
+ AppendByte ( m_MoveZ, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
diff --git a/source/packets/cPacket_RelativeEntityMove.h b/source/packets/cPacket_RelativeEntityMove.h
new file mode 100644
index 000000000..03d895b38
--- /dev/null
+++ b/source/packets/cPacket_RelativeEntityMove.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.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); }
+
+ bool Send( cSocket & a_Socket );
+
+ 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;
+};
diff --git a/source/packets/cPacket_RelativeEntityMoveLook.cpp b/source/packets/cPacket_RelativeEntityMoveLook.cpp
new file mode 100644
index 000000000..e879870cd
--- /dev/null
+++ b/source/packets/cPacket_RelativeEntityMoveLook.cpp
@@ -0,0 +1,20 @@
+#include "cPacket_RelativeEntityMoveLook.h"
+
+bool cPacket_RelativeEntityMoveLook::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_UniqueID, Message, i );
+ AppendByte ( m_MoveX, Message, i );
+ AppendByte ( m_MoveY, Message, i );
+ AppendByte ( m_MoveZ, Message, i );
+ AppendByte ( m_Yaw, Message, i );
+ AppendByte ( m_Pitch, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
diff --git a/source/packets/cPacket_RelativeEntityMoveLook.h b/source/packets/cPacket_RelativeEntityMoveLook.h
new file mode 100644
index 000000000..cb54db159
--- /dev/null
+++ b/source/packets/cPacket_RelativeEntityMoveLook.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.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); }
+
+ bool Send( cSocket & a_Socket );
+
+ 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;
+};
diff --git a/source/packets/cPacket_Respawn.cpp b/source/packets/cPacket_Respawn.cpp
new file mode 100644
index 000000000..e12ea1ace
--- /dev/null
+++ b/source/packets/cPacket_Respawn.cpp
@@ -0,0 +1,31 @@
+#include "cPacket_Respawn.h"
+
+bool cPacket_Respawn::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size;
+
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendByte ( m_World, Message, i );
+ AppendByte ( m_Difficulty, Message, i );
+ AppendByte ( m_CreativeMode, Message, i );
+ AppendShort ( m_WorldHeight, Message, i );
+ AppendLong ( m_MapSeed, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
+
+bool cPacket_Respawn::Parse(cSocket & a_Socket)
+{
+ m_Socket = a_Socket;
+ if( !ReadByte( m_World ) ) return false;
+ if( !ReadByte( m_Difficulty ) ) return false;
+ if( !ReadByte( m_CreativeMode ) ) return false;
+ if( !ReadShort( m_WorldHeight ) ) return false;
+ if( !ReadLong( m_MapSeed ) ) return false;
+ return true;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_Respawn.h b/source/packets/cPacket_Respawn.h
new file mode 100644
index 000000000..ab8fbe72a
--- /dev/null
+++ b/source/packets/cPacket_Respawn.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_Respawn : public cPacket
+{
+public:
+ cPacket_Respawn()
+ : m_World( 0 )
+ , m_Difficulty( 0 )
+ , m_CreativeMode( 0 )
+ , m_WorldHeight( 0 )
+ , m_MapSeed( 0 )
+ { m_PacketID = E_RESPAWN; }
+ virtual cPacket* Clone() const { return new cPacket_Respawn( *this ); }
+
+ bool Send(cSocket & a_Socket);
+ bool Parse(cSocket & a_Socket);
+
+ char m_World;
+ char m_Difficulty;
+ char m_CreativeMode;
+ short m_WorldHeight;
+ long long m_MapSeed;
+
+ static const unsigned int c_Size = 1 + 1 + 1 + 1 + 2 + 8;
+};
diff --git a/source/packets/cPacket_SpawnMob.cpp b/source/packets/cPacket_SpawnMob.cpp
new file mode 100644
index 000000000..8de03f04b
--- /dev/null
+++ b/source/packets/cPacket_SpawnMob.cpp
@@ -0,0 +1,60 @@
+#include "cPacket_SpawnMob.h"
+#include "Vector3i.h"
+
+#include "cMCLogger.h"
+
+cPacket_SpawnMob::~cPacket_SpawnMob()
+{
+ if( m_MetaData ) delete [] m_MetaData;
+ delete m_Pos;
+}
+
+cPacket_SpawnMob::cPacket_SpawnMob()
+ : m_UniqueID( 0 )
+ , m_Type( 0 )
+ , m_Pos( new Vector3i() )
+ , m_Yaw( 0 )
+ , m_Pitch( 0 )
+ , m_MetaDataSize( 0 )
+ , m_MetaData( 0 )
+{
+ m_PacketID = E_SPAWN_MOB;
+}
+
+cPacket_SpawnMob::cPacket_SpawnMob( const cPacket_SpawnMob & a_Clone )
+{
+ m_Pos = new Vector3i();
+
+ 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_MetaDataSize = a_Clone.m_MetaDataSize;
+ m_MetaData = new char[m_MetaDataSize];
+ memcpy( m_MetaData, a_Clone.m_MetaData, sizeof( char ) * m_MetaDataSize );
+}
+
+bool cPacket_SpawnMob::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size + m_MetaDataSize;
+
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger ( m_UniqueID, Message, i );
+ AppendByte ( m_Type, Message, i );
+ AppendInteger ( m_Pos->x, Message, i );
+ AppendInteger ( m_Pos->y, Message, i );
+ AppendInteger ( m_Pos->z, Message, i );
+ AppendByte ( m_Yaw, Message, i );
+ AppendByte ( m_Pitch, Message, i );
+ AppendData ( m_MetaData, m_MetaDataSize, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
diff --git a/source/packets/cPacket_SpawnMob.h b/source/packets/cPacket_SpawnMob.h
new file mode 100644
index 000000000..bd7c75464
--- /dev/null
+++ b/source/packets/cPacket_SpawnMob.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class Vector3i;
+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();
+
+ bool Send(cSocket & a_Socket);
+
+ int m_UniqueID;
+ char m_Type;
+ Vector3i* m_Pos;
+ char m_Yaw;
+ char m_Pitch;
+
+ static const unsigned int c_Size = 1 + 4 + 1 + 4 + 4 + 4 + 1 + 1; // + metadata
+
+ unsigned int m_MetaDataSize;
+ char* m_MetaData;
+};
diff --git a/source/packets/cPacket_TeleportEntity.cpp b/source/packets/cPacket_TeleportEntity.cpp
new file mode 100644
index 000000000..73c7c0524
--- /dev/null
+++ b/source/packets/cPacket_TeleportEntity.cpp
@@ -0,0 +1,34 @@
+#include "cPacket_TeleportEntity.h"
+
+#include "cEntity.h"
+
+cPacket_TeleportEntity::cPacket_TeleportEntity(cEntity* a_Client)
+{
+ m_PacketID = E_ENT_TELEPORT;
+
+ m_UniqueID = a_Client->GetUniqueID();
+ m_PosX = (int)(a_Client->GetPosX() * 32);
+ m_PosY = (int)(a_Client->GetPosY() * 32);
+ m_PosZ = (int)(a_Client->GetPosZ() * 32);
+ m_Rotation = (char)((a_Client->GetRotation()/360.f)*256);
+ m_Pitch = (char)((a_Client->GetPitch()/360.f)*256);
+}
+
+bool cPacket_TeleportEntity::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger( m_UniqueID, Message, i );
+ AppendInteger( m_PosX, Message, i );
+ AppendInteger( m_PosY, Message, i );
+ AppendInteger( m_PosZ, Message, i );
+ AppendByte ( m_Rotation, Message, i );
+ AppendByte ( m_Pitch, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
diff --git a/source/packets/cPacket_TeleportEntity.h b/source/packets/cPacket_TeleportEntity.h
new file mode 100644
index 000000000..da1f61c60
--- /dev/null
+++ b/source/packets/cPacket_TeleportEntity.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.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(cEntity* a_Client);
+
+ bool Send( cSocket & a_Socket );
+
+ 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;
+};
diff --git a/source/packets/cPacket_TimeUpdate.cpp b/source/packets/cPacket_TimeUpdate.cpp
new file mode 100644
index 000000000..09a9ca66a
--- /dev/null
+++ b/source/packets/cPacket_TimeUpdate.cpp
@@ -0,0 +1,22 @@
+#include "cPacket_TimeUpdate.h"
+
+bool cPacket_TimeUpdate::Parse(cSocket & a_Socket)
+{
+ m_Socket = a_Socket;
+ if( !ReadLong(m_Time) ) return false;
+ return true;
+}
+
+bool cPacket_TimeUpdate::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendLong ( m_Time, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_TimeUpdate.h b/source/packets/cPacket_TimeUpdate.h
new file mode 100644
index 000000000..9913eba2c
--- /dev/null
+++ b/source/packets/cPacket_TimeUpdate.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.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); }
+
+ bool Parse(cSocket & a_Socket);
+ bool Send(cSocket & a_Socket);
+
+ long long m_Time;
+ static const unsigned int c_Size = 1 + 8;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_UpdateHealth.cpp b/source/packets/cPacket_UpdateHealth.cpp
new file mode 100644
index 000000000..f46d159ad
--- /dev/null
+++ b/source/packets/cPacket_UpdateHealth.cpp
@@ -0,0 +1,20 @@
+#include "cPacket_UpdateHealth.h"
+
+#include "cMCLogger.h"
+
+bool cPacket_UpdateHealth::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size;
+
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendShort ( m_Health, Message, i );
+ AppendShort ( m_Food, Message, i );
+ AppendFloat ( m_Saturation, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
diff --git a/source/packets/cPacket_UpdateHealth.h b/source/packets/cPacket_UpdateHealth.h
new file mode 100644
index 000000000..97081e645
--- /dev/null
+++ b/source/packets/cPacket_UpdateHealth.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.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 ); }
+
+ bool Send(cSocket & a_Socket);
+
+ short m_Health;
+ short m_Food;
+ float m_Saturation;
+
+ static const unsigned int c_Size = 1 + 2 + 2 + 4;
+};
diff --git a/source/packets/cPacket_UpdateSign.cpp b/source/packets/cPacket_UpdateSign.cpp
new file mode 100644
index 000000000..f7d3f8618
--- /dev/null
+++ b/source/packets/cPacket_UpdateSign.cpp
@@ -0,0 +1,41 @@
+#include "cPacket_UpdateSign.h"
+
+bool cPacket_UpdateSign::Parse( cSocket & a_Socket )
+{
+ m_Socket = a_Socket;
+
+ if( !ReadInteger( m_PosX ) ) return false;
+ if( !ReadShort ( m_PosY ) ) return false;
+ if( !ReadInteger( m_PosZ ) ) return false;
+ if( !ReadString16 ( m_Line1 ) ) return false;
+ if( !ReadString16 ( m_Line2 ) ) return false;
+ if( !ReadString16 ( m_Line3 ) ) return false;
+ if( !ReadString16 ( m_Line4 ) ) return false;
+
+ return true;
+}
+
+bool cPacket_UpdateSign::Send( cSocket & a_Socket )
+{
+ unsigned int TotalSize = c_Size;
+ TotalSize += m_Line1.size() * sizeof( short );
+ TotalSize += m_Line2.size() * sizeof( short );
+ TotalSize += m_Line3.size() * sizeof( short );
+ TotalSize += m_Line4.size() * sizeof( short );
+
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger ( m_PosX, Message, i );
+ AppendShort ( m_PosY, Message, i );
+ AppendInteger ( m_PosZ, Message, i );
+ AppendString16 ( m_Line1, Message, i );
+ AppendString16 ( m_Line2, Message, i );
+ AppendString16 ( m_Line3, Message, i );
+ AppendString16 ( m_Line4, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_UpdateSign.h b/source/packets/cPacket_UpdateSign.h
new file mode 100644
index 000000000..f23da1540
--- /dev/null
+++ b/source/packets/cPacket_UpdateSign.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_UpdateSign : public cPacket
+{
+public:
+ cPacket_UpdateSign()
+ : m_PosX( 0 )
+ , m_PosY( 0 )
+ , m_PosZ( 0 )
+ { m_PacketID = E_UPDATE_SIGN; }
+ virtual cPacket* Clone() const { return new cPacket_UpdateSign( *this ); }
+
+ bool Parse( cSocket & a_Socket );
+ bool Send( cSocket & a_Socket );
+
+ int m_PosX;
+ short m_PosY;
+ int m_PosZ;
+ std::string m_Line1;
+ std::string m_Line2;
+ std::string m_Line3;
+ std::string m_Line4;
+
+ static const unsigned int c_Size = 1 + 4 + 2 + 4 + 2 + 2 + 2 + 2; // minimum size
+};
diff --git a/source/packets/cPacket_UseEntity.cpp b/source/packets/cPacket_UseEntity.cpp
new file mode 100644
index 000000000..bbe22d3ec
--- /dev/null
+++ b/source/packets/cPacket_UseEntity.cpp
@@ -0,0 +1,10 @@
+#include "cPacket_UseEntity.h"
+
+bool cPacket_UseEntity::Parse(cSocket & a_Socket)
+{
+ m_Socket = a_Socket;
+ if( !ReadInteger(m_UniqueID) ) return false;
+ if( !ReadInteger(m_TargetID) ) return false;
+ if( !ReadBool (m_bLeftClick) ) return false;
+ return true;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_UseEntity.h b/source/packets/cPacket_UseEntity.h
new file mode 100644
index 000000000..cd7b45e79
--- /dev/null
+++ b/source/packets/cPacket_UseEntity.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_UseEntity : public cPacket
+{
+public:
+ cPacket_UseEntity()
+ : m_UniqueID( 0 )
+ , m_TargetID( 0 )
+ , m_bLeftClick( false )
+ { m_PacketID = E_USE_ENTITY; }
+ virtual cPacket* Clone() const { return new cPacket_UseEntity(*this); }
+
+ bool Parse(cSocket & a_Socket);
+
+ int m_UniqueID;
+ int m_TargetID;
+ bool m_bLeftClick;
+
+ static const unsigned int c_Size = 1 + 4 + 4 + 1;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_WholeInventory.cpp b/source/packets/cPacket_WholeInventory.cpp
new file mode 100644
index 000000000..3ee047239
--- /dev/null
+++ b/source/packets/cPacket_WholeInventory.cpp
@@ -0,0 +1,68 @@
+#include "cPacket_WholeInventory.h"
+#include "../cItem.h"
+#include "../cInventory.h"
+#include "../cWindow.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];
+ memcpy( m_Items, a_Clone.m_Items, sizeof(cItem)*m_Count );
+}
+
+cPacket_WholeInventory::cPacket_WholeInventory( cInventory* a_Inventory )
+{
+ m_PacketID = E_INVENTORY_WHOLE;
+ m_WindowID = 0;
+ m_Count = a_Inventory->c_NumSlots;
+ m_Items = new cItem[m_Count];
+ memcpy( m_Items, a_Inventory->GetSlots(), sizeof(cItem)*m_Count );
+}
+
+cPacket_WholeInventory::cPacket_WholeInventory( 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];
+ memcpy( m_Items, a_Window->GetSlots(), sizeof(cItem)*m_Count );
+}
+
+cPacket_WholeInventory::~cPacket_WholeInventory()
+{
+ delete [] m_Items;
+}
+
+bool cPacket_WholeInventory::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size;
+
+ for(int i = 0; i < m_Count; i++)
+ {
+ if( m_Items[i].m_ItemID > -1 )
+ TotalSize+=3;
+ TotalSize+=2;
+ }
+
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendByte ( m_WindowID, Message, i );
+ AppendShort ( m_Count, Message, i );
+ for(int j = 0; j < m_Count; j++)
+ {
+ AppendShort ( (short)m_Items[j].m_ItemID, Message, i );
+ if( m_Items[j].m_ItemID > -1 )
+ {
+ AppendByte ( m_Items[j].m_ItemCount, Message, i );
+ AppendShort ( m_Items[j].m_ItemHealth, Message, i );
+ }
+ }
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_WholeInventory.h b/source/packets/cPacket_WholeInventory.h
new file mode 100644
index 000000000..a2e76658e
--- /dev/null
+++ b/source/packets/cPacket_WholeInventory.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.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( cInventory* a_Inventory );
+ cPacket_WholeInventory( 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); }
+
+ bool Send(cSocket & a_Socket);
+
+ char m_WindowID; // WTF?
+ short m_Count; // Number of items
+
+ cItem* m_Items; // Array of m_Count items
+
+ static const unsigned int c_Size = 1 + 1 + 2; // Minimal size
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_WindowClick.cpp b/source/packets/cPacket_WindowClick.cpp
new file mode 100644
index 000000000..6b295b4d5
--- /dev/null
+++ b/source/packets/cPacket_WindowClick.cpp
@@ -0,0 +1,36 @@
+#include "cPacket_WindowClick.h"
+
+
+bool cPacket_WindowClick::Parse(cSocket & a_Socket)
+{
+// LOG("-----------INV66-----------");
+ m_Socket = a_Socket;
+
+ if( !ReadByte(m_WindowID) ) return false;
+ if( !ReadShort(m_SlotNum) ) return false;
+ if( !ReadByte(m_RightMouse) ) return false;
+ if( !ReadShort(m_NumClicks) ) return false;
+ if( !ReadBool(m_Bool) ) return false;
+
+// LOG("WindowID : %i", m_Type );
+// LOG("FromSlot: %i", m_SlotNum );
+// LOG("Right/Le: %i", m_RightMouse );
+// LOG("NumClick: %i", m_NumClicks );
+
+ if( !ReadShort(m_ItemID) ) return false;
+// LOG("ItemID: %i", m_ItemID );
+ if( m_ItemID > -1 )
+ {
+ if( !ReadByte(m_ItemCount) ) return false;
+ if( !ReadShort(m_ItemUses) ) return false;
+// LOG("Count : %i", m_ItemCount );
+// LOG("Uses : %i", m_ItemUses );
+ }
+ else
+ {
+ m_ItemCount = 0;
+ m_ItemUses = 0;
+ }
+
+ return true;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_WindowClick.h b/source/packets/cPacket_WindowClick.h
new file mode 100644
index 000000000..d6f38e9ab
--- /dev/null
+++ b/source/packets/cPacket_WindowClick.h
@@ -0,0 +1,41 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_WindowClick : public cPacket // [C -> S]
+{
+public:
+ cPacket_WindowClick()
+ : m_WindowID( 0 )
+ , m_SlotNum( 0 )
+ , m_RightMouse( 0 )
+ , m_NumClicks( 0 )
+ , m_Bool( false )
+ , m_ItemID( 0 )
+ , m_ItemCount( 0 )
+ , m_ItemUses( 0 )
+ { m_PacketID = E_WINDOW_CLICK; }
+ virtual cPacket* Clone() const { return new cPacket_WindowClick(*this); }
+
+ bool Parse(cSocket & a_Socket);
+
+ char m_WindowID;
+ short m_SlotNum; // Slot
+ // 0 = craft result
+ // 1-4 = crafting table
+ // 5-8 = armor
+ // 9-35 = inventory
+ // 36-44 = Hot bar
+
+ char m_RightMouse; // 0 = left 1 = Right mb
+ short m_NumClicks; // Num clicks
+ bool m_Bool; // unkown????????????
+
+ // 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 + 1 + 2 + 2; // Minimal size ( +1+1 = max)
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_WindowClose.cpp b/source/packets/cPacket_WindowClose.cpp
new file mode 100644
index 000000000..0881fb703
--- /dev/null
+++ b/source/packets/cPacket_WindowClose.cpp
@@ -0,0 +1,27 @@
+#include "cPacket_WindowClose.h"
+
+bool cPacket_WindowClose::Parse(cSocket & a_Socket)
+{
+ //LOG("CLOSE INVENTORY PACKET");
+ m_Socket = a_Socket;
+
+ if( !ReadByte(m_Close) ) return false;
+
+ //LOG("Closed inventory?: %i", m_Close );
+
+ return true;
+}
+
+bool cPacket_WindowClose::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendByte ( m_Close, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_WindowClose.h b/source/packets/cPacket_WindowClose.h
new file mode 100644
index 000000000..1940eec0a
--- /dev/null
+++ b/source/packets/cPacket_WindowClose.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_WindowClose : public cPacket
+{
+public:
+ cPacket_WindowClose()
+ : m_Close( 0 )
+ { m_PacketID = E_WINDOW_CLOSE; }
+ virtual cPacket* Clone() const { return new cPacket_WindowClose(*this); }
+
+ bool Parse(cSocket & a_Socket);
+ bool Send(cSocket & a_Socket);
+
+ char m_Close; // 1 = close
+
+ static const unsigned int c_Size = 1 + 1;
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_WindowOpen.cpp b/source/packets/cPacket_WindowOpen.cpp
new file mode 100644
index 000000000..5d1299acd
--- /dev/null
+++ b/source/packets/cPacket_WindowOpen.cpp
@@ -0,0 +1,18 @@
+#include "cPacket_WindowOpen.h"
+
+bool cPacket_WindowOpen::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size + m_WindowTitle.size() * sizeof( short );
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendByte ( m_WindowID, Message, i );
+ AppendByte ( m_InventoryType, Message, i );
+ AppendString16( m_WindowTitle, Message, i );
+ AppendByte ( m_NumSlots, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file
diff --git a/source/packets/cPacket_WindowOpen.h b/source/packets/cPacket_WindowOpen.h
new file mode 100644
index 000000000..df05799d5
--- /dev/null
+++ b/source/packets/cPacket_WindowOpen.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.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); }
+
+ bool Send(cSocket & a_Socket);
+
+ char m_WindowID;
+ char m_InventoryType;
+ std::string m_WindowTitle;
+ char m_NumSlots;
+
+ static const unsigned int c_Size = 1 + 1 + 1 + 2 + 1; // + sizeof(string)
+}; \ No newline at end of file