1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 14:37:44 +00:00

Cleanup cleanup cleanup

This commit is contained in:
Mordred 2018-06-03 19:31:03 +02:00
parent f6375f326e
commit 04671e2e24
8 changed files with 82 additions and 118 deletions

View file

@ -1,6 +1,3 @@
/**
* Structural definitions common to all FFXIV:ARR packets.
*/
#ifndef _CORE_NETWORK_PACKETS_COMMON_H #ifndef _CORE_NETWORK_PACKETS_COMMON_H
#define _CORE_NETWORK_PACKETS_COMMON_H #define _CORE_NETWORK_PACKETS_COMMON_H
@ -46,6 +43,8 @@ namespace Packets {
* *
* 0 4 8 12 14 16 * 0 4 8 12 14 16
* +-------------------------------+---------------+-------+-------+ * +-------------------------------+---------------+-------+-------+
* | unknown_0 | unknown_8 |
* +-------------------------------+---------------+-------+-------+
* | timestamp | size | cType | count | * | timestamp | size | cType | count |
* +---+---+-------+---------------+---------------+-------+-------+ * +---+---+-------+---------------+---------------+-------+-------+
* | ? |CMP| ? | ? | * | ? |CMP| ? | ? |
@ -54,13 +53,10 @@ namespace Packets {
*/ */
struct FFXIVARR_PACKET_HEADER struct FFXIVARR_PACKET_HEADER
{ {
/** Unknown data, no actual use has been determined */
uint64_t unknown_0; uint64_t unknown_0;
uint64_t unknown_8; 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; uint64_t timestamp;
/** The size of the packet header and its payload */ /** The size of the packet header and its payload */
uint32_t size; uint32_t size;
@ -92,7 +88,7 @@ inline istream& operator>>(istream& is, FFXIVARR_PACKET_HEADER& hdr)
* *
* 0 4 8 12 16 * 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 : * : type-specific data of length, size, follows :
@ -109,7 +105,7 @@ struct FFXIVARR_PACKET_SEGMENT_HEADER
uint32_t target_actor; uint32_t target_actor;
/** The segment type. (1, 2, 3, 7, 8, 9, 10) */ /** The segment type. (1, 2, 3, 7, 8, 9, 10) */
uint16_t type; 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 )
@ -122,8 +118,6 @@ 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 */ /** Creates a constant representing the IPC type */
@ -142,7 +136,7 @@ struct FFXIVARR_PACKET_RAW
* *
* 0 4 6 8 12 16 * 0 4 6 8 12 16
* +-------+-------+------+----------+---------------+---------------+ * +-------+-------+------+----------+---------------+---------------+
* | 14 00 | type | ?? | serverId | timestamp | ??? | * | 14 00 | type | pad | serverId | timestamp | pad1 |
* +-------+-------+------+----------+---------------+---------------+ * +-------+-------+------+----------+---------------+---------------+
* | | * | |
* : data : * : data :
@ -153,10 +147,10 @@ struct FFXIVARR_IPC_HEADER
{ {
uint16_t reserved; uint16_t reserved;
uint16_t type; uint16_t type;
uint16_t unknown_2; uint16_t padding;
uint16_t serverId; uint16_t serverId;
uint32_t timestamp; 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 )
@ -169,8 +163,6 @@ 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 */ } /* Packets */
} /* Network */ } /* Network */
} /* Core */ } /* Core */

View file

@ -88,7 +88,7 @@ Core::Network::Packets::GamePacket::~GamePacket()
void Core::Network::Packets::GamePacket::savePacket() void Core::Network::Packets::GamePacket::savePacket()
{ {
char filename[20]; 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; FILE * fp = nullptr;
fp = fopen( filename, "wb" ); fp = fopen( filename, "wb" );
fwrite( &m_dataBuf[0], 1, m_segHdr.size, fp ); fwrite( &m_dataBuf[0], 1, m_segHdr.size, fp );

View file

@ -32,10 +32,10 @@ using ChatChannelPacket = GamePacketNew< T, ServerChatIpcType >;
* The base implementation of a game packet. Needed for parsing packets. * The base implementation of a game packet. Needed for parsing packets.
*/ */
template < typename T1 > template < typename T1 >
class GamePacketNewBase class FFXIVPacketBase
{ {
public: public:
virtual ~GamePacketNewBase() = default; virtual ~FFXIVPacketBase() = default;
/** /**
* @brief Gets the IPC type of this packet. (Useful for determining the * @brief Gets the IPC type of this packet. (Useful for determining the
* type of a parsed packet.) * type of a parsed packet.)
@ -50,7 +50,7 @@ public:
* 32 byte header information.) * 32 byte header information.)
*/ */
template < typename T, typename T1 > template < typename T, typename T1 >
class GamePacketNew : public GamePacketNewBase<T1> class GamePacketNew : public FFXIVPacketBase< T1 >
{ {
public: public:
/** /**

View file

@ -11,8 +11,7 @@ namespace Core
{ {
namespace Packets namespace Packets
{ {
PacketParseResult getHeader( PacketParseResult getHeader( const std::vector< uint8_t > &buffer,
const std::vector< uint8_t > &buffer,
const uint32_t offset, const uint32_t offset,
FFXIVARR_PACKET_HEADER &header ) FFXIVARR_PACKET_HEADER &header )
{ {
@ -21,23 +20,18 @@ namespace Core
// Check if we have enough bytes in the buffer. // Check if we have enough bytes in the buffer.
auto remainingBytes = buffer.size() - offset; auto remainingBytes = buffer.size() - offset;
if( remainingBytes < headerSize ) if( remainingBytes < headerSize )
{
return Incomplete; return Incomplete;
}
// Copy packet header. // Copy packet header.
memcpy( &header, buffer.data() + offset, headerSize ); memcpy( &header, buffer.data() + offset, headerSize );
if( !checkHeader(header) ) if( !checkHeader(header) )
{
return Malformed; return Malformed;
}
return Success; return Success;
} }
PacketParseResult getSegmentHeader( PacketParseResult getSegmentHeader( const std::vector< uint8_t > &buffer,
const std::vector< uint8_t > &buffer,
const uint32_t offset, const uint32_t offset,
FFXIVARR_PACKET_SEGMENT_HEADER &header ) FFXIVARR_PACKET_SEGMENT_HEADER &header )
{ {
@ -46,9 +40,7 @@ namespace Core
// Check if we have enough bytes in the buffer. // Check if we have enough bytes in the buffer.
auto remainingBytes = buffer.size() - offset; auto remainingBytes = buffer.size() - offset;
if( remainingBytes < headerSize ) if( remainingBytes < headerSize )
{
return Incomplete; return Incomplete;
}
// Copy segment header // Copy segment header
memcpy( &header, buffer.data() + offset, headerSize ); memcpy( &header, buffer.data() + offset, headerSize );
@ -56,8 +48,7 @@ namespace Core
return Success; return Success;
} }
PacketParseResult getPackets( PacketParseResult getPackets( const std::vector< uint8_t > &buffer,
const std::vector< uint8_t > &buffer,
const uint32_t offset, const uint32_t offset,
const FFXIVARR_PACKET_HEADER &packetHeader, const FFXIVARR_PACKET_HEADER &packetHeader,
std::vector< FFXIVARR_PACKET_RAW > &packets ) std::vector< FFXIVARR_PACKET_RAW > &packets )
@ -65,9 +56,7 @@ namespace Core
// sanity check: check there's enough bytes in the buffer // sanity check: check there's enough bytes in the buffer
const auto bytesExpected = packetHeader.size - sizeof( struct FFXIVARR_PACKET_HEADER ); const auto bytesExpected = packetHeader.size - sizeof( struct FFXIVARR_PACKET_HEADER );
if( buffer.size() - offset < bytesExpected ) if( buffer.size() - offset < bytesExpected )
{
return Incomplete; return Incomplete;
}
// Loop each message // Loop each message
uint32_t count = 0; uint32_t count = 0;
@ -79,9 +68,7 @@ namespace Core
// Copy ipc packet message // Copy ipc packet message
const auto packetResult = getPacket( buffer, offset + bytesProcessed, rawPacket ); const auto packetResult = getPacket( buffer, offset + bytesProcessed, rawPacket );
if( packetResult != Success ) if( packetResult != Success )
{
return packetResult; return packetResult;
}
// NOTE: isn't rawPacket is allocated on stack? // NOTE: isn't rawPacket is allocated on stack?
// why is okay to do this? // why is okay to do this?
@ -95,31 +82,22 @@ namespace Core
// sanity check: check if we processed all bytes. // 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. // 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 Malformed;
}
return Success; return Success;
} }
PacketParseResult getPacket( PacketParseResult getPacket( const std::vector< uint8_t > &buffer, const uint32_t offset,
const std::vector< uint8_t > &buffer, FFXIVARR_PACKET_RAW &packet )
const uint32_t offset,
FFXIVARR_PACKET_RAW &packet
)
{ {
// Copy segment header // Copy segment header
const auto headerResult = getSegmentHeader( buffer, offset, packet.segHdr ); const auto headerResult = getSegmentHeader( buffer, offset, packet.segHdr );
if( headerResult != Success ) if( headerResult != Success )
{
return headerResult; return headerResult;
}
// Check header sanity and it's size // Check header sanity and it's size
if( !checkSegmentHeader( packet.segHdr ) ) if( !checkSegmentHeader( packet.segHdr ) )
{
return Malformed; 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; const auto dataSize = packet.segHdr.size;
@ -135,15 +113,11 @@ namespace Core
{ {
// Max size of the packet is capped at 1MB for now. // 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; return false;
}
// Max number of message is capped at 255 for now. // Max number of message is capped at 255 for now.
if( header.count > 255 ) if( header.count > 255 )
{
return false; return false;
}
return true; return true;
} }
@ -152,9 +126,7 @@ namespace Core
{ {
// Max size of individual message is capped at 256KB for now. // Max size of individual message is capped at 256KB for now.
if( header.size > 256 * 1024 ) if( header.size > 256 * 1024 )
{
return false; return false;
}
return true; return true;
} }

View file

@ -7,14 +7,14 @@
#include <chrono> #include <chrono>
Core::Network::Packets::PacketContainer::PacketContainer( void ) Core::Network::Packets::PacketContainer::PacketContainer()
{ {
memset( &m_ipcHdr, 0, sizeof( FFXIVARR_PACKET_HEADER ) ); memset( &m_ipcHdr, 0, sizeof( FFXIVARR_PACKET_HEADER ) );
m_ipcHdr.size = sizeof( FFXIVARR_PACKET_HEADER ); m_ipcHdr.size = sizeof( FFXIVARR_PACKET_HEADER );
m_ipcHdr.count = 0; m_ipcHdr.count = 0;
} }
Core::Network::Packets::PacketContainer::~PacketContainer( void ) Core::Network::Packets::PacketContainer::~PacketContainer()
{ {
m_entryList.clear(); m_entryList.clear();
} }

View file

@ -16,8 +16,8 @@ class GamePacket;
class PacketContainer class PacketContainer
{ {
public: public:
PacketContainer( void ); PacketContainer();
~PacketContainer( void ); ~PacketContainer();
void addPacket( GamePacket pEntry ); void addPacket( GamePacket pEntry );

View file

@ -7,7 +7,6 @@
#include <Network/GamePacket.h> #include <Network/GamePacket.h>
#include <Network/GamePacketNew.h> #include <Network/GamePacketNew.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h> #include <Network/PacketDef/Zone/ServerZoneDef.h>
#include <Network/PacketContainer.h>
#include <Util/UtilMath.h> #include <Util/UtilMath.h>
using namespace Core::Common; using namespace Core::Common;

View file

@ -48,9 +48,10 @@ using namespace Core::Network::Packets::Server;
void Core::Network::GameConnection::fcInfoReqHandler( const Packets::GamePacket& inPacket, void Core::Network::GameConnection::fcInfoReqHandler( const Packets::GamePacket& inPacket,
Entity::Player& player ) Entity::Player& player )
{ {
GamePacketPtr pPe( new GamePacket( 0xDD, 0x78, player.getId(), player.getId() ) ); // TODO: use new packet struct for this
pPe->setValAt< uint8_t >( 0x48, 0x01 ); //GamePacketPtr pPe( new GamePacket( 0xDD, 0x78, player.getId(), player.getId() ) );
queueOutPacket( pPe ); //pPe->setValAt< uint8_t >( 0x48, 0x01 );
//queueOutPacket( pPe );
} }
void Core::Network::GameConnection::setSearchInfoHandler( const Packets::GamePacket& inPacket, void Core::Network::GameConnection::setSearchInfoHandler( const Packets::GamePacket& inPacket,