Rewritten all packets to use buffers instead of direct sockets, for future cSocketThreads compatibility.
Moved data sending from cPacket into cSocket git-svn-id: http://mc-server.googlecode.com/svn/trunk@240 0a769ca7-a7f5-676a-18bf-c427514a06d6master
parent
16feb0924e
commit
b7d524423c
|
@ -1,14 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <WinSock.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
// Changes endianness
|
||||
inline unsigned long long HostToNetwork8( void* a_Value )
|
||||
inline unsigned long long HostToNetwork8(const void* a_Value )
|
||||
{
|
||||
unsigned long long __HostToNetwork8;
|
||||
memcpy( &__HostToNetwork8, a_Value, sizeof( __HostToNetwork8 ) );
|
||||
|
@ -16,7 +14,11 @@ inline unsigned long long HostToNetwork8( void* a_Value )
|
|||
return __HostToNetwork8;
|
||||
}
|
||||
|
||||
inline unsigned int HostToNetwork4( void* a_Value )
|
||||
|
||||
|
||||
|
||||
|
||||
inline unsigned int HostToNetwork4(const void* a_Value )
|
||||
{
|
||||
unsigned int __HostToNetwork4;
|
||||
memcpy( &__HostToNetwork4, a_Value, sizeof( __HostToNetwork4 ) );
|
||||
|
@ -24,7 +26,11 @@ inline unsigned int HostToNetwork4( void* a_Value )
|
|||
return __HostToNetwork4;
|
||||
}
|
||||
|
||||
inline double NetworkToHostDouble8( void* a_Value )
|
||||
|
||||
|
||||
|
||||
|
||||
inline double NetworkToHostDouble8(const void* a_Value )
|
||||
{
|
||||
#define ntohll(x) ((((unsigned long long)ntohl((u_long)x)) << 32) + ntohl(x >> 32))
|
||||
unsigned long long buf = 0;//(*(unsigned long long*)a_Value);
|
||||
|
@ -35,14 +41,22 @@ inline double NetworkToHostDouble8( void* a_Value )
|
|||
return x;
|
||||
}
|
||||
|
||||
inline long long NetworkToHostLong8( void* a_Value )
|
||||
|
||||
|
||||
|
||||
|
||||
inline long long NetworkToHostLong8(const void * a_Value )
|
||||
{
|
||||
unsigned long long buf = *(unsigned long long*)a_Value;
|
||||
buf = ntohll(buf);
|
||||
return *reinterpret_cast<long long *>(&buf);
|
||||
}
|
||||
|
||||
inline float NetworkToHostFloat4( void* a_Value )
|
||||
|
||||
|
||||
|
||||
|
||||
inline float NetworkToHostFloat4(const void* a_Value )
|
||||
{
|
||||
u_long buf = *(u_long*)a_Value;
|
||||
buf = ntohl( buf );
|
||||
|
@ -50,3 +64,7 @@ inline float NetworkToHostFloat4( void* a_Value )
|
|||
memcpy( &x, &buf, sizeof(float) );
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h> // for mkdir
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <time.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
|
|
@ -104,7 +104,7 @@ int cBlockingTCPLink::Send(char * a_Data, unsigned int a_Size, int a_Flags /* =
|
|||
LOGERROR("cBlockingTCPLink: Trying to send data without a valid connection!");
|
||||
return -1;
|
||||
}
|
||||
return cPacket::SendData( m_Socket, a_Data, a_Size, a_Flags );
|
||||
return m_Socket.Send(a_Data, a_Size);
|
||||
}
|
||||
|
||||
|
||||
|
@ -119,7 +119,7 @@ int cBlockingTCPLink::SendMessage( const char* a_Message, int a_Flags /* = 0 */
|
|||
LOGWARN("cBlockingTCPLink: Trying to send message without a valid connection!");
|
||||
return -1;
|
||||
}
|
||||
return cPacket::SendData( m_Socket, a_Message, strlen(a_Message), a_Flags );
|
||||
return m_Socket.Send(a_Message, strlen(a_Message));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -190,8 +190,7 @@ cClientHandle::~cClientHandle()
|
|||
{
|
||||
cPacket_Disconnect Disconnect;
|
||||
Disconnect.m_Reason = "Server shut down? Kthnxbai";
|
||||
Disconnect.Send(m_Socket);
|
||||
|
||||
m_Socket.Send(&Disconnect);
|
||||
m_Socket.CloseSocket();
|
||||
}
|
||||
Lock.Unlock();
|
||||
|
@ -1586,7 +1585,7 @@ void cClientHandle::Tick(float a_Dt)
|
|||
if (cWorld::GetTime() - m_TimeLastPacket > 30.f) // 30 seconds time-out
|
||||
{
|
||||
cPacket_Disconnect DC("Nooooo!! You timed out! D: Come back!");
|
||||
DC.Send(m_Socket);
|
||||
m_Socket.Send(&DC);
|
||||
|
||||
cSleep::MilliSleep(1000); // Give packet some time to be received
|
||||
|
||||
|
@ -1731,7 +1730,7 @@ void cClientHandle::SendThread(void *lpParam)
|
|||
{
|
||||
LOGERROR("ERROR: Too many packets in queue for player %s !!", self->m_Username.c_str());
|
||||
cPacket_Disconnect DC("Too many packets in queue.");
|
||||
DC.Send(self->m_Socket);
|
||||
self->m_Socket.Send(DC);
|
||||
|
||||
cSleep::MilliSleep(1000); // Give packet some time to be received
|
||||
|
||||
|
@ -1773,7 +1772,7 @@ void cClientHandle::SendThread(void *lpParam)
|
|||
break;
|
||||
}
|
||||
|
||||
bool bSuccess = Packet->Send(self->m_Socket);
|
||||
bool bSuccess = self->m_Socket.Send(Packet);
|
||||
SocketLock.Unlock();
|
||||
|
||||
if (!bSuccess)
|
||||
|
@ -1806,51 +1805,67 @@ void cClientHandle::ReceiveThread(void *lpParam)
|
|||
|
||||
cClientHandle* self = (cClientHandle*)lpParam;
|
||||
|
||||
|
||||
char temp = 0;
|
||||
int iStat = 0;
|
||||
|
||||
cSocket socket = self->GetSocket();
|
||||
|
||||
while(self->m_bKeepThreadGoing)
|
||||
AString Received;
|
||||
while (self->m_bKeepThreadGoing)
|
||||
{
|
||||
iStat = socket.Receive(&temp, 1, 0);
|
||||
if (cSocket::IsSocketError(iStat) || iStat == 0)
|
||||
char Buffer[1024];
|
||||
iStat = socket.Receive(Buffer, sizeof(Buffer), 0);
|
||||
if (cSocket::IsSocketError(iStat) || (iStat == 0))
|
||||
{
|
||||
LOG("CLIENT DISCONNECTED (%i bytes):%s", iStat, GetWSAError().c_str());
|
||||
LOG("CLIENT DISCONNECTED (%i bytes):%s", iStat, cSocket::GetLastErrorString().c_str());
|
||||
break;
|
||||
}
|
||||
else
|
||||
Received.append(Buffer, iStat);
|
||||
|
||||
// Parse all complete packets in Received:
|
||||
while (!Received.empty())
|
||||
{
|
||||
cPacket* pPacket = self->m_PacketMap[(unsigned char)temp];
|
||||
cPacket* pPacket = self->m_PacketMap[(unsigned char)Received[0]];
|
||||
if (pPacket)
|
||||
{
|
||||
if (pPacket->Parse(socket))
|
||||
int NumBytes = pPacket->Parse(Received.data() + 1, Received.size() - 1);
|
||||
if (NumBytes == PACKET_ERROR)
|
||||
{
|
||||
self->AddPacket(pPacket);
|
||||
//self->HandlePendingPackets();
|
||||
LOGERROR("Protocol error while parsing packet type 0x%x; disconnecting client \"%s\"", Received[0], self->m_Username.c_str());
|
||||
cPacket_Disconnect DC("Protocol error");
|
||||
socket.Send(&DC);
|
||||
|
||||
cSleep::MilliSleep(1000); // Give packet some time to be received
|
||||
return;
|
||||
}
|
||||
else if (NumBytes == PACKET_INCOMPLETE)
|
||||
{
|
||||
// Not a complete packet
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR("Something went wrong during PacketID 0x%02x (%s)", temp, cSocket::GetErrorString( cSocket::GetLastError() ).c_str());
|
||||
LOG("CLIENT %s DISCONNECTED", self->m_Username.c_str());
|
||||
break;
|
||||
// Packet parsed successfully, add it to internal queue:
|
||||
self->AddPacket(pPacket);
|
||||
// Erase the packet from the buffer:
|
||||
assert(Received.size() > (size_t)NumBytes);
|
||||
Received.erase(0, NumBytes + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG("Unknown packet: 0x%02x \'%c\' %i", (unsigned char)temp, (unsigned char)temp, (unsigned char)temp);
|
||||
LOGERROR("Unknown packet type: 0x%2x", Received[0]);
|
||||
|
||||
AString Reason;
|
||||
Printf(Reason, "[C->S] Unknown PacketID: 0x%02x", (unsigned char)temp);
|
||||
Printf(Reason, "[C->S] Unknown PacketID: 0x%02x", Received[0]);
|
||||
cPacket_Disconnect DC(Reason);
|
||||
DC.Send(socket);
|
||||
socket.Send(&DC);
|
||||
|
||||
cSleep::MilliSleep(1000); // Give packet some time to be received
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // while (!Received.empty())
|
||||
} // while (self->m_bKeepThreadGoing)
|
||||
|
||||
self->Destroy();
|
||||
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||
|
||||
#include "cSocket.h"
|
||||
#include "packets/cPacket.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
// #include <sys/socket.h>
|
||||
// #include <netinet/in.h>
|
||||
#include <arpa/inet.h> //inet_ntoa()
|
||||
#else
|
||||
#define socklen_t int
|
||||
|
@ -273,6 +272,28 @@ int cSocket::Send(const char * a_Buffer, unsigned int a_Length)
|
|||
|
||||
|
||||
|
||||
int cSocket::Send(const cPacket * a_Packet)
|
||||
{
|
||||
AString Serialized;
|
||||
a_Packet->Serialize(Serialized);
|
||||
return Send(Serialized.data(), Serialized.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int cSocket::Send(const cPacket & a_Packet)
|
||||
{
|
||||
AString Serialized;
|
||||
a_Packet.Serialize(Serialized);
|
||||
return Send(Serialized.data(), Serialized.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
unsigned short cSocket::GetPort(void) const
|
||||
{
|
||||
assert(IsValid());
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
|
||||
|
||||
|
||||
class cPacket;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cSocket
|
||||
{
|
||||
public:
|
||||
|
@ -63,6 +69,8 @@ public:
|
|||
int Connect(SockAddr_In & a_Address); // Returns 0 on success, !0 on failure
|
||||
int Receive( char* a_Buffer, unsigned int a_Length, unsigned int a_Flags );
|
||||
int Send (const char * a_Buffer, unsigned int a_Length);
|
||||
int Send (const cPacket * a_Packet); // Sends the packet, doesn't handle partial sends
|
||||
int Send (const cPacket & a_Packet); // Sends the packet, doesn't handle partial sends
|
||||
|
||||
unsigned short GetPort(void) const; // Returns 0 on failure
|
||||
|
||||
|
|
|
@ -4,226 +4,303 @@
|
|||
#include "cPacket.h"
|
||||
#include "../Endianness.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define MSG_NOSIGNAL (0)
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
// These checks cannot be done in preprocessor, since sizeof() is evaluated while compiling, so in preprocessing it's unknown.
|
||||
// Check some basic type assumptions:
|
||||
#if (sizeof(int) != 4)
|
||||
#error "Bad size for int, protocol won't work"
|
||||
#endif
|
||||
|
||||
#ifdef __MAC_NA
|
||||
#define MSG_NOSIGNAL (0)
|
||||
#if (sizeof(float) != 4)
|
||||
#error "Bad size for float, protocol won't work"
|
||||
#endif
|
||||
|
||||
#if (sizeof(double) != 8)
|
||||
#error "Bad size for double, protocol won't work"
|
||||
#endif
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
// Blocking receive all function
|
||||
//*****************************************************************************
|
||||
int cPacket::RecvAll( cSocket & 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( cSocket & 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 )
|
||||
|
||||
int cPacket::ReadString16(const char * a_Data, int a_Size, AString & a_OutString )
|
||||
{
|
||||
int TotalBytes = 0;
|
||||
short StrLen;
|
||||
if(!ReadShort( StrLen )) return false;
|
||||
HANDLE_PACKET_READ(ReadShort, StrLen, TotalBytes);
|
||||
|
||||
if( StrLen == 0 )
|
||||
if (2 * StrLen > a_Size - TotalBytes)
|
||||
{
|
||||
a_OutString.clear();
|
||||
return true;
|
||||
// The string is not yet complete in the buffer
|
||||
return PACKET_INCOMPLETE;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// Simple UTF-16 to UTF-8 conversion - discard higher bits, ignore multishort sequences:
|
||||
a_OutString.clear();
|
||||
if( StrLen == 0 )
|
||||
a_OutString.reserve(StrLen);
|
||||
short * UTF16 = (short *)(a_Data + TotalBytes);
|
||||
for ( int i = 0; i < StrLen; ++i )
|
||||
{
|
||||
return true;
|
||||
a_OutString.push_back( (char)ntohs(UTF16[i]) );
|
||||
}
|
||||
|
||||
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;
|
||||
return TotalBytes + StrLen * sizeof(short);
|
||||
}
|
||||
|
||||
bool cPacket::ReadShort( short & a_OutShort )
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket::ReadShort(const char * a_Data, int a_Size, short & a_OutShort )
|
||||
{
|
||||
if( cSocket::IsSocketError( RecvAll( m_Socket, (char*)&a_OutShort, sizeof(short), 0 ) ) ) return false;
|
||||
a_OutShort = ntohs(a_OutShort);
|
||||
return true;
|
||||
if (a_Size < 2)
|
||||
{
|
||||
return PACKET_INCOMPLETE;
|
||||
}
|
||||
a_OutShort = ntohs(*((short *)a_Data));
|
||||
return 2;
|
||||
}
|
||||
|
||||
bool cPacket::ReadInteger( int & a_OutInteger )
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket::ReadInteger(const char * a_Data, int a_Size, int & a_OutInteger )
|
||||
{
|
||||
if( cSocket::IsSocketError( RecvAll( m_Socket, (char*)&a_OutInteger, sizeof(int), 0 ) ) ) return false;
|
||||
a_OutInteger = ntohl(a_OutInteger);
|
||||
return true;
|
||||
if (a_Size < 4)
|
||||
{
|
||||
return PACKET_INCOMPLETE;
|
||||
}
|
||||
a_OutInteger = ntohl(*((int *)a_Data));
|
||||
return 4;
|
||||
}
|
||||
|
||||
bool cPacket::ReadInteger( unsigned int & a_OutInteger )
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket::ReadInteger(const char * a_Data, int a_Size, 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;
|
||||
if (a_Size < 4)
|
||||
{
|
||||
return PACKET_INCOMPLETE;
|
||||
}
|
||||
a_OutInteger = ntohl(*((unsigned int *)a_Data));
|
||||
return 4;
|
||||
}
|
||||
|
||||
bool cPacket::ReadFloat( float & a_OutFloat )
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket::ReadFloat(const char * a_Data, int a_Size, float & a_OutFloat )
|
||||
{
|
||||
if( cSocket::IsSocketError( RecvAll( m_Socket, (char*)&a_OutFloat, sizeof(float), 0 ) ) ) return false;
|
||||
a_OutFloat = NetworkToHostFloat4( &a_OutFloat );
|
||||
return true;
|
||||
if (a_Size < sizeof(float))
|
||||
{
|
||||
return PACKET_INCOMPLETE;
|
||||
}
|
||||
a_OutFloat = NetworkToHostFloat4(a_Data);
|
||||
return sizeof(float);
|
||||
}
|
||||
|
||||
bool cPacket::ReadDouble( double & a_OutDouble )
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket::ReadDouble(const char * a_Data, int a_Size, double & a_OutDouble )
|
||||
{
|
||||
if( cSocket::IsSocketError( RecvAll( m_Socket, (char*)&a_OutDouble, sizeof(double), 0 ) ) ) return false;
|
||||
a_OutDouble = NetworkToHostDouble8( &a_OutDouble );
|
||||
return true;
|
||||
if (a_Size < sizeof(double))
|
||||
{
|
||||
return PACKET_INCOMPLETE;
|
||||
}
|
||||
a_OutDouble = NetworkToHostDouble8(a_Data);
|
||||
return sizeof(double);
|
||||
}
|
||||
|
||||
bool cPacket::ReadByte( char & a_OutByte )
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket::ReadByte(const char * a_Data, int a_Size, char & a_OutByte )
|
||||
{
|
||||
return !cSocket::IsSocketError( RecvAll( m_Socket, (char*)&a_OutByte, sizeof(char), 0 ) );
|
||||
if (a_Size < 1)
|
||||
{
|
||||
return PACKET_INCOMPLETE;
|
||||
}
|
||||
a_OutByte = *a_Data;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool cPacket::ReadByte( unsigned char & a_OutByte )
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket::ReadByte(const char * a_Data, int a_Size, unsigned char & a_OutByte )
|
||||
{
|
||||
return !cSocket::IsSocketError(RecvAll( m_Socket, (char*)&a_OutByte, sizeof(char), 0 ) );
|
||||
if (a_Size < 1)
|
||||
{
|
||||
return PACKET_INCOMPLETE;
|
||||
}
|
||||
a_OutByte = *((unsigned char *)a_Data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool cPacket::ReadLong( long long & a_OutLong )
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket::ReadLong(const char * a_Data, int a_Size, 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;
|
||||
if (a_Size < sizeof(a_OutLong))
|
||||
{
|
||||
return PACKET_INCOMPLETE;
|
||||
}
|
||||
a_OutLong = NetworkToHostLong8(a_Data);
|
||||
return sizeof(a_OutLong);
|
||||
}
|
||||
|
||||
bool cPacket::ReadBool( bool & a_OutBool )
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket::ReadBool(const char * a_Data, int a_Size, bool & a_OutBool )
|
||||
{
|
||||
if( cSocket::IsSocketError(RecvAll( m_Socket, (char*)&a_OutBool, sizeof(bool), 0 ) ) ) return false;
|
||||
return true;
|
||||
if (a_Size < sizeof(bool))
|
||||
{
|
||||
return PACKET_INCOMPLETE;
|
||||
}
|
||||
a_OutBool = (*a_Data != 0);
|
||||
return sizeof(bool);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// Append variables to a c-String
|
||||
//*****************************************************************************
|
||||
void cPacket::AppendString( std::string & a_String, char* a_Dst, unsigned int & a_Iterator )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket::AppendString(AString & a_Dst, const AString & a_String)
|
||||
{
|
||||
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();
|
||||
AppendShort(a_Dst, (unsigned short)a_String.size());
|
||||
a_Dst.append(a_String);
|
||||
}
|
||||
|
||||
void cPacket::AppendString16( std::string & a_String, char* a_Dst, unsigned int & a_Iterator )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket::AppendString16(AString & a_Dst, const AString & a_String)
|
||||
{
|
||||
AppendShort( (unsigned short)a_String.size(), a_Dst, a_Iterator );
|
||||
char* UTF16 = new char[ a_String.size() * sizeof( short ) ];
|
||||
AppendShort(a_Dst, (unsigned short)a_String.size());
|
||||
std::auto_ptr<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];
|
||||
UTF16.get()[i * sizeof( short )] = 0x00;
|
||||
UTF16.get()[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;
|
||||
a_Dst.append(UTF16.get(), a_String.size() * sizeof(short));
|
||||
}
|
||||
|
||||
void cPacket::AppendShort( short a_Short, char *a_Dst, unsigned int &a_Iterator )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket::AppendShort(AString & a_Dst, short a_Short)
|
||||
{
|
||||
short ConvertedShort = htons( a_Short );
|
||||
memcpy( a_Dst + a_Iterator, &ConvertedShort, sizeof( short ) ); a_Iterator+=sizeof( short );
|
||||
a_Dst.append((const char *)&ConvertedShort, sizeof(short));
|
||||
}
|
||||
|
||||
void cPacket::AppendShort( unsigned short a_Short, char *a_Dst, unsigned int &a_Iterator )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket::AppendShort(AString & a_Dst, unsigned short a_Short)
|
||||
{
|
||||
short ConvertedShort = htons( a_Short );
|
||||
memcpy( a_Dst + a_Iterator, &ConvertedShort, sizeof( unsigned short ) ); a_Iterator+=sizeof( unsigned short );
|
||||
a_Dst.append((const char *)&ConvertedShort, sizeof(short));
|
||||
}
|
||||
|
||||
|
||||
void cPacket::AppendInteger( int a_Integer, char* a_Dst, unsigned int & a_Iterator )
|
||||
|
||||
|
||||
|
||||
void cPacket::AppendInteger(AString & a_Dst, int a_Integer)
|
||||
{
|
||||
int ConvertedInt = htonl( a_Integer );
|
||||
memcpy( a_Dst + a_Iterator, &ConvertedInt, sizeof( int ) ); a_Iterator+=sizeof( int );
|
||||
a_Dst.append((const char *)&ConvertedInt, sizeof(int));
|
||||
}
|
||||
|
||||
void cPacket::AppendInteger( unsigned int a_Integer, char* a_Dst, unsigned int & a_Iterator )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket::AppendInteger(AString & a_Dst, unsigned int a_Integer)
|
||||
{
|
||||
unsigned int ConvertedInt = htonl( a_Integer );
|
||||
memcpy( a_Dst + a_Iterator, &ConvertedInt, sizeof( unsigned int ) ); a_Iterator+=sizeof( unsigned int );
|
||||
a_Dst.append((const char *)&ConvertedInt, sizeof(int));
|
||||
}
|
||||
|
||||
void cPacket::AppendFloat( float a_Float, char* a_Dst, unsigned int & a_Iterator )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket::AppendFloat(AString & a_Dst, float a_Float)
|
||||
{
|
||||
unsigned int ConvertedFloat = HostToNetwork4(&a_Float);
|
||||
memcpy( a_Dst + a_Iterator, &ConvertedFloat, sizeof(float) ); a_Iterator += sizeof(float);
|
||||
a_Dst.append((const char *)&ConvertedFloat, sizeof(int));
|
||||
}
|
||||
|
||||
void cPacket::AppendDouble( double & a_Double, char* a_Dst, unsigned int & a_Iterator )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket::AppendDouble(AString & a_Dst, const double & a_Double)
|
||||
{
|
||||
unsigned long long ConvertedDouble = HostToNetwork8(&a_Double);
|
||||
memcpy( a_Dst + a_Iterator, &ConvertedDouble, sizeof(double) ); a_Iterator += sizeof(double);
|
||||
a_Dst.append((const char *)&ConvertedDouble, 8);
|
||||
}
|
||||
|
||||
void cPacket::AppendByte( char a_Byte, char* a_Dst, unsigned int & a_Iterator )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket::AppendByte(AString & a_Dst, char a_Byte)
|
||||
{
|
||||
a_Dst[a_Iterator] = a_Byte; a_Iterator+=sizeof(char);
|
||||
a_Dst.append(&a_Byte, 1);
|
||||
}
|
||||
|
||||
void cPacket::AppendLong( long long & a_Long, char* a_Dst, unsigned int & a_Iterator )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket::AppendLong(AString & a_Dst, const long long & a_Long)
|
||||
{
|
||||
unsigned long long ConvertedLong = HostToNetwork8(&a_Long);
|
||||
memcpy( a_Dst + a_Iterator, &ConvertedLong, sizeof(long long) );
|
||||
a_Iterator += sizeof( long long );
|
||||
a_Dst.append((const char *)&ConvertedLong, sizeof(a_Long));
|
||||
}
|
||||
|
||||
void cPacket::AppendBool( bool a_Bool, char* a_Dst, unsigned int & a_Iterator )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket::AppendBool(AString & a_Dst, bool a_Bool)
|
||||
{
|
||||
a_Dst[a_Iterator] = (char)a_Bool; a_Iterator+=sizeof(bool);
|
||||
a_Dst.append((const char *)&a_Bool, 1);
|
||||
}
|
||||
|
||||
void cPacket::AppendData( char* a_Data, unsigned int a_Size, char* a_Dst, unsigned int & a_Iterator )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket::AppendData(AString & a_Dst, const char * a_Data, unsigned int a_Size)
|
||||
{
|
||||
memcpy( a_Dst + a_Iterator, a_Data, a_Size ); a_Iterator += a_Size;
|
||||
a_Dst.append(a_Data, a_Size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,28 @@
|
|||
|
||||
|
||||
|
||||
#define PACKET_INCOMPLETE -2
|
||||
#define PACKET_ERROR -1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Use this macro to simplify handling several ReadXXX in a row. It assumes that you want [a_Data, a_Size] parsed (which is true for all Parse() functions)
|
||||
#define HANDLE_PACKET_READ(Proc, Var, TotalBytes) \
|
||||
{ \
|
||||
int res = Proc(a_Data + TotalBytes, a_Size - TotalBytes, Var); \
|
||||
if (res < 0) \
|
||||
{ \
|
||||
return res; \
|
||||
} \
|
||||
TotalBytes += res; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -16,41 +38,52 @@ public:
|
|||
{}
|
||||
virtual ~cPacket() {}
|
||||
|
||||
virtual bool Parse( cSocket & a_Socket) {a_Socket.CloseSocket(); LOGERROR("Undefined NEW Parse function %x\n", m_PacketID ); return false; }
|
||||
virtual bool Send( cSocket & a_Socket) {a_Socket.CloseSocket(); LOGERROR("Undefined NEW Send function %x\n", m_PacketID ); return false; }
|
||||
virtual cPacket* Clone() const = 0;
|
||||
/// Called to parse the packet. Packet type has already been read and the correct packet type created. Return the number of characters processed, PACKET_INCOMPLETE for incomplete data, PACKET_ERROR for error
|
||||
virtual int Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
LOGERROR("Undefined Parse function for packet type 0x%x\n", m_PacketID );
|
||||
assert(!"Undefined Parse function");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Called to serialize the packet into a string. Append all packet data to a_Data, including the packet type!
|
||||
virtual void Serialize(AString & a_Data) const
|
||||
{
|
||||
LOGERROR("Undefined Serialize function for packet type 0x%x\n", m_PacketID );
|
||||
assert(!"Undefined Serialize function");
|
||||
}
|
||||
|
||||
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 );
|
||||
// These return the number of characters processed, PACKET_INCOMPLETE for incomplete data, PACKET_ERROR for error:
|
||||
static int ReadString16(const char * a_Data, int a_Size, AString & a_OutString );
|
||||
static int ReadShort (const char * a_Data, int a_Size, short & a_Short );
|
||||
static int ReadInteger (const char * a_Data, int a_Size, int & a_OutInteger );
|
||||
static int ReadInteger (const char * a_Data, int a_Size, unsigned int & a_OutInteger );
|
||||
static int ReadFloat (const char * a_Data, int a_Size, float & a_OutFloat );
|
||||
static int ReadDouble (const char * a_Data, int a_Size, double & a_OutDouble );
|
||||
static int ReadByte (const char * a_Data, int a_Size, char & a_OutByte );
|
||||
static int ReadByte (const char * a_Data, int a_Size, unsigned char & a_OutByte );
|
||||
static int ReadLong (const char * a_Data, int a_Size, long long & a_OutLong );
|
||||
static int ReadBool (const char * a_Data, int a_Size, bool & a_OutBool );
|
||||
|
||||
public:
|
||||
static int SendData( cSocket & a_Socket, const char* a_Message, unsigned int a_Size, int a_Options );
|
||||
static int RecvAll( cSocket & a_Socket, char* a_Data, unsigned int a_Size, int a_Options );
|
||||
// These append the data into the a_Dst string:
|
||||
static void AppendString ( AString & a_Dst, const AString & a_String);
|
||||
static void AppendString16( AString & a_Dst, const AString & a_String);
|
||||
static void AppendShort ( AString & a_Dst, short a_Short);
|
||||
static void AppendShort ( AString & a_Dst, unsigned short a_Short);
|
||||
static void AppendInteger ( AString & a_Dst, int a_Integer);
|
||||
static void AppendInteger ( AString & a_Dst, unsigned int a_Integer);
|
||||
static void AppendFloat ( AString & a_Dst, float a_Float);
|
||||
static void AppendDouble ( AString & a_Dst, const double & a_Double);
|
||||
static void AppendByte ( AString & a_Dst, char a_Byte);
|
||||
static void AppendLong ( AString & a_Dst, const long long & a_Long);
|
||||
static void AppendBool ( AString & a_Dst, bool a_Bool);
|
||||
static void AppendData ( AString & a_Dst, const char * a_Data, unsigned int a_Size);
|
||||
};
|
||||
|
||||
typedef std::list <cPacket*> PacketList;
|
||||
|
|
|
@ -7,11 +7,14 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_13::Parse(cSocket & a_Socket)
|
||||
int cPacket_13::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_Socket = a_Socket;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadInteger, m_EntityID, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte , m_ActionID, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if( !ReadInteger( m_EntityID ) ) return false;
|
||||
if( !ReadByte ( m_ActionID ) ) return false;
|
||||
return true;
|
||||
}
|
|
@ -21,10 +21,14 @@ public:
|
|||
{ m_PacketID = E_PACKET_13; }
|
||||
virtual cPacket* Clone() const { return new cPacket_13( *this ); }
|
||||
|
||||
bool Parse(cSocket & a_Socket);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
|
||||
int m_EntityID;
|
||||
int m_EntityID;
|
||||
char m_ActionID;
|
||||
|
||||
static const unsigned int c_Size = 1;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,29 +3,18 @@
|
|||
|
||||
#include "cPacket_AddToInventory.h"
|
||||
#include "cPacket_WholeInventory.h"
|
||||
#include "../cItem.h"
|
||||
#include "cPacket_ItemData.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPacket_AddToInventory::Send( cSocket & a_Socket )
|
||||
void cPacket_AddToInventory::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
cPacket_ItemData::AppendItem(a_Data, m_ItemType, m_Count, m_Life);
|
||||
}
|
||||
|
||||
cPacket_ItemData Item;
|
||||
|
||||
TotalSize += Item.GetSize((short) m_ItemType);
|
||||
|
||||
char* Message = new char[TotalSize];
|
||||
|
||||
unsigned int i = 0;
|
||||
AppendByte ( (char) m_PacketID, Message, i );
|
||||
|
||||
Item.AppendItem(Message, i, (short) m_ItemType, m_Count, this->m_Life);
|
||||
|
||||
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
|
||||
delete [] Message;
|
||||
return RetVal;
|
||||
}
|
|
@ -14,11 +14,13 @@ public:
|
|||
{ 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 );
|
||||
// _X: This was unimplemented, do we need it?:
|
||||
// bool Parse( cSocket & a_Socket );
|
||||
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
ENUM_ITEM_ID m_ItemType;
|
||||
char m_Count;
|
||||
short m_Life;
|
||||
static const unsigned int c_Size = 1;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -7,25 +7,25 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_ArmAnim::Parse( cSocket & a_Socket )
|
||||
int cPacket_ArmAnim::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_Socket = a_Socket;
|
||||
if(!ReadInteger(m_EntityID) ) return false;
|
||||
if(!ReadByte(m_Animation) ) return false;
|
||||
return true;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadInteger, m_EntityID, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte , m_Animation, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_ArmAnim::Send( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_ArmAnim::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_EntityID);
|
||||
AppendByte (a_Data, m_Animation);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -12,8 +12,8 @@ public:
|
|||
{ m_PacketID = E_ANIMATION; }
|
||||
virtual cPacket* Clone() const { return new cPacket_ArmAnim(*this); }
|
||||
|
||||
bool Parse(cSocket & a_Socket);
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_EntityID;
|
||||
char m_Animation;
|
||||
|
|
|
@ -9,28 +9,28 @@
|
|||
|
||||
cPacket_BlockAction::cPacket_BlockAction( const cPacket_BlockAction & a_Copy )
|
||||
{
|
||||
m_PacketID = E_BLOCK_ACTION;
|
||||
m_PosX = a_Copy.m_PosX;
|
||||
m_PosY = a_Copy.m_PosY;
|
||||
m_PosZ = a_Copy.m_PosZ;
|
||||
m_Byte1 = a_Copy.m_Byte1;
|
||||
m_Byte2 = a_Copy.m_Byte2;
|
||||
m_PacketID = E_BLOCK_ACTION;
|
||||
m_PosX = a_Copy.m_PosX;
|
||||
m_PosY = a_Copy.m_PosY;
|
||||
m_PosZ = a_Copy.m_PosZ;
|
||||
m_Byte1 = a_Copy.m_Byte1;
|
||||
m_Byte2 = a_Copy.m_Byte2;
|
||||
}
|
||||
|
||||
bool cPacket_BlockAction::Send(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_BlockAction::Serialize(AString & a_Data) const
|
||||
{
|
||||
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 );
|
||||
AppendShort ( m_PosY, Message, i );
|
||||
AppendInteger ( m_PosZ, Message, i );
|
||||
AppendByte ( m_Byte1, Message, i );
|
||||
AppendByte ( m_Byte2, Message, i );
|
||||
|
||||
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
|
||||
delete [] Message;
|
||||
return RetVal;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_PosX);
|
||||
AppendShort (a_Data, m_PosY);
|
||||
AppendInteger(a_Data, m_PosZ);
|
||||
AppendByte (a_Data, m_Byte1);
|
||||
AppendByte (a_Data, m_Byte2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
@ -16,13 +17,17 @@ public:
|
|||
cPacket_BlockAction( const cPacket_BlockAction & a_Copy );
|
||||
virtual cPacket* Clone() const { return new cPacket_BlockAction(*this); }
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_PosX; // Block X Coordinate
|
||||
int m_PosX; // Block X Coordinate
|
||||
short m_PosY; // Block Y Coordinate
|
||||
int m_PosZ; // Block Z Coordinate
|
||||
char m_Byte1; // Varies
|
||||
char m_Byte2; // Varies
|
||||
int m_PosZ; // Block Z Coordinate
|
||||
char m_Byte1; // Varies
|
||||
char m_Byte2; // Varies
|
||||
|
||||
static const unsigned int c_Size = 1 + 4 + 2 + 4 + 1 + 1;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,20 +7,16 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_BlockChange::Send(cSocket & a_Socket)
|
||||
void cPacket_BlockChange::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_PosX);
|
||||
AppendByte (a_Data, m_PosY);
|
||||
AppendInteger(a_Data, m_PosZ);
|
||||
AppendByte (a_Data, m_BlockType);
|
||||
AppendByte (a_Data, m_BlockMeta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -15,12 +15,13 @@ public:
|
|||
{ m_PacketID = E_BLOCK_CHANGE; }
|
||||
virtual cPacket* Clone() const { return new cPacket_BlockChange(*this); }
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_PosX;
|
||||
int m_PosX;
|
||||
char m_PosY;
|
||||
int m_PosZ;
|
||||
int m_PosZ;
|
||||
char m_BlockType;
|
||||
char m_BlockMeta;
|
||||
|
||||
static const unsigned int c_Size = 1 + 4 + 1 + 4 + 1 + 1;
|
||||
};
|
|
@ -7,30 +7,30 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_BlockDig::Send(cSocket & a_Socket)
|
||||
void cPacket_BlockDig::Serialize(AString & a_Data) const
|
||||
{
|
||||
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;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_PosX);
|
||||
AppendByte (a_Data, m_PosY);
|
||||
AppendInteger(a_Data, m_PosZ);
|
||||
AppendByte (a_Data, m_Direction);
|
||||
}
|
||||
|
||||
bool cPacket_BlockDig::Parse(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket_BlockDig::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
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;
|
||||
}
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadByte, m_Status, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_PosY, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_Direction, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -15,13 +15,18 @@ public:
|
|||
{ 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);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
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
|
||||
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
|
||||
}; //tolua_export
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -8,29 +8,29 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_BlockPlace::Parse(cSocket & a_Socket)
|
||||
int cPacket_BlockPlace::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
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;
|
||||
}*/
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_PosY, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_Direction, TotalBytes);
|
||||
|
||||
cPacket_ItemData Item;
|
||||
|
||||
Item.Parse(m_Socket);
|
||||
int res = Item.Parse(a_Data + TotalBytes, a_Size - TotalBytes);
|
||||
if (res < 0)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
TotalBytes += res;
|
||||
|
||||
m_ItemType = Item.m_ItemID;
|
||||
m_Count = Item.m_ItemCount;
|
||||
m_Uses = Item.m_ItemUses;
|
||||
m_Count = Item.m_ItemCount;
|
||||
m_Uses = Item.m_ItemUses;
|
||||
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_BlockPlace : public cPacket //tolua_export
|
||||
{ //tolua_export
|
||||
public:
|
||||
|
@ -17,16 +21,20 @@ public:
|
|||
{ m_PacketID = E_BLOCK_PLACE; }
|
||||
virtual cPacket* Clone() const { return new cPacket_BlockPlace(*this); }
|
||||
|
||||
bool Parse(cSocket & a_Socket);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
|
||||
int m_PosX; //tolua_export
|
||||
int m_PosX; //tolua_export
|
||||
char m_PosY; //tolua_export
|
||||
int m_PosZ; //tolua_export
|
||||
int m_PosZ; //tolua_export
|
||||
char m_Direction; //tolua_export
|
||||
|
||||
short m_ItemType; //tolua_export
|
||||
char m_Count; //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
|
||||
}; //tolua_export
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,23 +7,23 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_Chat::Parse( cSocket & a_Socket )
|
||||
int cPacket_Chat::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_Socket = a_Socket;
|
||||
if( !ReadString16( m_Message ) ) return false;
|
||||
return true;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadString16, m_Message, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_Chat::Send( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_Chat::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size + m_Message.size() * sizeof( short );
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendString16(a_Data, m_Message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -10,9 +10,13 @@ public:
|
|||
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);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
std::string m_Message;
|
||||
AString m_Message;
|
||||
static const unsigned int c_Size = 3; // Minimum size
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,17 +7,13 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_CollectItem::Send( cSocket & a_Socket )
|
||||
void cPacket_CollectItem::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_CollectedID);
|
||||
AppendInteger(a_Data, m_CollectorID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -3,6 +3,9 @@
|
|||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_CollectItem : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -12,9 +15,13 @@ public:
|
|||
{ m_PacketID = E_COLLECT_ITEM; }
|
||||
virtual cPacket* Clone() const { return new cPacket_CollectItem(*this); }
|
||||
|
||||
bool Send( cSocket & a_Socket );
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_CollectedID;
|
||||
int m_CollectorID;
|
||||
static const unsigned int c_Size = 1 + 4 + 4;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -17,45 +17,52 @@ cPacket_CreativeInventoryAction::cPacket_CreativeInventoryAction( const cPacket_
|
|||
m_Damage = a_Copy.m_Damage;
|
||||
}
|
||||
|
||||
bool cPacket_CreativeInventoryAction::Parse(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket_CreativeInventoryAction::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_Socket = a_Socket;
|
||||
if( !ReadShort ( m_Slot ) ) return false;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadShort, m_Slot, TotalBytes);
|
||||
|
||||
cPacket_ItemData Item;
|
||||
|
||||
Item.Parse(m_Socket);
|
||||
int res = Item.Parse(a_Data + TotalBytes, a_Size - TotalBytes);
|
||||
if (res < 0)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
TotalBytes += res;
|
||||
|
||||
m_ItemID = Item.m_ItemID;
|
||||
m_Quantity = Item.m_ItemCount;
|
||||
m_Damage = Item.m_ItemUses;
|
||||
|
||||
|
||||
return true;
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_CreativeInventoryAction::Send(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_CreativeInventoryAction::Serialize(AString & a_Data) const
|
||||
{
|
||||
//LOG("InventoryChange:");
|
||||
unsigned int TotalSize = c_Size;
|
||||
|
||||
cPacket_ItemData Item;
|
||||
|
||||
TotalSize += Item.GetSize(m_ItemID);
|
||||
|
||||
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_CreateInventoryAction: Sending Creative item ID: %i", m_ItemID );
|
||||
short ItemID = m_ItemID;
|
||||
assert(ItemID >= -1); // Check validity of packets in debug runtime
|
||||
if (ItemID <= 0)
|
||||
{
|
||||
ItemID = -1;
|
||||
// Fix, to make sure no invalid values are sent.
|
||||
// WARNING: HERE ITS -1, BUT IN NAMED ENTITY SPAWN PACKET ITS 0 !!
|
||||
}
|
||||
|
||||
unsigned int i = 0;
|
||||
AppendByte ( (char)m_PacketID, Message, i );
|
||||
AppendShort ( m_Slot, Message, i );
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendShort (a_Data, m_Slot);
|
||||
|
||||
Item.AppendItem(Message, i, m_ItemID, m_Quantity, m_Damage);
|
||||
|
||||
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
|
||||
delete [] Message;
|
||||
return RetVal;
|
||||
cPacket_ItemData::AppendItem(a_Data, ItemID, m_Quantity, m_Damage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Sure it´s not Creative Inventory?
|
||||
|
||||
class cPacket_CreativeInventoryAction : public cPacket
|
||||
|
@ -17,8 +21,8 @@ public:
|
|||
cPacket_CreativeInventoryAction( const cPacket_CreativeInventoryAction & a_Copy );
|
||||
virtual cPacket* Clone() const { return new cPacket_CreativeInventoryAction(*this); }
|
||||
|
||||
bool Parse(cSocket & a_Socket);
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
short m_Slot; // 0 = hold 1-4 = armor
|
||||
short m_ItemID;
|
||||
|
@ -27,3 +31,7 @@ public:
|
|||
|
||||
static const unsigned int c_Size = 1 + 2;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -15,16 +15,16 @@ cPacket_DestroyEntity::cPacket_DestroyEntity(cEntity* a_Entity)
|
|||
m_UniqueID = a_Entity->GetUniqueID();
|
||||
}
|
||||
|
||||
bool cPacket_DestroyEntity::Send( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_DestroyEntity::Serialize(AString & a_Data) const
|
||||
{
|
||||
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;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_UniqueID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,15 @@
|
|||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cEntity;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_DestroyEntity : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -13,8 +21,13 @@ public:
|
|||
cPacket_DestroyEntity(cEntity* a_Entity);
|
||||
virtual cPacket* Clone() const { return new cPacket_DestroyEntity(*this); }
|
||||
|
||||
bool Send( cSocket & a_Socket );
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_UniqueID;
|
||||
|
||||
static const unsigned int c_Size = 1 + 4;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,23 +7,23 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_Disconnect::Parse( cSocket & a_Socket )
|
||||
int cPacket_Disconnect::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_Socket = a_Socket;
|
||||
if( !ReadString16(m_Reason) ) return false;
|
||||
return true;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadString16, m_Reason, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_Disconnect::Send( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_Disconnect::Serialize(AString & a_Data) const
|
||||
{
|
||||
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;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendString16(a_Data, m_Reason);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_Disconnect : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -10,9 +14,13 @@ public:
|
|||
cPacket_Disconnect(const AString & 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 );
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
AString m_Reason;
|
||||
static const unsigned int c_Size = 3; // Minimum size
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -16,34 +16,33 @@ cPacket_EntityEquipment::cPacket_EntityEquipment( const cPacket_EntityEquipment
|
|||
m_Short = 0;
|
||||
}
|
||||
|
||||
bool cPacket_EntityEquipment::Parse(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket_EntityEquipment::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
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;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadInteger, m_UniqueID, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadShort, m_Slot, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadShort, m_ItemID, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadShort, m_Short, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_EntityEquipment::Send(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_EntityEquipment::Serialize(AString & a_Data) const
|
||||
{
|
||||
//LOG("InventoryChange:");
|
||||
unsigned int TotalSize = c_Size;
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_UniqueID);
|
||||
AppendShort (a_Data, m_Slot);
|
||||
AppendShort (a_Data, m_ItemID);
|
||||
AppendShort (a_Data, m_Short);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -3,6 +3,9 @@
|
|||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_EntityEquipment : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -15,8 +18,8 @@ public:
|
|||
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);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_UniqueID;
|
||||
short m_Slot; // 0 = hold 1-4 = armor
|
||||
|
@ -24,4 +27,8 @@ public:
|
|||
short m_Short;
|
||||
|
||||
static const unsigned int c_Size = 1 + 4 + 2 + 2 + 2;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -14,22 +14,22 @@ 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);
|
||||
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 )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_EntityLook::Serialize(AString & a_Data) const
|
||||
{
|
||||
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;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_UniqueID);
|
||||
AppendByte (a_Data, m_Rotation);
|
||||
AppendByte (a_Data, m_Pitch);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cEntity;
|
||||
class cPacket_EntityLook : public cPacket
|
||||
{
|
||||
|
@ -15,7 +19,7 @@ public:
|
|||
cPacket_EntityLook(cEntity* a_Entity);
|
||||
virtual cPacket* Clone() const { return new cPacket_EntityLook(*this); }
|
||||
|
||||
bool Send( cSocket & a_Socket );
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_UniqueID;
|
||||
char m_Rotation;
|
||||
|
@ -23,3 +27,7 @@ public:
|
|||
|
||||
static const unsigned int c_Size = 1 + 4 + 1 + 1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,18 +7,13 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_EntityStatus::Send(cSocket & a_Socket)
|
||||
void cPacket_EntityStatus::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_UniqueID);
|
||||
AppendByte (a_Data, m_Status);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -3,6 +3,9 @@
|
|||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_EntityStatus : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -12,7 +15,7 @@ public:
|
|||
{ m_PacketID = E_ENT_STATUS; }
|
||||
virtual cPacket* Clone() const { return new cPacket_EntityStatus( *this ); }
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
static const char STATUS_TAKEDAMAGE = 2;
|
||||
static const char STATUS_DIE = 3;
|
||||
|
@ -22,3 +25,7 @@ public:
|
|||
|
||||
static const unsigned int c_Size = 1 + 4 + 1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -15,35 +15,38 @@ cPacket_Explosion::~cPacket_Explosion()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cPacket_Explosion::cPacket_Explosion( const cPacket_Explosion & a_Copy )
|
||||
{
|
||||
m_PacketID = E_EXPLOSION;
|
||||
m_PosX = a_Copy.m_PosX;
|
||||
m_PosY = a_Copy.m_PosY;
|
||||
m_PosZ = a_Copy.m_PosZ;
|
||||
m_Radius = a_Copy.m_Radius; //might not be radius
|
||||
m_RecordsCount= a_Copy.m_RecordsCount;
|
||||
m_PacketID = E_EXPLOSION;
|
||||
m_PosX = a_Copy.m_PosX;
|
||||
m_PosY = a_Copy.m_PosY;
|
||||
m_PosZ = a_Copy.m_PosZ;
|
||||
m_Radius = a_Copy.m_Radius; //might not be radius
|
||||
m_RecordsCount= a_Copy.m_RecordsCount;
|
||||
|
||||
m_Records = new char[(m_RecordsCount * 3)];
|
||||
memcpy( m_Records, a_Copy.m_Records, (m_RecordsCount * 3) );
|
||||
|
||||
m_Records = new char[(m_RecordsCount * 3)];
|
||||
memcpy( m_Records, a_Copy.m_Records, (m_RecordsCount * 3) );
|
||||
}
|
||||
|
||||
bool cPacket_Explosion::Send(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_Explosion::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size + (m_RecordsCount * 3);
|
||||
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_PosZ, Message, i );
|
||||
AppendFloat ( m_Radius, Message, i );
|
||||
AppendInteger ( m_RecordsCount, Message, i );
|
||||
AppendData ( m_Records, (m_RecordsCount * 3),Message, i );
|
||||
|
||||
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
|
||||
delete [] Message;
|
||||
return RetVal;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendDouble (a_Data, m_PosX);
|
||||
AppendDouble (a_Data, m_PosY);
|
||||
AppendDouble (a_Data, m_PosZ);
|
||||
AppendFloat (a_Data, m_Radius);
|
||||
AppendInteger(a_Data, m_RecordsCount);
|
||||
AppendData (a_Data, m_Records, (m_RecordsCount * 3));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_Explosion : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -18,7 +22,7 @@ public:
|
|||
~cPacket_Explosion();
|
||||
virtual cPacket* Clone() const { return new cPacket_Explosion(*this); }
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
double m_PosX; // The entity ID of the thunderbolt
|
||||
double m_PosY; // Always true. Might have a meaning in the future...
|
||||
|
@ -30,3 +34,7 @@ public:
|
|||
|
||||
char* m_Records;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,9 +7,13 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_Flying::Parse(cSocket & a_Socket)
|
||||
int cPacket_Flying::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_Socket = a_Socket;
|
||||
if( !ReadBool( m_bFlying ) ) return false;
|
||||
return true;
|
||||
}
|
||||
int TotalBytes= 0;
|
||||
HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_Flying : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -12,8 +16,12 @@ public:
|
|||
{ m_PacketID = E_FLYING; }
|
||||
virtual cPacket* Clone() const { return new cPacket_Flying(*this); }
|
||||
|
||||
bool Parse(cSocket & a_Socket);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
|
||||
bool m_bFlying;
|
||||
static const unsigned int c_Size = 2;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,25 +7,23 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_Handshake::Parse(cSocket & a_Socket)
|
||||
int cPacket_Handshake::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
//printf("Parse: NEW Handshake\n");
|
||||
m_Socket = a_Socket;
|
||||
if( !ReadString16( m_Username ) ) return false;
|
||||
return true;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadString16, m_Username, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_Handshake::Send(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_Handshake::Serialize(AString & a_Data) const
|
||||
{
|
||||
//LOG("Send: NEW Handshake %s", m_Username.c_str() );
|
||||
unsigned int TotalSize = c_Size + m_Username.size() * sizeof(short);
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendString16(a_Data, m_Username);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,17 +1,25 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.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);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
std::string m_Username;
|
||||
static const unsigned int c_Size = 3; // Minimal size
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,19 +7,14 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_InventoryProgressBar::Send(cSocket & a_Socket)
|
||||
void cPacket_InventoryProgressBar::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendByte (a_Data, m_WindowID);
|
||||
AppendShort(a_Data, m_ProgressBar);
|
||||
AppendShort(a_Data, m_Value);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_InventoryProgressBar : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -13,11 +17,15 @@ public:
|
|||
{ m_PacketID = E_INVENTORY_PROGRESS; }
|
||||
virtual cPacket* Clone() const { return new cPacket_InventoryProgressBar(*this); }
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
char m_WindowID;
|
||||
short m_ProgressBar;
|
||||
short m_Value;
|
||||
|
||||
static const unsigned int c_Size = 1 + 1 + 2 + 2;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,26 +9,15 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_InventorySlot::Send(cSocket & a_Socket)
|
||||
void cPacket_InventorySlot::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendByte (a_Data, m_WindowID);
|
||||
AppendShort(a_Data, m_SlotNum);
|
||||
|
||||
cPacket_ItemData Item;
|
||||
|
||||
TotalSize += Item.GetSize(m_ItemID);
|
||||
|
||||
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 );
|
||||
cPacket_ItemData::AppendItem(a_Data, m_ItemID, m_ItemCount, m_ItemUses);
|
||||
}
|
||||
|
||||
|
||||
Item.AppendItem(Message, i, m_ItemID, m_ItemCount, m_ItemUses);
|
||||
|
||||
|
||||
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
|
||||
delete [] Message;
|
||||
return RetVal;
|
||||
}
|
|
@ -1,9 +1,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
#include "../BlockID.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_InventorySlot : public cPacket // Set item [S -> C] ?
|
||||
{
|
||||
public:
|
||||
|
@ -16,7 +21,7 @@ public:
|
|||
{ m_PacketID = E_INVENTORY_SLOT; }
|
||||
virtual cPacket* Clone() const { return new cPacket_InventorySlot(*this); }
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
char m_WindowID;
|
||||
short m_SlotNum; // Slot
|
||||
|
@ -32,4 +37,8 @@ public:
|
|||
short m_ItemUses;
|
||||
|
||||
static const unsigned int c_Size = 1 + 1 + 2; // Minimal size ( +1+1 = max)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,36 +7,37 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_ItemData::Parse(cSocket & a_Socket)
|
||||
int cPacket_ItemData::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_Socket = a_Socket;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadShort, m_ItemID, TotalBytes);
|
||||
|
||||
if( !ReadShort(m_ItemID) ) return false;
|
||||
|
||||
if( m_ItemID > -1 )
|
||||
if (m_ItemID <= -1)
|
||||
{
|
||||
if( !ReadByte(m_ItemCount) ) return false;
|
||||
if( !ReadShort(m_ItemUses) ) return false;
|
||||
m_ItemCount = 0;
|
||||
m_ItemUses = 0;
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
if(cItem::IsEnchantable((ENUM_ITEM_ID) m_ItemID))
|
||||
HANDLE_PACKET_READ(ReadByte , m_ItemCount, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadShort, m_ItemUses, TotalBytes);
|
||||
|
||||
if (cItem::IsEnchantable((ENUM_ITEM_ID) m_ItemID))
|
||||
{
|
||||
HANDLE_PACKET_READ(ReadShort, m_EnchantNums, TotalBytes);
|
||||
|
||||
if ( m_EnchantNums > -1 )
|
||||
{
|
||||
if( !ReadShort(m_EnchantNums) ) return false;
|
||||
if( m_EnchantNums > -1 )
|
||||
{
|
||||
//TODO Not implemented yet!
|
||||
}
|
||||
// TODO: Enchantment not implemented yet!
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ItemCount = 0;
|
||||
m_ItemUses = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket_ItemData::GetSize(short a_ItemID)
|
||||
{
|
||||
if(a_ItemID <= -1)
|
||||
|
@ -47,20 +48,34 @@ int cPacket_ItemData::GetSize(short a_ItemID)
|
|||
}
|
||||
|
||||
|
||||
void cPacket_ItemData::AppendItem(char* a_Message, unsigned int &a_Iterator, cItem *a_Item)
|
||||
|
||||
|
||||
|
||||
void cPacket_ItemData::AppendItem(AString & a_Data, const cItem * a_Item)
|
||||
{
|
||||
return AppendItem(a_Message, a_Iterator, (short) a_Item->m_ItemID, a_Item->m_ItemCount, a_Item->m_ItemHealth);
|
||||
return AppendItem(a_Data, a_Item->m_ItemID, a_Item->m_ItemCount, a_Item->m_ItemHealth);
|
||||
}
|
||||
|
||||
void cPacket_ItemData::AppendItem(char* a_Message, unsigned int &a_Iterator, short a_ItemID, char a_Quantity, short a_Damage)
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_ItemData::AppendItem(AString & a_Data, short a_ItemID, char a_Quantity, short a_Damage)
|
||||
{
|
||||
|
||||
AppendShort ( (short) a_ItemID, a_Message, a_Iterator );
|
||||
if(a_ItemID > -1)
|
||||
AppendShort(a_Data, (short) a_ItemID);
|
||||
if (a_ItemID > -1)
|
||||
{
|
||||
AppendByte ( a_Quantity, a_Message, a_Iterator );
|
||||
AppendShort ( a_Damage, a_Message, a_Iterator );
|
||||
if(cItem::IsEnchantable((ENUM_ITEM_ID) a_ItemID))
|
||||
AppendShort ( (short) -1, a_Message, a_Iterator );
|
||||
AppendByte (a_Data, a_Quantity);
|
||||
AppendShort(a_Data, a_Damage);
|
||||
|
||||
if (cItem::IsEnchantable((ENUM_ITEM_ID) a_ItemID))
|
||||
{
|
||||
// TODO: Implement enchantments
|
||||
AppendShort(a_Data, (short) -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -15,17 +15,15 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
bool Parse(cSocket & a_Socket);
|
||||
|
||||
virtual cPacket* Clone() const { return new cPacket_ItemData(*this); }
|
||||
|
||||
void AppendItem(char* a_Message, unsigned int &a_Iterator, short a_ItemID, char a_Quantity, short a_Damage);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
|
||||
void AppendItem(char* a_Message, unsigned int &a_Iterator, cItem *a_Item);
|
||||
static void AppendItem(AString & a_Data, short a_ItemID, char a_Quantity, short a_Damage);
|
||||
static void AppendItem(AString & a_Data, const cItem * a_Item);
|
||||
|
||||
int GetSize(short a_ItemID);
|
||||
|
||||
|
||||
// Below = item
|
||||
short m_ItemID; // if this is -1 the next stuff dont exist
|
||||
char m_ItemCount;
|
||||
|
|
|
@ -7,24 +7,23 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_ItemSwitch::Parse( cSocket & a_Socket )
|
||||
int cPacket_ItemSwitch::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_Socket = a_Socket;
|
||||
|
||||
if( !ReadShort ( m_SlotNum ) ) return false;
|
||||
return true;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadShort, m_SlotNum, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_ItemSwitch::Send( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_ItemSwitch::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendShort(a_Data, m_SlotNum);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_ItemSwitch : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -11,9 +15,14 @@ public:
|
|||
{ m_PacketID = E_ITEM_SWITCH; }
|
||||
virtual cPacket* Clone() const { return new cPacket_ItemSwitch(*this); }
|
||||
|
||||
bool Parse(cSocket & a_Socket);
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
short m_SlotNum;
|
||||
|
||||
static const unsigned int c_Size = 1 + 2;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,23 +7,23 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_KeepAlive::Send(cSocket & a_Socket)
|
||||
void cPacket_KeepAlive::Serialize(AString & a_Data) const
|
||||
{
|
||||
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;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_KeepAliveID);
|
||||
}
|
||||
|
||||
bool cPacket_KeepAlive::Parse(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket_KeepAlive::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_Socket = a_Socket;
|
||||
if( !ReadInteger( m_KeepAliveID ) ) return false;
|
||||
return true;
|
||||
}
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadInteger, m_KeepAliveID, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_KeepAlive : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -10,10 +14,14 @@ public:
|
|||
cPacket_KeepAlive(int a_PingID) { m_KeepAliveID = a_PingID; }
|
||||
virtual cPacket* Clone() const { return new cPacket_KeepAlive(*this); }
|
||||
|
||||
virtual bool Parse(cSocket & a_Socket);
|
||||
virtual bool Send(cSocket & a_Socket);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_KeepAliveID;
|
||||
|
||||
static const unsigned int c_Size = 1 + 4;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,44 +10,45 @@
|
|||
const std::string cPacket_Login::LEVEL_TYPE_DEFAULT = "DEFAULT";
|
||||
const std::string cPacket_Login::LEVEL_TYPE_SUPERFLAT = "SUPERFLAT";
|
||||
|
||||
bool cPacket_Login::Parse( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket_Login::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
//printf("Parse: NEW Login\n");
|
||||
m_Socket = a_Socket;
|
||||
|
||||
int TotalBytes = 0;
|
||||
m_Username.clear();
|
||||
|
||||
if( !ReadInteger( m_ProtocolVersion ) ) return false;
|
||||
if( !ReadString16( m_Username ) ) return false;
|
||||
if( !ReadLong ( m_MapSeed ) ) return false;
|
||||
if( !ReadString16( m_LevelType ) ) 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;
|
||||
HANDLE_PACKET_READ(ReadInteger, m_ProtocolVersion, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadString16, m_Username, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadLong, m_MapSeed, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadString16, m_LevelType, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadInteger, m_ServerMode, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_Dimension, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_Difficulty, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_WorldHeight, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_MaxPlayers, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_Login::Send( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_Login::Serialize(AString & a_Data) const
|
||||
{
|
||||
//printf("Send: NEW Login\n");
|
||||
unsigned int TotalSize = c_Size + m_Username.size() * sizeof(short) + m_LevelType.size() * sizeof(short);
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger (a_Data, m_ProtocolVersion);
|
||||
AppendString16(a_Data, m_Username);
|
||||
AppendLong (a_Data, m_MapSeed);
|
||||
AppendString16(a_Data, m_LevelType);
|
||||
AppendInteger (a_Data, m_ServerMode);
|
||||
AppendByte (a_Data, m_Dimension);
|
||||
AppendByte (a_Data, m_Difficulty);
|
||||
AppendByte (a_Data, m_WorldHeight);
|
||||
AppendByte (a_Data, m_MaxPlayers);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 );
|
||||
AppendString16( m_LevelType, 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;
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_Login : public cPacket //tolua_export
|
||||
|
@ -19,21 +22,25 @@ public:
|
|||
{ 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);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_ProtocolVersion; //tolua_export
|
||||
std::string m_Username; //tolua_export
|
||||
AString m_Username; //tolua_export
|
||||
long long m_MapSeed; //tolua_export
|
||||
std::string m_LevelType; //tolua_export
|
||||
AString m_LevelType; //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 + 2 + 4 + 1 + 1 + 1 + 1; // Minimal size
|
||||
|
||||
|
||||
static const std::string LEVEL_TYPE_DEFAULT;
|
||||
static const std::string LEVEL_TYPE_SUPERFLAT;
|
||||
static const AString LEVEL_TYPE_DEFAULT;
|
||||
static const AString LEVEL_TYPE_SUPERFLAT;
|
||||
}; //tolua_export
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -12,12 +12,13 @@
|
|||
|
||||
cPacket_MapChunk::~cPacket_MapChunk()
|
||||
{
|
||||
if( m_CompressedData )
|
||||
{
|
||||
delete [] m_CompressedData;
|
||||
}
|
||||
delete [] m_CompressedData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cPacket_MapChunk::cPacket_MapChunk(cChunk* a_Chunk)
|
||||
{
|
||||
m_PacketID = E_MAP_CHUNK;
|
||||
|
@ -31,7 +32,7 @@ cPacket_MapChunk::cPacket_MapChunk(cChunk* a_Chunk)
|
|||
m_SizeZ = 15;
|
||||
|
||||
uLongf CompressedSize = compressBound( cChunk::c_BlockDataSize );
|
||||
char* CompressedBlockData = new char[CompressedSize];
|
||||
char * CompressedBlockData = new char[CompressedSize];
|
||||
|
||||
compress2( (Bytef*)CompressedBlockData, &CompressedSize, (const Bytef*)a_Chunk->pGetBlockData(), cChunk::c_BlockDataSize, Z_DEFAULT_COMPRESSION);
|
||||
|
||||
|
@ -39,6 +40,10 @@ cPacket_MapChunk::cPacket_MapChunk(cChunk* a_Chunk)
|
|||
m_CompressedSize = CompressedSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cPacket_MapChunk::cPacket_MapChunk( const cPacket_MapChunk & a_Copy )
|
||||
{
|
||||
m_PacketID = E_MAP_CHUNK;
|
||||
|
@ -54,23 +59,23 @@ cPacket_MapChunk::cPacket_MapChunk( const cPacket_MapChunk & a_Copy )
|
|||
memcpy( m_CompressedData, a_Copy.m_CompressedData, m_CompressedSize );
|
||||
}
|
||||
|
||||
bool cPacket_MapChunk::Send(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_MapChunk::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size + m_CompressedSize;
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_PosX);
|
||||
AppendShort (a_Data, m_PosY);
|
||||
AppendInteger(a_Data, m_PosZ);
|
||||
AppendByte (a_Data, m_SizeX);
|
||||
AppendByte (a_Data, m_SizeY);
|
||||
AppendByte (a_Data, m_SizeZ);
|
||||
AppendInteger(a_Data, m_CompressedSize);
|
||||
AppendData (a_Data, m_CompressedData, m_CompressedSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cChunk;
|
||||
class cPacket_MapChunk : public cPacket
|
||||
{
|
||||
|
@ -22,7 +26,7 @@ public:
|
|||
~cPacket_MapChunk();
|
||||
virtual cPacket* Clone() const { return new cPacket_MapChunk(*this); }
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_PosX; // In block coordinates
|
||||
short m_PosY;
|
||||
|
@ -33,5 +37,9 @@ public:
|
|||
int m_CompressedSize;
|
||||
static const unsigned int c_Size = 1 + 4 + 2 + 4 + 1 + 1 + 1 + 4;
|
||||
|
||||
char* m_CompressedData;
|
||||
};
|
||||
char * m_CompressedData;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -17,6 +17,10 @@ cPacket_Metadata::cPacket_Metadata(int s, int id)
|
|||
FormPacket();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cPacket_Metadata::cPacket_Metadata()
|
||||
: m_UniqueID( 0 )
|
||||
, m_Type( 0 )
|
||||
|
@ -27,19 +31,30 @@ cPacket_Metadata::cPacket_Metadata()
|
|||
FormPacket();
|
||||
}
|
||||
|
||||
cPacket_Metadata::~cPacket_Metadata() {
|
||||
//if( m_MetaData ) delete [] m_MetaData;
|
||||
|
||||
|
||||
|
||||
|
||||
cPacket_Metadata::~cPacket_Metadata()
|
||||
{
|
||||
delete [] m_MetaData;
|
||||
}
|
||||
|
||||
void cPacket_Metadata::FormPacket() {
|
||||
if( m_MetaData ) delete [] m_MetaData;
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_Metadata::FormPacket()
|
||||
{
|
||||
delete [] m_MetaData;
|
||||
m_MetaData = new char[3];
|
||||
m_MetaDataSize = 3;
|
||||
//m_UniqueID = GetUniqueID();
|
||||
// m_UniqueID = GetUniqueID();
|
||||
m_MetaData[0] = 0x00;
|
||||
|
||||
m_MetaData[2] = 0x7f;
|
||||
switch(m_EMetaData) {
|
||||
switch(m_EMetaData)
|
||||
{
|
||||
case cPawn::NORMAL:
|
||||
m_MetaData[1] = 0x00;
|
||||
break;
|
||||
|
@ -65,15 +80,17 @@ void cPacket_Metadata::FormPacket() {
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
void cPacket_Metadata::Serialize(AString & a_Data) const
|
||||
{
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_UniqueID);
|
||||
AppendData (a_Data, m_MetaData, m_MetaDataSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
|
||||
#pragma once
|
||||
#include "cPacket.h"
|
||||
|
||||
#include "../cPawn.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_Metadata : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -10,7 +15,8 @@ public:
|
|||
cPacket_Metadata();
|
||||
~cPacket_Metadata();
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
void FormPacket();
|
||||
virtual cPacket* Clone() const { return new cPacket_Metadata( *this ); }
|
||||
|
||||
|
@ -22,3 +28,7 @@ public:
|
|||
unsigned int m_MetaDataSize;
|
||||
char* m_MetaData;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -21,6 +21,10 @@ cPacket_MultiBlock::cPacket_MultiBlock( const cPacket_MultiBlock & a_Copy )
|
|||
memcpy( m_BlockMetas, a_Copy.m_BlockMetas, m_NumBlocks );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cPacket_MultiBlock::~cPacket_MultiBlock()
|
||||
{
|
||||
if( m_BlockCoordinates ) delete [] m_BlockCoordinates;
|
||||
|
@ -28,22 +32,22 @@ cPacket_MultiBlock::~cPacket_MultiBlock()
|
|||
if( m_BlockMetas ) delete [] m_BlockMetas;
|
||||
}
|
||||
|
||||
bool cPacket_MultiBlock::Send(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_MultiBlock::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size + m_NumBlocks * ( sizeof(short) + 2*sizeof(char) );
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_ChunkX);
|
||||
AppendInteger(a_Data, m_ChunkZ);
|
||||
AppendShort (a_Data, m_NumBlocks);
|
||||
|
||||
AppendData (a_Data, (char *)m_BlockCoordinates, sizeof(short) * m_NumBlocks);
|
||||
AppendData (a_Data, m_BlockTypes, m_NumBlocks);
|
||||
AppendData (a_Data, m_BlockMetas, m_NumBlocks);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_MultiBlock : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -18,7 +22,7 @@ public:
|
|||
~cPacket_MultiBlock();
|
||||
virtual cPacket* Clone() const { return new cPacket_MultiBlock(*this); }
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_ChunkX;
|
||||
int m_ChunkZ;
|
||||
|
@ -29,4 +33,8 @@ public:
|
|||
unsigned short* m_BlockCoordinates; // x<<12 | z<<8 | y
|
||||
char* m_BlockTypes;
|
||||
char* m_BlockMetas;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,26 +7,28 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_NamedEntitySpawn::Send( cSocket & a_Socket )
|
||||
void cPacket_NamedEntitySpawn::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size + m_PlayerName.size() * sizeof( short );
|
||||
char* Message = new char[TotalSize];
|
||||
short CurrentItem = m_CurrentItem;
|
||||
assert(CurrentItem > 0);
|
||||
if (CurrentItem <= 0)
|
||||
{
|
||||
CurrentItem = 0;
|
||||
// Fix, to make sure no invalid values are sent.
|
||||
// WARNING: HERE ITS 0, BUT IN EQUIP PACKET ITS -1 !!
|
||||
}
|
||||
|
||||
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;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger (a_Data, m_UniqueID);
|
||||
AppendString16(a_Data, m_PlayerName);
|
||||
AppendInteger (a_Data, m_PosX);
|
||||
AppendInteger (a_Data, m_PosY);
|
||||
AppendInteger (a_Data, m_PosZ);
|
||||
AppendByte (a_Data, m_Rotation);
|
||||
AppendByte (a_Data, m_Pitch);
|
||||
AppendShort (a_Data, CurrentItem);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_NamedEntitySpawn : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -17,10 +21,10 @@ public:
|
|||
{ m_PacketID = E_NAMED_ENTITY_SPAWN; }
|
||||
virtual cPacket* Clone() const { return new cPacket_NamedEntitySpawn(*this); }
|
||||
|
||||
bool Send( cSocket & a_Socket );
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_UniqueID;
|
||||
std::string m_PlayerName;
|
||||
AString m_PlayerName;
|
||||
int m_PosX; // Pixel position, devide by 32 for block position
|
||||
int m_PosY;
|
||||
int m_PosZ;
|
||||
|
@ -30,3 +34,7 @@ public:
|
|||
|
||||
static const unsigned int c_Size = 1 + 4 + 2 + 4 + 4 + 4 + 1 + 1 + 2; // Minimum size
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,28 +10,33 @@
|
|||
cPacket_NewInvalidState::cPacket_NewInvalidState( const cPacket_NewInvalidState & a_Copy )
|
||||
{
|
||||
m_PacketID = E_NEW_INVALID_STATE;
|
||||
m_Reason = a_Copy.m_Reason;
|
||||
m_Reason = a_Copy.m_Reason;
|
||||
m_GameMode = a_Copy.m_GameMode;
|
||||
}
|
||||
|
||||
bool cPacket_NewInvalidState::Parse(cSocket & a_Socket) {
|
||||
m_Socket = a_Socket;
|
||||
if( !ReadByte ( m_Reason ) ) return false;
|
||||
if( !ReadByte ( m_GameMode ) ) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cPacket_NewInvalidState::Send(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
int cPacket_NewInvalidState::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
char* Message = new char[TotalSize];
|
||||
|
||||
unsigned int i = 0;
|
||||
AppendByte ( (char)m_PacketID, Message, i );
|
||||
AppendByte ( m_Reason, Message, i );
|
||||
AppendByte ( m_GameMode, Message, i );
|
||||
|
||||
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
|
||||
delete [] Message;
|
||||
return RetVal;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadByte, m_Reason, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_GameMode, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_NewInvalidState::Serialize(AString & a_Data) const
|
||||
{
|
||||
AppendByte(a_Data, m_PacketID);
|
||||
AppendByte(a_Data, m_Reason);
|
||||
AppendByte(a_Data, m_GameMode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_NewInvalidState : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -14,11 +17,15 @@ public:
|
|||
cPacket_NewInvalidState( const cPacket_NewInvalidState & a_Copy );
|
||||
virtual cPacket* Clone() const { return new cPacket_NewInvalidState(*this); }
|
||||
|
||||
bool Parse(cSocket & a_Socket);
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
char m_Reason; // 0 = Invalid Bed, 1 = Begin Raining, 2 End Raining, 3 = Change Gamemode
|
||||
char m_GameMode; // Used only when reason = 3. 0 is survival, 1 is creative.
|
||||
|
||||
static const unsigned int c_Size = 1 + 1 + 1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,41 +7,41 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_PickupSpawn::Parse( cSocket & a_Socket )
|
||||
int cPacket_PickupSpawn::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
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;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadInteger, m_UniqueID, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadShort, m_Item, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_Count, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadShort, m_Health, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadInteger, m_PosY, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_Rotation, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_Pitch, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_Roll, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_PickupSpawn::Send( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_PickupSpawn::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_UniqueID);
|
||||
AppendShort (a_Data, m_Item);
|
||||
AppendByte (a_Data, m_Count);
|
||||
AppendShort (a_Data, m_Health);
|
||||
AppendInteger(a_Data, m_PosX);
|
||||
AppendInteger(a_Data, m_PosY);
|
||||
AppendInteger(a_Data, m_PosZ);
|
||||
AppendByte (a_Data, m_Rotation);
|
||||
AppendByte (a_Data, m_Pitch);
|
||||
AppendByte (a_Data, m_Roll);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_PickupSpawn : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -20,8 +24,8 @@ public:
|
|||
{ m_PacketID = E_PICKUP_SPAWN; }
|
||||
virtual cPacket* Clone() const { return new cPacket_PickupSpawn(*this); }
|
||||
|
||||
bool Parse( cSocket & a_Socket );
|
||||
bool Send( cSocket & a_Socket );
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_UniqueID;
|
||||
short m_Item;
|
||||
|
@ -36,3 +40,7 @@ public:
|
|||
|
||||
static const unsigned int c_Size = 1 + 4 + 2 + 1 + 2 + 4 + 4 + 4 + 1 + 1 + 1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_Ping : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -10,7 +14,11 @@ public:
|
|||
{ m_PacketID = E_PING; }
|
||||
virtual cPacket* Clone() const { return new cPacket_Ping(*this); }
|
||||
|
||||
bool Parse(cSocket & a_Socket) { (void)a_Socket; return true; }
|
||||
virtual int Parse(const char * a_Data, int a_Size) override {return 0; }
|
||||
|
||||
static const unsigned int c_Size = 1;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
|
||||
|
||||
cPacket_PlayerListItem::cPacket_PlayerListItem(std::string a_PlayerName, bool a_Online, short a_Ping)
|
||||
cPacket_PlayerListItem::cPacket_PlayerListItem(const AString & a_PlayerName, bool a_Online, short a_Ping)
|
||||
{
|
||||
m_PacketID = E_PLAYER_LIST_ITEM;
|
||||
m_PlayerName = a_PlayerName;
|
||||
|
@ -16,33 +16,41 @@ cPacket_PlayerListItem::cPacket_PlayerListItem(std::string a_PlayerName, bool a_
|
|||
m_Ping = a_Ping;
|
||||
}
|
||||
|
||||
bool cPacket_PlayerListItem::Parse( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket_PlayerListItem::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_Socket = a_Socket;
|
||||
if (!ReadString(m_PlayerName)) return false;
|
||||
if (!ReadBool(m_Online)) return false;
|
||||
if (!ReadShort(m_Ping)) return false;
|
||||
return true;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadString16, m_PlayerName, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadBool, m_Online, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadShort, m_Ping, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_PlayerListItem::Send( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_PlayerListItem::Serialize(AString & a_Data) const
|
||||
{
|
||||
int len = m_PlayerName.length();
|
||||
int end = (len <= 16) ? len : 16;
|
||||
m_PlayerName = m_PlayerName.substr(0, end);
|
||||
if (len <= 14)
|
||||
m_PlayerName += cChatColor::White; // mistakes happen when you code late night :P
|
||||
AString PlayerName(m_PlayerName);
|
||||
if (PlayerName.length() > 16)
|
||||
{
|
||||
PlayerName.erase(16);
|
||||
}
|
||||
else if (PlayerName.length() <= 14)
|
||||
{
|
||||
PlayerName += cChatColor::White;
|
||||
}
|
||||
|
||||
unsigned int TotalSize = c_Size + m_PlayerName.size()*sizeof(short);
|
||||
char* Message = new char[TotalSize];
|
||||
|
||||
unsigned int i = 0;
|
||||
AppendByte((char)m_PacketID, Message, i);
|
||||
AppendString16(m_PlayerName, Message, i);
|
||||
AppendBool(m_Online, Message, i);
|
||||
AppendShort(m_Ping, Message, i);
|
||||
|
||||
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
|
||||
delete [] Message;
|
||||
return RetVal;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendString16(a_Data, PlayerName);
|
||||
AppendBool (a_Data, m_Online);
|
||||
AppendShort (a_Data, m_Ping);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,22 +1,30 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_PlayerListItem : public cPacket
|
||||
{
|
||||
public:
|
||||
cPacket_PlayerListItem() { m_PacketID = E_PLAYER_LIST_ITEM; }
|
||||
cPacket_PlayerListItem(std::string a_PlayerName, bool a_Online, short a_Ping);
|
||||
cPacket_PlayerListItem(const AString & a_PlayerName, bool a_Online, short a_Ping);
|
||||
|
||||
bool Parse(cSocket & a_Socket);
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
virtual cPacket* Clone() const { return new cPacket_PlayerListItem(*this); }
|
||||
|
||||
std::string m_PlayerName; // Supports chat coloring, limited to 16 characters.
|
||||
bool m_Online;
|
||||
short m_Ping;
|
||||
AString m_PlayerName; // Supports chat coloring, limited to 16 characters.
|
||||
bool m_Online;
|
||||
short m_Ping;
|
||||
|
||||
static const unsigned int c_Size = 6; // Minimal size ( 6 + string )
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -11,33 +11,36 @@
|
|||
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();
|
||||
m_Pitch = a_Player->GetPitch();
|
||||
m_bFlying = a_Player->GetFlying();
|
||||
}
|
||||
|
||||
bool cPacket_PlayerLook::Parse( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket_PlayerLook::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_Socket = a_Socket;
|
||||
if( !ReadFloat( m_Rotation ) ) return false;
|
||||
if( !ReadFloat( m_Pitch ) ) return false;
|
||||
if( !ReadBool ( m_bFlying ) ) return false;
|
||||
return true;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadFloat, m_Rotation, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadFloat, m_Pitch, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_PlayerLook::Send( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_PlayerLook::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendFloat (a_Data, m_Rotation);
|
||||
AppendFloat (a_Data, m_Pitch);
|
||||
AppendBool (a_Data, m_bFlying);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,9 +1,18 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPlayer;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_PlayerLook : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -15,11 +24,16 @@ public:
|
|||
cPacket_PlayerLook( cPlayer* a_Player );
|
||||
virtual cPacket* Clone() const { return new cPacket_PlayerLook(*this); }
|
||||
|
||||
bool Parse( cSocket & a_Socket );
|
||||
bool Send( cSocket & a_Socket );
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
float m_Rotation;
|
||||
float m_Pitch;
|
||||
bool m_bFlying; // Yeah.. wtf
|
||||
bool m_bFlying; // Yeah.. wtf
|
||||
|
||||
static const unsigned int c_Size = 10;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -11,47 +11,48 @@
|
|||
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();
|
||||
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 )
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket_PlayerMoveLook::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
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;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadDouble, m_PosX, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadDouble, m_PosY, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadDouble, m_Stance, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadDouble, m_PosZ, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadFloat, m_Rotation, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadFloat, m_Pitch, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_PlayerMoveLook::Send( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_PlayerMoveLook::Serialize(AString & a_Data) const
|
||||
{
|
||||
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;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendDouble(a_Data, m_PosX);
|
||||
AppendDouble(a_Data, m_PosY);
|
||||
AppendDouble(a_Data, m_Stance);
|
||||
AppendDouble(a_Data, m_PosZ);
|
||||
AppendFloat (a_Data, m_Rotation);
|
||||
AppendFloat (a_Data, m_Pitch);
|
||||
AppendBool (a_Data, m_bFlying);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,18 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPlayer;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_PlayerMoveLook : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -19,15 +28,16 @@ public:
|
|||
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);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
double m_PosX;
|
||||
double m_PosY;
|
||||
double m_Stance;
|
||||
double m_PosZ;
|
||||
float m_Rotation;
|
||||
float m_Pitch;
|
||||
bool m_bFlying; // Yeah.. wtf
|
||||
float m_Rotation;
|
||||
float m_Pitch;
|
||||
bool m_bFlying; // Yeah.. wtf
|
||||
|
||||
static const unsigned int c_Size = 42;
|
||||
};
|
||||
|
|
|
@ -19,31 +19,35 @@ cPacket_PlayerPosition::cPacket_PlayerPosition( cPlayer* a_Player )
|
|||
m_bFlying = a_Player->GetFlying();
|
||||
}
|
||||
|
||||
bool cPacket_PlayerPosition::Parse(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket_PlayerPosition::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
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;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadDouble, m_PosX, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadDouble, m_PosY, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadDouble, m_Stance, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadDouble, m_PosZ, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_PlayerPosition::Send(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_PlayerPosition::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendDouble (a_Data, m_PosX);
|
||||
AppendDouble (a_Data, m_PosY);
|
||||
AppendDouble (a_Data, m_Stance);
|
||||
AppendDouble (a_Data, m_PosZ);
|
||||
AppendBool (a_Data, m_bFlying);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,9 +1,19 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPlayer;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_PlayerPosition : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -17,13 +27,18 @@ public:
|
|||
{ 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);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
double m_PosX;
|
||||
double m_PosY;
|
||||
double m_Stance;
|
||||
double m_PosZ;
|
||||
bool m_bFlying; // Yeah.. wtf
|
||||
bool m_bFlying; // Yeah.. wtf
|
||||
|
||||
static const unsigned int c_Size = 34;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,18 +7,14 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_PreChunk::Send(cSocket & a_Socket)
|
||||
void cPacket_PreChunk::Serialize(AString & a_Data) const
|
||||
{
|
||||
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;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_PosX);
|
||||
AppendInteger(a_Data, m_PosZ);
|
||||
AppendBool (a_Data, m_bLoad);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_PreChunk: public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -13,10 +17,15 @@ public:
|
|||
{ m_PacketID = E_PRE_CHUNK; }
|
||||
virtual cPacket* Clone() const { return new cPacket_PreChunk(*this); }
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_PosX;
|
||||
int m_PosZ;
|
||||
int m_PosX;
|
||||
int m_PosZ;
|
||||
bool m_bLoad;
|
||||
|
||||
static const unsigned int c_Size = 10;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,19 +7,15 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_RelativeEntityMove::Send( cSocket & a_Socket )
|
||||
void cPacket_RelativeEntityMove::Serialize(AString & a_Data) const
|
||||
{
|
||||
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;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_UniqueID);
|
||||
AppendByte (a_Data, m_MoveX);
|
||||
AppendByte (a_Data, m_MoveY);
|
||||
AppendByte (a_Data, m_MoveZ);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_RelativeEntityMove : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -14,12 +18,16 @@ public:
|
|||
{ m_PacketID = E_REL_ENT_MOVE; }
|
||||
virtual cPacket* Clone() const { return new cPacket_RelativeEntityMove(*this); }
|
||||
|
||||
bool Send( cSocket & a_Socket );
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_UniqueID;
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,21 +7,18 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_RelativeEntityMoveLook::Send( cSocket & a_Socket )
|
||||
void cPacket_RelativeEntityMoveLook::Serialize(AString & a_Data) const
|
||||
{
|
||||
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;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_UniqueID);
|
||||
AppendByte (a_Data, m_MoveX);
|
||||
AppendByte (a_Data, m_MoveY);
|
||||
AppendByte (a_Data, m_MoveZ);
|
||||
AppendByte (a_Data, m_Yaw);
|
||||
AppendByte (a_Data, m_Pitch);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_RelativeEntityMoveLook : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -16,9 +20,9 @@ public:
|
|||
{ m_PacketID = E_REL_ENT_MOVE_LOOK; }
|
||||
virtual cPacket* Clone() const { return new cPacket_RelativeEntityMoveLook(*this); }
|
||||
|
||||
bool Send( cSocket & a_Socket );
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_UniqueID;
|
||||
int m_UniqueID;
|
||||
char m_MoveX; // Pixels, divide by 32 for block
|
||||
char m_MoveY;
|
||||
char m_MoveZ;
|
||||
|
@ -27,3 +31,7 @@ public:
|
|||
|
||||
static const unsigned int c_Size = 1 + 4 + 1 + 1 + 1 + 1 + 1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,34 +7,33 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_Respawn::Send(cSocket & a_Socket)
|
||||
void cPacket_Respawn::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size + m_LevelType.size() * sizeof(short);
|
||||
|
||||
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 );
|
||||
AppendString16 ( m_LevelType, Message, i );
|
||||
|
||||
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
|
||||
delete [] Message;
|
||||
return RetVal;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendByte (a_Data, m_World);
|
||||
AppendByte (a_Data, m_Difficulty);
|
||||
AppendByte (a_Data, m_CreativeMode);
|
||||
AppendShort (a_Data, m_WorldHeight);
|
||||
AppendLong (a_Data, m_MapSeed);
|
||||
AppendString16(a_Data, m_LevelType);
|
||||
}
|
||||
|
||||
bool cPacket_Respawn::Parse(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
int cPacket_Respawn::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
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;
|
||||
if( !ReadString16( m_LevelType ) ) return false;
|
||||
return true;
|
||||
}
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadByte, m_World, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_Difficulty, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadByte, m_CreativeMode, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadShort, m_WorldHeight, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadLong, m_MapSeed, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadString16, m_LevelType, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
#include "cPacket_Login.h"
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_Respawn : public cPacket
|
||||
{
|
||||
|
@ -18,15 +22,19 @@ public:
|
|||
{ m_PacketID = E_RESPAWN; }
|
||||
virtual cPacket* Clone() const { return new cPacket_Respawn( *this ); }
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
bool Parse(cSocket & a_Socket);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
char m_World;
|
||||
char m_Difficulty;
|
||||
char m_CreativeMode;
|
||||
short m_WorldHeight;
|
||||
long long m_MapSeed;
|
||||
std::string m_LevelType;
|
||||
AString m_LevelType;
|
||||
|
||||
static const unsigned int c_Size = 1 + 1 + 1 + 1 + 2 + 8 + 2;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,29 +9,28 @@
|
|||
|
||||
cPacket_SoundEffect::cPacket_SoundEffect( const cPacket_SoundEffect & a_Copy )
|
||||
{
|
||||
m_PacketID = E_SOUND_EFFECT;
|
||||
m_SoundID = a_Copy.m_SoundID;
|
||||
m_PosX = a_Copy.m_PosX;
|
||||
m_PosY = a_Copy.m_PosY;
|
||||
m_PosZ = a_Copy.m_PosZ;
|
||||
m_SoundData = a_Copy.m_SoundData;
|
||||
m_PacketID = E_SOUND_EFFECT;
|
||||
m_SoundID = a_Copy.m_SoundID;
|
||||
m_PosX = a_Copy.m_PosX;
|
||||
m_PosY = a_Copy.m_PosY;
|
||||
m_PosZ = a_Copy.m_PosZ;
|
||||
m_SoundData = a_Copy.m_SoundData;
|
||||
}
|
||||
|
||||
|
||||
bool cPacket_SoundEffect::Send(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
void cPacket_SoundEffect::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
char* Message = new char[TotalSize];
|
||||
|
||||
unsigned int i = 0;
|
||||
AppendByte ( (char)m_PacketID, Message, i );
|
||||
AppendInteger ( m_SoundID, Message, i );
|
||||
AppendInteger ( m_PosX, Message, i );
|
||||
AppendByte ( (char)m_PosY, Message, i );
|
||||
AppendInteger ( m_PosZ, Message, i );
|
||||
AppendInteger ( m_SoundData, Message, i );
|
||||
|
||||
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
|
||||
delete [] Message;
|
||||
return RetVal;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_SoundID);
|
||||
AppendInteger(a_Data, m_PosX);
|
||||
AppendByte (a_Data, m_PosY);
|
||||
AppendInteger(a_Data, m_PosZ);
|
||||
AppendInteger(a_Data, m_SoundData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_SoundEffect : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -16,7 +20,7 @@ public:
|
|||
cPacket_SoundEffect( const cPacket_SoundEffect & a_Copy );
|
||||
virtual cPacket* Clone() const { return new cPacket_SoundEffect(*this); }
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_SoundID; // Sound ID
|
||||
int m_PosX; // Block X Coordinate
|
||||
|
@ -26,3 +30,7 @@ public:
|
|||
|
||||
static const unsigned int c_Size = 1 + 4 + 4 + 1 + 4 + 4;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -14,11 +14,15 @@ cPacket_SpawnMob::~cPacket_SpawnMob()
|
|||
delete m_Pos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cPacket_SpawnMob::cPacket_SpawnMob()
|
||||
: m_UniqueID( 0 )
|
||||
, m_Type( 0 )
|
||||
, m_Pos( new Vector3i() )
|
||||
, m_Yaw( 0 )
|
||||
, m_Yaw( 0 )
|
||||
, m_Pitch( 0 )
|
||||
, m_MetaDataSize( 0 )
|
||||
, m_MetaData( 0 )
|
||||
|
@ -26,6 +30,10 @@ cPacket_SpawnMob::cPacket_SpawnMob()
|
|||
m_PacketID = E_SPAWN_MOB;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cPacket_SpawnMob::cPacket_SpawnMob( const cPacket_SpawnMob & a_Clone )
|
||||
{
|
||||
m_Pos = new Vector3i();
|
||||
|
@ -42,24 +50,23 @@ cPacket_SpawnMob::cPacket_SpawnMob( const cPacket_SpawnMob & a_Clone )
|
|||
memcpy( m_MetaData, a_Clone.m_MetaData, sizeof( char ) * m_MetaDataSize );
|
||||
}
|
||||
|
||||
bool cPacket_SpawnMob::Send(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_SpawnMob::Serialize(AString & a_Data) const
|
||||
{
|
||||
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;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger (a_Data, m_UniqueID);
|
||||
AppendByte (a_Data, m_Type);
|
||||
AppendInteger (a_Data, m_Pos->x);
|
||||
AppendInteger (a_Data, m_Pos->y);
|
||||
AppendInteger (a_Data, m_Pos->z);
|
||||
AppendByte (a_Data, m_Yaw);
|
||||
AppendByte (a_Data, m_Pitch);
|
||||
AppendData (a_Data, m_MetaData, m_MetaDataSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,18 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Vector3i;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_SpawnMob : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -12,16 +21,20 @@ public:
|
|||
virtual cPacket* Clone() const { return new cPacket_SpawnMob( *this ); }
|
||||
~cPacket_SpawnMob();
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_UniqueID;
|
||||
char m_Type;
|
||||
int m_UniqueID;
|
||||
char m_Type;
|
||||
Vector3i* m_Pos;
|
||||
char m_Yaw;
|
||||
char m_Pitch;
|
||||
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;
|
||||
char * m_MetaData;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -17,25 +17,25 @@ cPacket_TeleportEntity::cPacket_TeleportEntity(cEntity* a_Client)
|
|||
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);
|
||||
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 )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_TeleportEntity::Serialize(AString & a_Data) const
|
||||
{
|
||||
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;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger(a_Data, m_UniqueID);
|
||||
AppendInteger(a_Data, m_PosX);
|
||||
AppendInteger(a_Data, m_PosY);
|
||||
AppendInteger(a_Data, m_PosZ);
|
||||
AppendByte (a_Data, m_Rotation);
|
||||
AppendByte (a_Data, m_Pitch);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cEntity;
|
||||
class cPacket_TeleportEntity : public cPacket
|
||||
{
|
||||
|
@ -18,14 +22,18 @@ public:
|
|||
virtual cPacket* Clone() const { return new cPacket_TeleportEntity(*this); }
|
||||
cPacket_TeleportEntity(cEntity* a_Client);
|
||||
|
||||
bool Send( cSocket & a_Socket );
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_UniqueID;
|
||||
int m_PosX; // Pixel position, divide by 32 for block position
|
||||
int m_PosY;
|
||||
int m_PosZ;
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,28 +9,28 @@
|
|||
|
||||
cPacket_Thunderbolt::cPacket_Thunderbolt( const cPacket_Thunderbolt & a_Copy )
|
||||
{
|
||||
m_PacketID = E_THUNDERBOLT;
|
||||
m_UniqueID = 237183; //just a random Ent ID. I don't think this matters at all.
|
||||
m_Unknown = true;
|
||||
m_xLBPos = a_Copy.m_xLBPos;
|
||||
m_yLBPos = a_Copy.m_yLBPos;
|
||||
m_zLBPos = a_Copy.m_zLBPos;
|
||||
m_PacketID = E_THUNDERBOLT;
|
||||
m_UniqueID = 237183; //just a random Ent ID. I don't think this matters at all.
|
||||
m_Unknown = true;
|
||||
m_xLBPos = a_Copy.m_xLBPos;
|
||||
m_yLBPos = a_Copy.m_yLBPos;
|
||||
m_zLBPos = a_Copy.m_zLBPos;
|
||||
}
|
||||
|
||||
bool cPacket_Thunderbolt::Send(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_Thunderbolt::Serialize(AString & a_Data) const
|
||||
{
|
||||
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 );
|
||||
AppendBool ( m_Unknown, Message, i );
|
||||
AppendInteger ( m_xLBPos*32, Message, i );
|
||||
AppendInteger ( m_yLBPos*32, Message, i );
|
||||
AppendInteger ( m_zLBPos*32, Message, i );
|
||||
|
||||
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
|
||||
delete [] Message;
|
||||
return RetVal;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger (a_Data, m_UniqueID);
|
||||
AppendBool (a_Data, m_Unknown);
|
||||
AppendInteger (a_Data, m_xLBPos * 32);
|
||||
AppendInteger (a_Data, m_yLBPos * 32);
|
||||
AppendInteger (a_Data, m_zLBPos * 32);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_Thunderbolt : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -16,13 +20,17 @@ public:
|
|||
cPacket_Thunderbolt( const cPacket_Thunderbolt & a_Copy );
|
||||
virtual cPacket* Clone() const { return new cPacket_Thunderbolt(*this); }
|
||||
|
||||
bool Send(cSocket & a_Socket);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
int m_UniqueID; // The entity ID of the thunderbolt
|
||||
int m_UniqueID; // The entity ID of the thunderbolt
|
||||
bool m_Unknown; // Always true. Might have a meaning in the future...
|
||||
int m_xLBPos; // Thunderbolt X as Absolute Integer
|
||||
int m_yLBPos; // Thunderbolt Y as Absolute Integer
|
||||
int m_zLBPos; // Thunderbolt Z as Absolute Integer
|
||||
int m_xLBPos; // Thunderbolt X as Absolute Integer
|
||||
int m_yLBPos; // Thunderbolt Y as Absolute Integer
|
||||
int m_zLBPos; // Thunderbolt Z as Absolute Integer
|
||||
|
||||
static const unsigned int c_Size = 1 + 4 + 1 + 4 + 4 + 4;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,23 +7,23 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_TimeUpdate::Parse(cSocket & a_Socket)
|
||||
int cPacket_TimeUpdate::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_Socket = a_Socket;
|
||||
if( !ReadLong(m_Time) ) return false;
|
||||
return true;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadLong, m_Time, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_TimeUpdate::Send(cSocket & a_Socket)
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_TimeUpdate::Serialize(AString & a_Data) const
|
||||
{
|
||||
unsigned int TotalSize = c_Size;
|
||||
char* Message = new char[TotalSize];
|
||||
AppendByte(a_Data, m_PacketID);
|
||||
AppendLong(a_Data, m_Time);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_TimeUpdate : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -12,9 +16,14 @@ public:
|
|||
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);
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
long long m_Time;
|
||||
|
||||
static const unsigned int c_Size = 1 + 8;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,19 +7,14 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_UpdateHealth::Send(cSocket & a_Socket)
|
||||
void cPacket_UpdateHealth::Serialize(AString & a_Data) const
|
||||
{
|
||||
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;
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendShort(a_Data, m_Health);
|
||||
AppendShort(a_Data, m_Food);
|
||||
AppendFloat(a_Data, m_Saturation);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_UpdateHealth : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -14,7 +18,7 @@ public:
|
|||
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);
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
short m_Health;
|
||||
short m_Food;
|
||||
|
@ -22,3 +26,7 @@ public:
|
|||
|
||||
static const unsigned int c_Size = 1 + 2 + 2 + 4;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,42 +7,35 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_UpdateSign::Parse( cSocket & a_Socket )
|
||||
int cPacket_UpdateSign::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
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;
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadShort, m_PosY, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadString16, m_Line1, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadString16, m_Line2, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadString16, m_Line3, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadString16, m_Line4, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
bool cPacket_UpdateSign::Send( cSocket & a_Socket )
|
||||
|
||||
|
||||
|
||||
|
||||
void cPacket_UpdateSign::Serialize(AString & a_Data) const
|
||||
{
|
||||
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 );
|
||||
AppendByte (a_Data, m_PacketID);
|
||||
AppendInteger (a_Data, m_PosX);
|
||||
AppendShort (a_Data, m_PosY);
|
||||
AppendInteger (a_Data, m_PosZ);
|
||||
AppendString16(a_Data, m_Line1);
|
||||
AppendString16(a_Data, m_Line2);
|
||||
AppendString16(a_Data, m_Line3);
|
||||
AppendString16(a_Data, m_Line4);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cPacket_UpdateSign : public cPacket
|
||||
{
|
||||
public:
|
||||
|
@ -13,16 +17,20 @@ public:
|
|||
{ m_PacketID = E_UPDATE_SIGN; }
|
||||
virtual cPacket* Clone() const { return new cPacket_UpdateSign( *this ); }
|
||||
|
||||
bool Parse( cSocket & a_Socket );
|
||||
bool Send( cSocket & a_Socket );
|
||||
virtual int Parse(const char * a_Data, int a_Size) override;
|
||||
virtual void Serialize(AString & a_Data) const override;
|
||||
|
||||
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;
|
||||
int m_PosX;
|
||||
short m_PosY;
|
||||
int m_PosZ;
|
||||
AString m_Line1;
|
||||
AString m_Line2;
|
||||
AString m_Line3;
|
||||
AString m_Line4;
|
||||
|
||||
static const unsigned int c_Size = 1 + 4 + 2 + 4 + 2 + 2 + 2 + 2; // minimum size
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,11 +7,15 @@
|
|||
|
||||
|
||||
|
||||
bool cPacket_UseEntity::Parse(cSocket & a_Socket)
|
||||
int cPacket_UseEntity::Parse(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_Socket = a_Socket;
|
||||
if( !ReadInteger(m_UniqueID) ) return false;
|
||||
if( !ReadInteger(m_TargetID) ) return false;
|
||||
if( !ReadBool (m_bLeftClick) ) return false;
|
||||
return true;
|
||||
}
|
||||
int TotalBytes = 0;
|
||||
HANDLE_PACKET_READ(ReadInteger, m_UniqueID, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadInteger, m_TargetID, TotalBytes);
|
||||
HANDLE_PACKET_READ(ReadBool, m_bLeftClick, TotalBytes);
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue