1
Fork 0
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:
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
#define _CORE_NETWORK_PACKETS_COMMON_H
@ -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;
@ -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,7 +105,7 @@ 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 )
@ -122,8 +118,6 @@ inline istream& operator>>(istream& is, FFXIVARR_PACKET_SEGMENT_HEADER& hdr)
return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr );
}
// TODO: Include structures for the individual packet segment types
template < int T > struct FFXIVIpcBasePacket
{
/** Creates a constant representing the IPC type */
@ -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,10 +147,10 @@ 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 )
@ -169,8 +163,6 @@ inline istream& operator>>(istream& is, FFXIVARR_IPC_HEADER& hdr)
return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr );
}
} /* Packets */
} /* Network */
} /* Core */

View file

@ -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 );

View file

@ -32,10 +32,10 @@ using ChatChannelPacket = GamePacketNew< T, ServerChatIpcType >;
* The base implementation of a game packet. Needed for parsing packets.
*/
template < typename T1 >
class GamePacketNewBase
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.)
@ -50,7 +50,7 @@ public:
* 32 byte header information.)
*/
template < typename T, typename T1 >
class GamePacketNew : public GamePacketNewBase<T1>
class GamePacketNew : public FFXIVPacketBase< T1 >
{
public:
/**

View file

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

View file

@ -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();
}

View file

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

View file

@ -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;

View file

@ -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,