1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 14:37:44 +00:00
sapphire/src/servers/Server_Common/Network/GamePacket.h

98 lines
2.1 KiB
C
Raw Normal View History

2017-08-08 13:53:47 +02:00
#ifndef _GAMEPACKET_H_
#define _GAMEPACKET_H_
#include "CommonNetwork.h"
2017-08-19 00:18:40 +02:00
#include "src/servers/Server_Common/Forwards.h"
2017-08-08 13:53:47 +02:00
#include <stdint.h>
#include <string.h>
namespace Core {
namespace Network {
namespace Packets {
class GamePacket {
public:
GamePacket( uint16_t subType, uint16_t size, uint32_t id1, uint32_t id2, uint16_t type = 0x03 );
GamePacket( char * pData, uint16_t size, bool bWriteStamp = true );
GamePacket( const Packets::FFXIVARR_PACKET_RAW& packetData );
GamePacket( void );
~GamePacket( void );
uint16_t getSize() const
2017-08-08 13:53:47 +02:00
{
return m_segHdr.size;
}
uint16_t getType() const
2017-08-08 13:53:47 +02:00
{
return m_segHdr.type;
}
uint16_t getSubType() const
2017-08-08 13:53:47 +02:00
{
return m_subType;
}
template<class T>
void setValAt( uint16_t pos, T value )
{
2017-08-26 15:07:31 +09:00
assert( m_segHdr.size > pos );
memcpy( reinterpret_cast< uint8_t* >( &m_dataBuf[0] + pos ), &value, sizeof( T ) );
2017-08-08 13:53:47 +02:00
}
template<class T>
T getValAt( uint16_t pos ) const
2017-08-08 13:53:47 +02:00
{
2017-08-26 15:07:31 +09:00
assert(m_segHdr.size > pos);
return *reinterpret_cast< const T* >( &m_dataBuf[0] + pos );
2017-08-08 13:53:47 +02:00
}
void setBytesAt( uint16_t offset, uint8_t * bytes, uint16_t length )
2017-08-08 13:53:47 +02:00
{
2017-08-26 15:07:31 +09:00
assert(m_segHdr.size > offset);
memcpy( reinterpret_cast< uint8_t* >( &m_dataBuf[0] + offset ), bytes, length );
2017-08-08 13:53:47 +02:00
}
const char * getStringAt( uint16_t pos ) const
2017-08-08 13:53:47 +02:00
{
2017-08-26 15:07:31 +09:00
assert(m_segHdr.size > pos);
return reinterpret_cast< const char* >( &m_dataBuf[0] + pos );
2017-08-08 13:53:47 +02:00
}
void setStringAt( uint16_t pos, const std::string& str )
{
2017-08-26 15:07:31 +09:00
assert(m_segHdr.size > pos);
memcpy( reinterpret_cast< uint8_t* >( &m_dataBuf[0] + pos ), str.c_str(), str.length() );
2017-08-08 13:53:47 +02:00
}
uint8_t * getData()
2017-08-08 13:53:47 +02:00
{
return reinterpret_cast< uint8_t* >( &m_dataBuf[0] );
2017-08-08 13:53:47 +02:00
}
void setHeader( uint16_t size, uint16_t type, uint32_t id1, uint32_t id2, uint16_t subType, uint32_t unknown = 0xFED2E000 );
std::string toString() const;
2017-08-08 13:53:47 +02:00
void savePacket();
FFXIVARR_PACKET_SEGMENT_HEADER m_segHdr;
protected:
uint16_t m_unknown2;
uint16_t m_subType;
uint32_t m_timeStamp;
std::vector<uint8_t> m_dataBuf;
};
}
}
}
#endif