2012-02-02 13:13:24 -08:00
|
|
|
|
2011-10-03 11:41:19 -07:00
|
|
|
#pragma once
|
|
|
|
|
2012-01-27 06:04:28 -08:00
|
|
|
#include "../cSocket.h"
|
|
|
|
#include "../PacketID.h"
|
|
|
|
|
2012-02-01 04:46:44 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 11:41:19 -07:00
|
|
|
|
|
|
|
class cPacket
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cPacket()
|
|
|
|
: m_PacketID( 0 )
|
|
|
|
{}
|
|
|
|
virtual ~cPacket() {}
|
|
|
|
|
2012-02-06 23:44:42 -08:00
|
|
|
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; }
|
2011-10-03 11:41:19 -07:00
|
|
|
virtual cPacket* Clone() const = 0;
|
|
|
|
|
|
|
|
unsigned char m_PacketID;
|
|
|
|
cSocket m_Socket; // Current socket being used
|
|
|
|
protected:
|
|
|
|
bool ReadString ( std::string & a_OutString );
|
|
|
|
bool ReadString16( std::string & a_OutString );
|
|
|
|
bool ReadShort ( short & a_Short );
|
|
|
|
bool ReadInteger(int & a_OutInteger );
|
|
|
|
bool ReadInteger(unsigned int & a_OutInteger );
|
|
|
|
bool ReadFloat ( float & a_OutFloat );
|
|
|
|
bool ReadDouble ( double & a_OutDouble );
|
|
|
|
bool ReadByte ( char & a_OutByte );
|
|
|
|
bool ReadByte ( unsigned char & a_OutByte );
|
|
|
|
bool ReadLong ( long long & a_OutLong );
|
|
|
|
bool ReadBool ( bool & a_OutBool );
|
|
|
|
|
|
|
|
void AppendString ( std::string & a_String, char* a_Dst, unsigned int & a_Iterator );
|
|
|
|
void AppendString16 ( std::string & a_String, char* a_Dst, unsigned int & a_Iterator );
|
|
|
|
void AppendShort ( short a_Short, char* a_Dst, unsigned int & a_Iterator );
|
|
|
|
void AppendShort ( unsigned short a_Short, char* a_Dst, unsigned int & a_Iterator );
|
|
|
|
void AppendInteger ( int a_Integer, char* a_Dst, unsigned int & a_Iterator );
|
|
|
|
void AppendInteger ( unsigned int a_Integer, char* a_Dst, unsigned int & a_Iterator );
|
|
|
|
void AppendFloat ( float a_Float, char* a_Dst, unsigned int & a_Iterator );
|
|
|
|
void AppendDouble ( double & a_Double, char* a_Dst, unsigned int & a_Iterator );
|
|
|
|
void AppendByte ( char a_Byte, char* a_Dst, unsigned int & a_Iterator );
|
|
|
|
void AppendLong ( long long & a_Long, char* a_Dst, unsigned int & a_Iterator );
|
|
|
|
void AppendBool ( bool a_Bool, char* a_Dst, unsigned int & a_Iterator );
|
|
|
|
void AppendData ( char* a_Data, unsigned int a_Size, char* a_Dst, unsigned int & a_Iterator );
|
|
|
|
|
|
|
|
public:
|
2011-10-21 14:25:29 -07:00
|
|
|
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 );
|
2011-10-03 11:41:19 -07:00
|
|
|
};
|
2012-02-01 04:46:44 -08:00
|
|
|
|
2012-02-02 13:13:24 -08:00
|
|
|
typedef std::list <cPacket*> PacketList;
|
|
|
|
typedef std::deque<cPacket *> PacketQueue;
|
|
|
|
|
2012-02-01 04:46:44 -08:00
|
|
|
|
|
|
|
|
|
|
|
|