mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-26 06:27:45 +00:00
Cleanup cleanup cleanup
This commit is contained in:
parent
f6375f326e
commit
04671e2e24
8 changed files with 82 additions and 118 deletions
|
@ -1,6 +1,3 @@
|
|||
/**
|
||||
* Structural definitions common to all FFXIV:ARR packets.
|
||||
*/
|
||||
#ifndef _CORE_NETWORK_PACKETS_COMMON_H
|
||||
#define _CORE_NETWORK_PACKETS_COMMON_H
|
||||
|
||||
|
@ -25,7 +22,7 @@ namespace Packets {
|
|||
*
|
||||
* std::stringstream buf;
|
||||
* buf << pkt_hdr;
|
||||
* for (int i = 0; i < n; i++)
|
||||
* for( int i = 0; i < n; i++ )
|
||||
* {
|
||||
* buf << pkt_seg_hdr[i];
|
||||
* buf << {pkt_seg_data[i]};
|
||||
|
@ -46,6 +43,8 @@ namespace Packets {
|
|||
*
|
||||
* 0 4 8 12 14 16
|
||||
* +-------------------------------+---------------+-------+-------+
|
||||
* | unknown_0 | unknown_8 |
|
||||
* +-------------------------------+---------------+-------+-------+
|
||||
* | timestamp | size | cType | count |
|
||||
* +---+---+-------+---------------+---------------+-------+-------+
|
||||
* | ? |CMP| ? | ? |
|
||||
|
@ -54,13 +53,10 @@ namespace Packets {
|
|||
*/
|
||||
struct FFXIVARR_PACKET_HEADER
|
||||
{
|
||||
|
||||
/** Unknown data, no actual use has been determined */
|
||||
uint64_t unknown_0;
|
||||
uint64_t unknown_8;
|
||||
/**
|
||||
* Represents the number of milliseconds since epoch that the packet was
|
||||
* sent.
|
||||
*/
|
||||
/** Represents the number of milliseconds since epoch that the packet was sent. */
|
||||
uint64_t timestamp;
|
||||
/** The size of the packet header and its payload */
|
||||
uint32_t size;
|
||||
|
@ -74,14 +70,14 @@ struct FFXIVARR_PACKET_HEADER
|
|||
uint32_t unknown_24;
|
||||
};
|
||||
|
||||
inline ostream& operator<<(ostream& os, const FFXIVARR_PACKET_HEADER& hdr)
|
||||
inline ostream& operator << ( ostream& os, const FFXIVARR_PACKET_HEADER& hdr )
|
||||
{
|
||||
return os.write(reinterpret_cast<const char*>(&hdr), sizeof hdr);
|
||||
return os.write( reinterpret_cast< const char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
inline istream& operator>>(istream& is, FFXIVARR_PACKET_HEADER& hdr)
|
||||
inline istream& operator >> ( istream& is, FFXIVARR_PACKET_HEADER& hdr )
|
||||
{
|
||||
return is.read(reinterpret_cast<char*>(&hdr), sizeof hdr);
|
||||
return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,7 +88,7 @@ inline istream& operator>>(istream& is, FFXIVARR_PACKET_HEADER& hdr)
|
|||
*
|
||||
* 0 4 8 12 16
|
||||
* +---------------+---------------+---------------+-------+-------+
|
||||
* | size | source_actor | target_actor | type | ? |
|
||||
* | size | source_actor | target_actor | type | pad |
|
||||
* +---------------+---------------+---------------+-------+-------+
|
||||
* | |
|
||||
* : type-specific data of length, size, follows :
|
||||
|
@ -109,22 +105,20 @@ struct FFXIVARR_PACKET_SEGMENT_HEADER
|
|||
uint32_t target_actor;
|
||||
/** The segment type. (1, 2, 3, 7, 8, 9, 10) */
|
||||
uint16_t type;
|
||||
uint16_t _reserved_E;
|
||||
uint16_t padding;
|
||||
};
|
||||
|
||||
inline ostream& operator<<(ostream& os, const FFXIVARR_PACKET_SEGMENT_HEADER& hdr)
|
||||
inline ostream& operator << ( ostream& os, const FFXIVARR_PACKET_SEGMENT_HEADER& hdr )
|
||||
{
|
||||
return os.write(reinterpret_cast<const char*>(&hdr), sizeof hdr);
|
||||
return os.write( reinterpret_cast< const char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
inline istream& operator>>(istream& is, FFXIVARR_PACKET_SEGMENT_HEADER& hdr)
|
||||
inline istream& operator >> ( istream& is, FFXIVARR_PACKET_SEGMENT_HEADER& hdr )
|
||||
{
|
||||
return is.read(reinterpret_cast<char*>(&hdr), sizeof hdr);
|
||||
return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
// TODO: Include structures for the individual packet segment types
|
||||
|
||||
template <int T> struct FFXIVIpcBasePacket
|
||||
template < int T > struct FFXIVIpcBasePacket
|
||||
{
|
||||
/** Creates a constant representing the IPC type */
|
||||
enum { _ServerIpcType = T };
|
||||
|
@ -133,7 +127,7 @@ template <int T> struct FFXIVIpcBasePacket
|
|||
struct FFXIVARR_PACKET_RAW
|
||||
{
|
||||
FFXIVARR_PACKET_SEGMENT_HEADER segHdr;
|
||||
std::vector<uint8_t> data;
|
||||
std::vector< uint8_t > data;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -142,7 +136,7 @@ struct FFXIVARR_PACKET_RAW
|
|||
*
|
||||
* 0 4 6 8 12 16
|
||||
* +-------+-------+------+----------+---------------+---------------+
|
||||
* | 14 00 | type | ?? | serverId | timestamp | ??? |
|
||||
* | 14 00 | type | pad | serverId | timestamp | pad1 |
|
||||
* +-------+-------+------+----------+---------------+---------------+
|
||||
* | |
|
||||
* : data :
|
||||
|
@ -153,24 +147,22 @@ struct FFXIVARR_IPC_HEADER
|
|||
{
|
||||
uint16_t reserved;
|
||||
uint16_t type;
|
||||
uint16_t unknown_2;
|
||||
uint16_t padding;
|
||||
uint16_t serverId;
|
||||
uint32_t timestamp;
|
||||
uint32_t unknown_C;
|
||||
uint32_t padding1;
|
||||
};
|
||||
|
||||
inline ostream& operator<<(ostream& os, const FFXIVARR_IPC_HEADER& hdr)
|
||||
inline ostream& operator << ( ostream& os, const FFXIVARR_IPC_HEADER& hdr )
|
||||
{
|
||||
return os.write(reinterpret_cast<const char*>(&hdr), sizeof hdr);
|
||||
return os.write( reinterpret_cast< const char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
inline istream& operator>>(istream& is, FFXIVARR_IPC_HEADER& hdr)
|
||||
inline istream& operator >> ( istream& is, FFXIVARR_IPC_HEADER& hdr )
|
||||
{
|
||||
return is.read(reinterpret_cast<char*>(&hdr), sizeof hdr);
|
||||
return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
|
||||
|
||||
} /* Packets */
|
||||
} /* Network */
|
||||
} /* Core */
|
||||
|
|
|
@ -88,7 +88,7 @@ Core::Network::Packets::GamePacket::~GamePacket()
|
|||
void Core::Network::Packets::GamePacket::savePacket()
|
||||
{
|
||||
char filename[20];
|
||||
sprintf( filename, "dump_0x%x.dat", m_subType );
|
||||
sprintf( filename, "dump_0x%x_%i.dat", m_subType, Util::getTimeMs() );
|
||||
FILE * fp = nullptr;
|
||||
fp = fopen( filename, "wb" );
|
||||
fwrite( &m_dataBuf[0], 1, m_segHdr.size, fp );
|
||||
|
|
|
@ -16,11 +16,11 @@ namespace Packets {
|
|||
// Must forward define these in order to enable the compiler to produce the
|
||||
// correct template functions.
|
||||
|
||||
template <typename T, typename T1>
|
||||
template < typename T, typename T1 >
|
||||
class GamePacketNew;
|
||||
|
||||
template <typename T, typename T1>
|
||||
std::ostream& operator<< ( std::ostream& os, const GamePacketNew<T, T1>& packet );
|
||||
template < typename T, typename T1 >
|
||||
std::ostream& operator<< ( std::ostream& os, const GamePacketNew< T, T1 >& packet );
|
||||
|
||||
template< class T >
|
||||
using ZoneChannelPacket = GamePacketNew< T, ServerZoneIpcType >;
|
||||
|
@ -31,11 +31,11 @@ using ChatChannelPacket = GamePacketNew< T, ServerChatIpcType >;
|
|||
/**
|
||||
* The base implementation of a game packet. Needed for parsing packets.
|
||||
*/
|
||||
template <typename T1>
|
||||
class GamePacketNewBase
|
||||
template < typename T1 >
|
||||
class FFXIVPacketBase
|
||||
{
|
||||
public:
|
||||
virtual ~GamePacketNewBase() = default;
|
||||
virtual ~FFXIVPacketBase() = default;
|
||||
/**
|
||||
* @brief Gets the IPC type of this packet. (Useful for determining the
|
||||
* type of a parsed packet.)
|
||||
|
@ -49,8 +49,8 @@ public:
|
|||
* type that represents just the IPC data portion (the bytes after the initial
|
||||
* 32 byte header information.)
|
||||
*/
|
||||
template <typename T, typename T1>
|
||||
class GamePacketNew : public GamePacketNewBase<T1>
|
||||
template < typename T, typename T1 >
|
||||
class GamePacketNew : public FFXIVPacketBase< T1 >
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -58,7 +58,7 @@ public:
|
|||
* @param sourceActorId The source actor id.
|
||||
* @param targetActorId The target actor id.
|
||||
*/
|
||||
GamePacketNew<T, T1>( uint32_t sourceActorId, uint32_t targetActorId )
|
||||
GamePacketNew< T, T1 >( uint32_t sourceActorId, uint32_t targetActorId )
|
||||
{
|
||||
initialize();
|
||||
m_segHdr.source_actor = sourceActorId;
|
||||
|
@ -69,7 +69,7 @@ public:
|
|||
* @brief Constructs a new game packet with the specified actors.
|
||||
* @param sourceActorId The source and target actor id.
|
||||
*/
|
||||
GamePacketNew<T, T1>( uint32_t bothActorId )
|
||||
GamePacketNew< T, T1 >( uint32_t bothActorId )
|
||||
{
|
||||
initialize();
|
||||
m_segHdr.source_actor = bothActorId;
|
||||
|
@ -109,7 +109,7 @@ public:
|
|||
* @param actorId The source actor id.
|
||||
* @return This IPC packet object (can be used for chaining).
|
||||
*/
|
||||
GamePacketNew<T, T1> sourceActor( uint32_t actorId )
|
||||
GamePacketNew< T, T1 > sourceActor( uint32_t actorId )
|
||||
{
|
||||
m_segHdr.source_actor = actorId;
|
||||
return this;
|
||||
|
@ -129,7 +129,7 @@ public:
|
|||
* @param actorId The target actor id.
|
||||
* @return This IPC packet object (can be used for chaining).
|
||||
*/
|
||||
GamePacketNew<T, T1> targetActor( uint32_t actorId )
|
||||
GamePacketNew< T, T1 > targetActor( uint32_t actorId )
|
||||
{
|
||||
m_segHdr.target_actor = actorId;
|
||||
return this;
|
||||
|
@ -144,7 +144,7 @@ public:
|
|||
return m_segHdr.target_actor;
|
||||
};
|
||||
|
||||
friend std::ostream& operator<< <> ( std::ostream& os, const GamePacketNew<T, T1>& packet );
|
||||
friend std::ostream& operator<< <> ( std::ostream& os, const GamePacketNew< T, T1 >& packet );
|
||||
|
||||
friend class GamePacketFactory;
|
||||
|
||||
|
@ -205,7 +205,7 @@ private:
|
|||
};
|
||||
};
|
||||
|
||||
template <typename T, typename T1>
|
||||
template < typename T, typename T1 >
|
||||
std::ostream& operator<<( std::ostream& os, const GamePacketNew<T, T1>& packet )
|
||||
{
|
||||
#if 0
|
||||
|
|
|
@ -11,80 +11,67 @@ namespace Core
|
|||
{
|
||||
namespace Packets
|
||||
{
|
||||
PacketParseResult getHeader(
|
||||
const std::vector< uint8_t > &buffer,
|
||||
const uint32_t offset,
|
||||
FFXIVARR_PACKET_HEADER &header)
|
||||
PacketParseResult getHeader( const std::vector< uint8_t > &buffer,
|
||||
const uint32_t offset,
|
||||
FFXIVARR_PACKET_HEADER &header )
|
||||
{
|
||||
const auto headerSize = sizeof( FFXIVARR_PACKET_HEADER );
|
||||
|
||||
// Check if we have enough bytes in the buffer.
|
||||
auto remainingBytes = buffer.size() - offset;
|
||||
if ( remainingBytes < headerSize )
|
||||
{
|
||||
if( remainingBytes < headerSize )
|
||||
return Incomplete;
|
||||
}
|
||||
|
||||
// Copy packet header.
|
||||
memcpy( &header, buffer.data() + offset, headerSize );
|
||||
|
||||
if ( !checkHeader(header) )
|
||||
{
|
||||
if( !checkHeader(header) )
|
||||
return Malformed;
|
||||
}
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
PacketParseResult getSegmentHeader(
|
||||
const std::vector< uint8_t > &buffer,
|
||||
const uint32_t offset,
|
||||
FFXIVARR_PACKET_SEGMENT_HEADER &header)
|
||||
PacketParseResult getSegmentHeader( const std::vector< uint8_t > &buffer,
|
||||
const uint32_t offset,
|
||||
FFXIVARR_PACKET_SEGMENT_HEADER &header )
|
||||
{
|
||||
const auto headerSize = sizeof( FFXIVARR_PACKET_SEGMENT_HEADER );
|
||||
|
||||
// Check if we have enough bytes in the buffer.
|
||||
auto remainingBytes = buffer.size() - offset;
|
||||
if (remainingBytes < headerSize)
|
||||
{
|
||||
if( remainingBytes < headerSize )
|
||||
return Incomplete;
|
||||
}
|
||||
|
||||
// Copy segment header
|
||||
memcpy(&header, buffer.data() + offset, headerSize);
|
||||
memcpy( &header, buffer.data() + offset, headerSize );
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
PacketParseResult getPackets(
|
||||
const std::vector< uint8_t > &buffer,
|
||||
const uint32_t offset,
|
||||
const FFXIVARR_PACKET_HEADER &packetHeader,
|
||||
std::vector< FFXIVARR_PACKET_RAW > &packets)
|
||||
PacketParseResult getPackets( const std::vector< uint8_t > &buffer,
|
||||
const uint32_t offset,
|
||||
const FFXIVARR_PACKET_HEADER &packetHeader,
|
||||
std::vector< FFXIVARR_PACKET_RAW > &packets )
|
||||
{
|
||||
// sanity check: check there's enough bytes in the buffer
|
||||
const auto bytesExpected = packetHeader.size - sizeof(struct FFXIVARR_PACKET_HEADER);
|
||||
if ( buffer.size() - offset < bytesExpected )
|
||||
{
|
||||
const auto bytesExpected = packetHeader.size - sizeof( struct FFXIVARR_PACKET_HEADER );
|
||||
if( buffer.size() - offset < bytesExpected )
|
||||
return Incomplete;
|
||||
}
|
||||
|
||||
// Loop each message
|
||||
uint32_t count = 0;
|
||||
uint32_t bytesProcessed = 0;
|
||||
while ( count < packetHeader.count )
|
||||
while( count < packetHeader.count )
|
||||
{
|
||||
FFXIVARR_PACKET_RAW rawPacket;
|
||||
|
||||
// Copy ipc packet message
|
||||
const auto packetResult = getPacket(buffer, offset + bytesProcessed, rawPacket);
|
||||
if ( packetResult != Success )
|
||||
{
|
||||
const auto packetResult = getPacket( buffer, offset + bytesProcessed, rawPacket );
|
||||
if( packetResult != Success )
|
||||
return packetResult;
|
||||
}
|
||||
|
||||
|
||||
// NOTE: isn't rawPacket is allocated on stack?
|
||||
// why is okay to do this?
|
||||
// why is okay to do this?
|
||||
packets.push_back( rawPacket );
|
||||
|
||||
// Add message size and count
|
||||
|
@ -94,34 +81,25 @@ namespace Core
|
|||
|
||||
// sanity check: check if we processed all bytes.
|
||||
// this check can fail if size of messages don't add up to size reported from packet header.
|
||||
if ( bytesExpected != bytesProcessed )
|
||||
{
|
||||
if( bytesExpected != bytesProcessed )
|
||||
return Malformed;
|
||||
}
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
PacketParseResult getPacket(
|
||||
const std::vector< uint8_t > &buffer,
|
||||
const uint32_t offset,
|
||||
FFXIVARR_PACKET_RAW &packet
|
||||
)
|
||||
PacketParseResult getPacket( const std::vector< uint8_t > &buffer, const uint32_t offset,
|
||||
FFXIVARR_PACKET_RAW &packet )
|
||||
{
|
||||
// Copy segment header
|
||||
const auto headerResult = getSegmentHeader(buffer, offset, packet.segHdr);
|
||||
if ( headerResult != Success )
|
||||
{
|
||||
const auto headerResult = getSegmentHeader( buffer, offset, packet.segHdr );
|
||||
if( headerResult != Success )
|
||||
return headerResult;
|
||||
}
|
||||
|
||||
// Check header sanity and it's size
|
||||
if ( !checkSegmentHeader( packet.segHdr ) )
|
||||
{
|
||||
if( !checkSegmentHeader( packet.segHdr ) )
|
||||
return Malformed;
|
||||
}
|
||||
|
||||
const auto dataOffset = offset + sizeof(struct FFXIVARR_PACKET_SEGMENT_HEADER);
|
||||
const auto dataOffset = offset + sizeof( struct FFXIVARR_PACKET_SEGMENT_HEADER );
|
||||
const auto dataSize = packet.segHdr.size;
|
||||
|
||||
// Allocate data buffer and copy
|
||||
|
@ -131,30 +109,24 @@ namespace Core
|
|||
return Success;
|
||||
}
|
||||
|
||||
bool checkHeader(const FFXIVARR_PACKET_HEADER &header)
|
||||
bool checkHeader( const FFXIVARR_PACKET_HEADER &header )
|
||||
{
|
||||
// Max size of the packet is capped at 1MB for now.
|
||||
if ( header.size > 1 * 1024 * 1024 )
|
||||
{
|
||||
if( header.size > 1 * 1024 * 1024 )
|
||||
return false;
|
||||
}
|
||||
|
||||
// Max number of message is capped at 255 for now.
|
||||
if ( header.count > 255 )
|
||||
{
|
||||
if( header.count > 255 )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkSegmentHeader(const FFXIVARR_PACKET_SEGMENT_HEADER &header)
|
||||
|
||||
bool checkSegmentHeader( const FFXIVARR_PACKET_SEGMENT_HEADER &header )
|
||||
{
|
||||
// Max size of individual message is capped at 256KB for now.
|
||||
if ( header.size > 256 * 1024 )
|
||||
{
|
||||
if( header.size > 256 * 1024 )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
#include <chrono>
|
||||
|
||||
|
||||
Core::Network::Packets::PacketContainer::PacketContainer( void )
|
||||
Core::Network::Packets::PacketContainer::PacketContainer()
|
||||
{
|
||||
memset( &m_ipcHdr, 0, sizeof( FFXIVARR_PACKET_HEADER ) );
|
||||
m_ipcHdr.size = sizeof( FFXIVARR_PACKET_HEADER );
|
||||
m_ipcHdr.count = 0;
|
||||
}
|
||||
|
||||
Core::Network::Packets::PacketContainer::~PacketContainer( void )
|
||||
Core::Network::Packets::PacketContainer::~PacketContainer()
|
||||
{
|
||||
m_entryList.clear();
|
||||
}
|
||||
|
|
|
@ -16,14 +16,14 @@ class GamePacket;
|
|||
class PacketContainer
|
||||
{
|
||||
public:
|
||||
PacketContainer( void );
|
||||
~PacketContainer( void );
|
||||
PacketContainer();
|
||||
~PacketContainer();
|
||||
|
||||
void addPacket( GamePacket pEntry );
|
||||
|
||||
FFXIVARR_PACKET_HEADER m_ipcHdr;
|
||||
|
||||
std::vector<GamePacket> m_entryList;
|
||||
std::vector< GamePacket > m_entryList;
|
||||
|
||||
std::string toString();
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <Network/GamePacket.h>
|
||||
#include <Network/GamePacketNew.h>
|
||||
#include <Network/PacketDef/Zone/ServerZoneDef.h>
|
||||
#include <Network/PacketContainer.h>
|
||||
#include <Util/UtilMath.h>
|
||||
|
||||
using namespace Core::Common;
|
||||
|
|
|
@ -48,9 +48,10 @@ using namespace Core::Network::Packets::Server;
|
|||
void Core::Network::GameConnection::fcInfoReqHandler( const Packets::GamePacket& inPacket,
|
||||
Entity::Player& player )
|
||||
{
|
||||
GamePacketPtr pPe( new GamePacket( 0xDD, 0x78, player.getId(), player.getId() ) );
|
||||
pPe->setValAt< uint8_t >( 0x48, 0x01 );
|
||||
queueOutPacket( pPe );
|
||||
// TODO: use new packet struct for this
|
||||
//GamePacketPtr pPe( new GamePacket( 0xDD, 0x78, player.getId(), player.getId() ) );
|
||||
//pPe->setValAt< uint8_t >( 0x48, 0x01 );
|
||||
//queueOutPacket( pPe );
|
||||
}
|
||||
|
||||
void Core::Network::GameConnection::setSearchInfoHandler( const Packets::GamePacket& inPacket,
|
||||
|
|
Loading…
Add table
Reference in a new issue