1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-05 10:17:46 +00:00

Merge pull request #334 from NotAdam/develop

use structs for incoming packets & some cleanup
This commit is contained in:
Mordred 2018-07-08 19:30:11 +02:00 committed by GitHub
commit 7a0390d38e
18 changed files with 328 additions and 253 deletions

View file

@ -27,6 +27,23 @@ namespace Common {
float z;
};
enum InventoryOperation : uint8_t
{
Discard = 0x07,
Move = 0x08,
Swap = 0x09,
Merge = 0x0C,
Split = 0x0A
};
enum ClientLanguage : uint8_t
{
Japanese = 1,
English = 2,
German = 4,
French = 8
};
enum EquipSlot : uint8_t
{
MainHand = 0,

View file

@ -1,35 +0,0 @@
#include "XMLConfig.h"
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/lexical_cast.hpp>
namespace Core {
// instanciate and load a config
XMLConfig::XMLConfig()
{
}
XMLConfig::~XMLConfig()
{
}
using boost::property_tree::ptree;
const ptree& empty_ptree()
{
static ptree t;
return t;
};
bool XMLConfig::loadConfig( const std::string& fileName )
{
boost::property_tree::read_xml( fileName, m_propTree );
return true;
}
}

View file

@ -1,73 +0,0 @@
#ifndef __XMLCONFIG_H
#define __XMLCONFIG_H
#include <stdint.h>
#include <boost/property_tree/ptree.hpp>
#include <map>
namespace Core {
// very simple XML parser class
// this hasn't gotten much attention yet as it works good as it is.
class XMLConfig
{
public:
typedef std::map<std::string, std::string> SettingMap;
typedef std::map<std::string, SettingMap> CategoryMap;
// instanciate and load a config
XMLConfig();
~XMLConfig();
// load a config file
bool loadConfig( const std::string& fileName );
template< class T >
T getValue( const std::string& name, T defaultValue = T() )
{
try
{
return m_propTree.get< T >( name );
}
catch( ... )
{
return defaultValue;
}
}
template< class T >
void setValue( const std::string& name, T defaultValue = T() )
{
m_propTree.put( name, defaultValue );
}
template< class T >
T getAttrValue( boost::property_tree::ptree node, const std::string& name, T defaultValue = T() )
{
try
{
T outVal = node.get< T >( "<xmlattr>." + name );
return outVal;
}
catch( const std::runtime_error& )
{
T outVal = defaultValue;
return outVal;
}
}
boost::property_tree::ptree getChild( const std::string& name )
{
auto val = m_propTree.get_child( name );
return val;
}
private:
boost::property_tree::ptree m_propTree;
};
}
#endif

View file

@ -219,7 +219,7 @@ namespace Core {
enum ClientTriggerType
{
ToggleSeathe = 0x01,
ToggleSheathe = 0x01,
ToggleAutoAttack = 0x02,
ChangeTarget = 0x03,

View file

@ -137,10 +137,11 @@ struct FFXIVARR_PACKET_RAW
*/
enum FFXIVARR_SEGMENT_TYPE
{
SEGMENTTYPE_SESSIONINIT = 1,
SEGMENTTYPE_IPC = 3,
SEGMENTTYPE_RESPONSE = 7,
SEGMENTTYPE_KEEPALIVE = 8,
SEGMENTTYPE_ENCRYPTIONHANDSHAKE = 9,
SEGMENTTYPE_KEEPALIVE = 7,
//SEGMENTTYPE_RESPONSE = 8,
SEGMENTTYPE_ENCRYPTIONINIT = 9,
};
/**

View file

@ -179,6 +179,18 @@ public:
initialize();
};
FFXIVIpcPacket< T, T1 >( const FFXIVARR_PACKET_RAW& rawPacket )
{
auto ipcHdrSize = sizeof( FFXIVARR_IPC_HEADER );
auto copySize = std::min< uint32_t >( sizeof( T ), rawPacket.segHdr.size - ipcHdrSize );
memcpy( &m_segHdr, &rawPacket.segHdr, sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) );
memcpy( &m_data, &rawPacket.data[0] + ipcHdrSize, copySize );
memset( &m_ipcHdr, 0, ipcHdrSize );
m_ipcHdr.type = static_cast< ServerZoneIpcType >( m_data._ServerIpcType );
}
uint32_t getContentSize() override
{
return sizeof( FFXIVARR_IPC_HEADER ) + sizeof( T );
@ -215,6 +227,8 @@ public:
/** Gets a reference to the underlying IPC data structure. */
T& data() { return m_data; };
const T& data() const { return m_data; }
protected:
/** Initializes the fields of the header structures */
virtual void initialize()

View file

@ -91,8 +91,9 @@ namespace Packets {
LogMessage = 0x00D0,
LinkshellList = 0x011C, // updated 4.3
SetCharaFCTag = 0x013B, // updated 4.3
SetFreeCompanyInfo = 0x013D, // updated 4.3
CharaFreeCompanyTag = 0x013B, // updated 4.3
FreeCompanyBoardMsg = 0x013C, // updated 4.3
FreeCompanyInfo = 0x013D, // updated 4.3
StatusEffectList = 0x014E, // updated 4.3
Effect = 0x0151, // updated 4.3
@ -223,13 +224,17 @@ namespace Packets {
ReqJoinNoviceNetwork = 0x0129, // updated 4.2
ReqCountdownInitiate = 0x012C, // updated 4.2
ReqCountdownCancel = 0x012D, // updated 4.2
ReqCountdownInitiate = 0x0138, // updated 4.3
ReqCountdownCancel = 0x0139, // updated 4.3
ClearWaymarks = 0x013A, // updated 4.3
ZoneLineHandler = 0x013C, // updated 4.3
ClientTrigger = 0x013D, // updated 4.3
DiscoveryHandler = 0x013E, // updated 4.3
AddWaymark = 0x013F, // updated 4.3
SkillHandler = 0x0140, // updated 4.3
GMCommand1 = 0x0141, // updated 4.3
GMCommand2 = 0x0142, // updated 4.3

View file

@ -0,0 +1,171 @@
#ifndef _CORE_NETWORK_PACKETS_ZONE_CLIENT_IPC_H
#define _CORE_NETWORK_PACKETS_ZONE_CLIENT_IPC_H
#include <Common.h>
#include <Network/CommonNetwork.h>
namespace Core {
namespace Network {
namespace Packets {
namespace Client {
struct FFXIVIpcGmCommand1 : FFXIVIpcBasePacket< GMCommand1 >
{
/* 0000 */ uint32_t commandId;
/* 0004 */ uint32_t param1;
/* 0008 */ uint32_t param2;
/* 000C */ uint8_t unknown_C[0xC];
/* 0018 */ uint32_t param3;
};
struct FFXIVIpcGmCommand2 : FFXIVIpcBasePacket< GMCommand2 >
{
/* 0000 */ uint32_t commandId;
/* 0004 */ char unk_4[0x10];
/* 0014 */ char param1[0x20];
};
struct FFXIVIpcClientTrigger : FFXIVIpcBasePacket< ClientTrigger >
{
/* 0000 */ uint16_t commandId;
/* 0002 */ uint8_t unk_2[2];
/* 0004 */ uint32_t param11;
/* 0008 */ uint32_t param12;
/* 000C */ uint32_t param2;
/* 0010 */ char unk_10[8];
/* 0018 */ uint64_t param3;
};
struct FFXIVIpcSkillHandler : FFXIVIpcBasePacket< SkillHandler >
{
/* 0000 */ char pad_0000[1];
/* 0001 */ uint8_t type;
/* 0002 */ char pad_0002[2];
/* 0004 */ uint32_t actionId;
/* 0008 */ uint32_t useCount;
/* 000C */ char pad_000C[4];
/* 0010 */ uint64_t targetId;
};
struct FFXIVIpcZoneLineHandler : FFXIVIpcBasePacket< ZoneLineHandler >
{
/* 0000 */ uint32_t zoneLineId;
};
struct FFXIVIpcDiscoveryHandler : FFXIVIpcBasePacket< DiscoveryHandler >
{
/* 0000 */ uint32_t positionRef;
};
struct FFXIVIpcEventHandlerReturn : FFXIVIpcBasePacket< ReturnEventHandler >
{
/* 0000 */ uint32_t eventId;
/* 0004 */ uint16_t scene;
/* 0006 */ uint16_t param1;
/* 0008 */ uint16_t param2;
/* 000A */ char pad_000A[2];
/* 000C */ uint16_t param3;
};
struct FFXIVIpcEnterTerritoryHandler : FFXIVIpcBasePacket< EnterTeriEventHandler >
{
/* 0000 */ uint32_t eventId;
/* 0004 */ uint16_t param1;
/* 0006 */ uint16_t param2;
};
struct FFXIVIpcEventHandlerOutsideRange : FFXIVIpcBasePacket< OutOfRangeEventHandler >
{
/* 0000 */ uint32_t param1;
/* 0004 */ uint32_t eventId;
/* 0008 */ Common::FFXIVARR_POSITION3 position;
};
struct FFXIVIpcEventHandlerWithinRange : FFXIVIpcBasePacket< WithinRangeEventHandler >
{
/* 0000 */ uint32_t param1;
/* 0004 */ uint32_t eventId;
/* 0008 */ Common::FFXIVARR_POSITION3 position;
};
struct FFXIVIpcEventHandlerEmote : FFXIVIpcBasePacket< EmoteEventHandler >
{
/* 0000 */ uint64_t actorId;
/* 0008 */ uint32_t eventId;
/* 000C */ uint16_t emoteId;
};
struct FFXIVIpcEventHandlerTalk : FFXIVIpcBasePacket< TalkEventHandler >
{
/* 0000 */ uint64_t actorId;
/* 0008 */ uint32_t eventId;
};
struct FFXIVIpcPingHandler : FFXIVIpcBasePacket< PingHandler >
{
/* 0000 */ uint32_t timestamp; // maybe lol..
};
struct FFXIVIpcSetSearchInfo : FFXIVIpcBasePacket< SetSearchInfoHandler >
{
union
{
/* 0000 */ uint64_t status;
struct
{
/* 0000 */ uint32_t status1;
/* 0004 */ uint32_t status2;
};
};
/* 0008 */ char pad_0008[9];
/* 0011 */ Common::ClientLanguage language;
/* 0012 */ char searchComment[193];
};
struct FFXIVIpcTellHandler : FFXIVIpcBasePacket< TellReq >
{
/* 0000 */ char pad_0000[4];
/* 0004 */ char targetPCName[32];
/* 0024 */ char message[1012];
};
struct FFXIVIpcChatHandler : FFXIVIpcBasePacket< ChatHandler >
{
/* 0000 */ char pad_0000[4];
/* 0004 */ uint32_t sourceId;
/* 0008 */ char pad_0008[16];
/* 0018 */ Common::ChatType chatType;
/* 001A */ char message[1012];
};
struct FFXIVIpcLinkshellEventHandler : FFXIVIpcBasePacket< LinkshellEventHandler >
{
/* 0000 */ uint32_t eventId;
/* 0004 */ uint16_t scene;
/* 0006 */ char pad_0006[1];
/* 0007 */ char lsName[21];
};
struct FFXIVIpcInventoryModifyHandler : FFXIVIpcBasePacket< InventoryModifyHandler >
{
/* 0000 */ uint32_t seq;
/* 0004 */ Common::InventoryOperation action;
/* 0005 */ char pad_0005[3];
/* 0008 */ uint16_t splitCount; // todo: check packet handler in game and see if this is sent as a u16 or u32
/* 000A */ char pad_000A[2];
/* 000C */ uint16_t fromContainer;
/* 000E */ char pad_000E[2];
/* 0010 */ uint8_t fromSlot;
/* 0011 */ char pad_0011[15];
/* 0020 */ uint16_t toContainer;
/* 0022 */ char pad_0022[2];
/* 0024 */ uint8_t toSlot;
};
}
}
}
}
#endif //_CORE_NETWORK_PACKETS_ZONE_CLIENT_IPC_H

View file

@ -482,7 +482,7 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets:
switch( inPacket.segHdr.type )
{
case 9: // Encryption init
case SEGMENTTYPE_ENCRYPTIONINIT: // Encryption init
{
std::string key_phrase( reinterpret_cast< char* >( &inPacket.data[36] ) );
generateEncryptionKey( *reinterpret_cast< uint32_t* >( &inPacket.data[100] ), key_phrase );
@ -500,13 +500,13 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets:
}
case 3: // game packet
case SEGMENTTYPE_IPC: // game packet
{
g_log.info( "GamePacket [" + std::to_string( inPacket.segHdr.type ) + "]" );
handleGamePacket( inPacket );
break;
}
case 7: // keep alive
case SEGMENTTYPE_KEEPALIVE: // keep alive
{
uint32_t id = *reinterpret_cast< uint32_t* >( &inPacket.data[0] );
uint32_t timeStamp = *reinterpret_cast< uint32_t* >( &inPacket.data[4] );

View file

@ -488,7 +488,7 @@ void Core::Entity::Player::updateDbSearchInfo() const
stmtS1->setInt( 2, m_id );
pDb->execute( stmtS1 );
auto stmtS2 = pDb->getPreparedStatement( Db::CHARA_SEARCHINFO_UP_SELECTREGION );
auto stmtS2 = pDb->getPreparedStatement( Db::CHARA_SEARCHINFO_UP_SEARCHCOMMENT );
stmtS2->setString( 1, string( m_searchMessage != nullptr ? m_searchMessage : "" ) );
stmtS2->setInt( 2, m_id );
pDb->execute( stmtS2 );

View file

@ -211,7 +211,7 @@ void Core::Network::GameConnection::handleZonePacket( Core::Network::Packets::FF
pLog->debug( sessionStr + " Undefined Zone IPC : Unknown ( " +
boost::str( boost::format( "%|04X|" ) %
static_cast< uint32_t >( opcode ) ) + " )" );
//pLog->debug( "\n" + pPacket.toString() );
pLog->debug( "Dump:\n" + Util::binaryToHexDump( const_cast< uint8_t* >( &pPacket.data[0] ), pPacket.segHdr.size ) );
}
}
@ -381,7 +381,7 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets:
{
switch( inPacket.segHdr.type )
{
case 1:
case SEGMENTTYPE_SESSIONINIT:
{
char* id = ( char* ) &( inPacket.data[4] );
uint32_t playerId = boost::lexical_cast< uint32_t >( id );
@ -445,12 +445,12 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets:
break;
}
case 3: // game packet
case SEGMENTTYPE_IPC: // game packet
{
queueInPacket( inPacket );
break;
}
case 7: // keep alive
case SEGMENTTYPE_KEEPALIVE: // keep alive
{
uint32_t id = *( uint32_t* ) &inPacket.data[0];
uint32_t timeStamp = *( uint32_t* ) &inPacket.data[4];

View file

@ -7,6 +7,7 @@
#include <Exd/ExdDataGenerated.h>
#include <Network/PacketContainer.h>
#include <Network/CommonActorControl.h>
#include <Network/PacketDef/Zone/ClientZoneDef.h>
#include "Zone/Zone.h"
#include "Zone/ZonePosition.h"
@ -42,15 +43,16 @@ using namespace Core::Network::ActorControl;
void Core::Network::GameConnection::clientTriggerHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket,
Entity::Player& player )
{
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
auto pLog = g_fw.get< Logger >();
uint16_t commandId = *reinterpret_cast< uint16_t* >( &copy.data[0x10] );
uint64_t param1 = *reinterpret_cast< uint64_t* >( &copy.data[0x14] );
uint32_t param11 = *reinterpret_cast< uint32_t* >( &copy.data[0x14] );
uint32_t param12 = *reinterpret_cast< uint32_t* >( &copy.data[0x18] );
uint32_t param2 = *reinterpret_cast< uint32_t* >( &copy.data[0x1C] );
uint64_t param3 = *reinterpret_cast< uint64_t* >( &copy.data[0x28] );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcClientTrigger >( inPacket );
const auto& commandId = packet.data().commandId;
const auto& param1 = *reinterpret_cast< const uint64_t* >( &packet.data().param11 );
const auto& param11 = packet.data().param11;
const auto& param12 = packet.data().param12;
const auto& param2 = packet.data().param2;
const auto& param3 = packet.data().param3;
pLog->debug( "[" + std::to_string( m_pSession->getId() ) + "] Incoming action: " +
boost::str( boost::format( "%|04X|" ) % ( uint32_t ) ( commandId & 0xFFFF ) ) +
@ -64,7 +66,7 @@ void Core::Network::GameConnection::clientTriggerHandler( const Packets::FFXIVAR
switch( commandId )
{
case ClientTriggerType::ToggleSeathe: // Toggle sheathe
case ClientTriggerType::ToggleSheathe: // Toggle sheathe
{
if ( param11 == 1 )
player.setStance( Entity::Chara::Stance::Active );

View file

@ -7,6 +7,7 @@
#include <Network/PacketContainer.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h>
#include <sapphire_zone/Event/EventHandler.h>
#include <Network/PacketDef/Zone/ClientZoneDef.h>
#include "Network/GameConnection.h"
#include "Network/PacketWrappers/ServerNoticePacket.h"
@ -38,10 +39,12 @@ void Core::Network::GameConnection::eventHandlerTalk( const Packets::FFXIVARR_PA
{
auto pScriptMgr = g_fw.get< Scripting::ScriptMgr >();
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
auto actorId = *reinterpret_cast< uint64_t* >( &copy.data[0x10] );
auto eventId = *reinterpret_cast< uint32_t* >( &copy.data[0x18] );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcEventHandlerTalk >( inPacket );
const auto& actorId = packet.data().actorId;
const auto& eventId = packet.data().eventId;
auto eventType = static_cast< uint16_t >( eventId >> 16 );
std::string eventName = "onTalk";
@ -81,12 +84,13 @@ void Core::Network::GameConnection::eventHandlerEmote( const Packets::FFXIVARR_P
auto pScriptMgr = g_fw.get< Scripting::ScriptMgr >();
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
auto actorId = *reinterpret_cast< uint64_t* >( &copy.data[0x10] );
auto eventId = *reinterpret_cast< uint32_t* >( &copy.data[0x18] );
auto emoteId = *reinterpret_cast< uint16_t* >( &copy.data[0x1C] );
auto eventType = static_cast< uint16_t >( eventId >> 16 );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcEventHandlerEmote >( inPacket );
const auto& actorId = packet.data().actorId;
const auto& eventId = packet.data().eventId;
const auto& emoteId = packet.data().emoteId;
const auto eventType = static_cast< uint16_t >( eventId >> 16 );
std::string eventName = "onEmote";
std::string objName = Event::getEventName( eventId );
@ -118,14 +122,12 @@ void Core::Network::GameConnection::eventHandlerWithinRange( const Packets::FFXI
Entity::Player& player )
{
auto pScriptMgr = g_fw.get< Scripting::ScriptMgr >();
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
auto eventId = *reinterpret_cast< uint32_t* >( &copy.data[0x14] );
auto param1 = *reinterpret_cast< uint32_t* >( &copy.data[0x10] );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcEventHandlerWithinRange >( inPacket );
auto x = *reinterpret_cast< float* >( &copy.data[0x18] );
auto y = *reinterpret_cast< float* >( &copy.data[0x1C] );
auto z = *reinterpret_cast< float* >( &copy.data[0x20] );
const auto& eventId = packet.data().eventId;
const auto& param1 = packet.data().param1;
const auto& pos = packet.data().position;
std::string eventName = "onWithinRange";
std::string objName = Event::getEventName( eventId );
@ -134,7 +136,7 @@ void Core::Network::GameConnection::eventHandlerWithinRange( const Packets::FFXI
player.eventStart( player.getId(), eventId, Event::EventHandler::WithinRange, 1, param1 );
pScriptMgr->onWithinRange( player, eventId, param1, x, y, z );
pScriptMgr->onWithinRange( player, eventId, param1, pos.x, pos.y, pos.z );
player.checkEvent( eventId );
}
@ -143,14 +145,11 @@ void Core::Network::GameConnection::eventHandlerOutsideRange( const Packets::FFX
Entity::Player& player )
{
auto pScriptMgr = g_fw.get< Scripting::ScriptMgr >();
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
auto eventId = *reinterpret_cast< uint32_t* >( &copy.data[0x14] );
auto param1 = *reinterpret_cast< uint32_t* >( &copy.data[0x10] );
auto x = *reinterpret_cast< float* >( &copy.data[0x18] );
auto y = *reinterpret_cast< float* >( &copy.data[0x1C] );
auto z = *reinterpret_cast< float* >( &copy.data[0x20] );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcEventHandlerOutsideRange >( inPacket );
const auto& eventId = packet.data().eventId;
const auto& param1 = packet.data().param1;
const auto& pos = packet.data().position;
std::string eventName = "onOutsideRange";
std::string objName = Event::getEventName( eventId );
@ -159,7 +158,7 @@ void Core::Network::GameConnection::eventHandlerOutsideRange( const Packets::FFX
player.eventStart( player.getId(), eventId, Event::EventHandler::WithinRange, 1, param1 );
pScriptMgr->onOutsideRange( player, eventId, param1, x, y, z );
pScriptMgr->onOutsideRange( player, eventId, param1, pos.x, pos.y, pos.z );
player.checkEvent( eventId );
}
@ -168,11 +167,12 @@ void Core::Network::GameConnection::eventHandlerEnterTerritory( const Packets::F
Entity::Player& player )
{
auto pScriptMgr = g_fw.get< Scripting::ScriptMgr >();
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
auto eventId = *reinterpret_cast< uint32_t* >( &copy.data[0x10] );
auto param1 = *reinterpret_cast< uint16_t* >( &copy.data[0x14] );
auto param2 = *reinterpret_cast< uint16_t* >( &copy.data[0x16] );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcEnterTerritoryHandler >( inPacket );
const auto& eventId = packet.data().eventId;
const auto& param1 = packet.data().param1;
const auto& param2 = packet.data().param2;
std::string eventName = "onEnterTerritory";
@ -197,13 +197,12 @@ void Core::Network::GameConnection::eventHandlerEnterTerritory( const Packets::F
void Core::Network::GameConnection::eventHandlerReturn( const Packets::FFXIVARR_PACKET_RAW& inPacket,
Entity::Player& player )
{
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
auto eventId = *reinterpret_cast< uint32_t* >( &copy.data[0x10] );
auto scene = *reinterpret_cast< uint16_t* >( &copy.data[0x14] );
auto param1 = *reinterpret_cast< uint16_t* >( &copy.data[0x16] );
auto param2 = *reinterpret_cast< uint16_t* >( &copy.data[0x18] );
auto param3 = *reinterpret_cast< uint16_t* >( &copy.data[0x1C] );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcEventHandlerReturn >( inPacket );
const auto& eventId = packet.data().eventId;
const auto& scene = packet.data().scene;
const auto& param1 = packet.data().param1;
const auto& param2 = packet.data().param2;
const auto& param3 = packet.data().param3;
std::string eventName = Event::getEventName( eventId );
@ -244,15 +243,11 @@ void Core::Network::GameConnection::eventHandlerReturn( const Packets::FFXIVARR_
void Core::Network::GameConnection::eventHandlerLinkshell( const Packets::FFXIVARR_PACKET_RAW& inPacket,
Entity::Player& player )
{
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
const auto packet = ZoneChannelPacket< Client::FFXIVIpcLinkshellEventHandler >( inPacket );
auto eventId = *reinterpret_cast< uint32_t* >( &copy.data[0x10] );
auto scene = *reinterpret_cast< uint16_t* >( &copy.data[0x14] );
auto lsName = std::string( reinterpret_cast< char* >( &copy.data[0x17] ) );
auto linkshellEvent = makeZonePacket< FFXIVIpcEventLinkshell >( player.getId() );
linkshellEvent->data().eventId = eventId;
linkshellEvent->data().scene = static_cast< uint8_t >( scene );
auto linkshellEvent = makeZonePacket< Server::FFXIVIpcEventLinkshell >( player.getId() );
linkshellEvent->data().eventId = packet.data().eventId;
linkshellEvent->data().scene = static_cast< uint8_t >( packet.data().scene );
linkshellEvent->data().param3 = 1;
linkshellEvent->data().unknown1 = 0x15a;
player.queuePacket( linkshellEvent );

View file

@ -6,6 +6,7 @@
#include <Logging/Logger.h>
#include <Network/PacketContainer.h>
#include <Network/CommonActorControl.h>
#include <Network/PacketDef/Zone/ClientZoneDef.h>
#include <unordered_map>
@ -91,12 +92,11 @@ void Core::Network::GameConnection::gm1Handler( const Packets::FFXIVARR_PACKET_R
if( player.getGmRank() <= 0 )
return;
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
auto commandId = *reinterpret_cast< uint32_t* >( &copy.data[0x10] );
uint32_t param1 = *reinterpret_cast< uint32_t* >( &copy.data[0x14] );
uint32_t param2 = *reinterpret_cast< uint32_t* >( &copy.data[0x18] );
uint32_t param3 = *reinterpret_cast< uint32_t* >( &copy.data[0x28] );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcGmCommand1 >( inPacket );
const auto& commandId = packet.data().commandId;
const auto& param1 = packet.data().param1;
const auto& param2 = packet.data().param2;
const auto& param3 = packet.data().param3;
auto pLog = g_fw.get< Logger >();
pLog->debug( player.getName() + " used GM1 commandId: " + std::to_string( commandId ) +
@ -310,9 +310,11 @@ void Core::Network::GameConnection::gm1Handler( const Packets::FFXIVARR_PACKET_R
}
case GmCommand::Item:
{
if( param2 < 1 || param2 > 99 )
auto quantity = param2;
if( quantity < 1 || quantity > 999 )
{
param2 = 1;
quantity = 1;
}
if( ( param1 == 0xcccccccc ) )
@ -321,7 +323,7 @@ void Core::Network::GameConnection::gm1Handler( const Packets::FFXIVARR_PACKET_R
return;
}
if( !targetPlayer->addItem( -1, param1, param2 ) )
if( !targetPlayer->addItem( -1, param1, quantity ) )
player.sendUrgent( "Item " + std::to_string( param1 ) + " not found..." );
break;
}
@ -489,10 +491,10 @@ void Core::Network::GameConnection::gm2Handler( const Packets::FFXIVARR_PACKET_R
auto pLog = g_fw.get< Logger >();
auto pServerZone = g_fw.get< ServerZone >();
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
auto commandId = *reinterpret_cast< uint32_t* >( &copy.data[0x10] );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcGmCommand2 >( inPacket );
auto param1 = std::string( reinterpret_cast< char* >( &copy.data[0x24] ) );
const auto& commandId = packet.data().commandId;
const auto& param1 = std::string( packet.data().param1 );
pLog->debug( player.getName() + " used GM2 commandId: " + std::to_string( commandId ) + ", params: " + param1 );

View file

@ -5,6 +5,7 @@
#include <Network/GamePacketNew.h>
#include <Logging/Logger.h>
#include <Network/PacketContainer.h>
#include <Network/PacketDef/Zone/ClientZoneDef.h>
#include "Network/GameConnection.h"
#include "Network/PacketWrappers/ServerNoticePacket.h"
@ -29,39 +30,26 @@ using namespace Core::Common;
using namespace Core::Network::Packets;
using namespace Core::Network::Packets::Server;
enum InventoryOperation
{
Discard = 0x07,
Move = 0x08,
Swap = 0x09,
Merge = 0x0C,
Split = 0x0A
};
void Core::Network::GameConnection::inventoryModifyHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket,
Entity::Player& player )
{
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
auto seq = *reinterpret_cast< uint32_t* >( &copy.data[0x10] );
auto action = *reinterpret_cast< uint8_t* >( &copy.data[0x14] );
auto fromSlot = *reinterpret_cast< uint8_t* >( &copy.data[0x20] );
auto toSlot = *reinterpret_cast< uint8_t* >( &copy.data[0x34] );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcInventoryModifyHandler >( inPacket );
auto fromContainer = *reinterpret_cast< uint16_t* >( &copy.data[0x1C] );
auto toContainer = *reinterpret_cast< uint16_t* >( &copy.data[0x30] );
const auto& action = packet.data().action;
const auto& splitCount = packet.data().splitCount;
// todo: check packet handler in game and see if this is sent as a u16 or u32
auto splitCount = *reinterpret_cast< uint16_t* >( &copy.data[0x38] );
const auto& fromSlot = packet.data().fromSlot;
const auto& fromContainer = packet.data().fromContainer;
const auto& toSlot = packet.data().toSlot;
const auto& toContainer = packet.data().toContainer;
auto ackPacket = makeZonePacket< FFXIVIpcInventoryActionAck >( player.getId() );
ackPacket->data().sequence = seq;
auto ackPacket = makeZonePacket< Server::FFXIVIpcInventoryActionAck >( player.getId() );
ackPacket->data().sequence = packet.data().seq;
ackPacket->data().type = 7;
player.queuePacket( ackPacket );
auto pLog = g_fw.get< Logger >();
//pLog->debug( inPacket.toString() );
pLog->debug( "InventoryAction: " + std::to_string( action ) );
// TODO: other inventory operations need to be implemented

View file

@ -11,7 +11,7 @@
#include <Util/Util.h>
#include <unordered_map>
#include <Network/PacketDef/Zone/ClientZoneDef.h>
#include <Logging/Logger.h>
#include "Network/GameConnection.h"
@ -63,15 +63,14 @@ void Core::Network::GameConnection::fcInfoReqHandler( const Core::Network::Packe
void Core::Network::GameConnection::setSearchInfoHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket,
Entity::Player& player )
{
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
const auto packet = ZoneChannelPacket< Client::FFXIVIpcSetSearchInfo >( inPacket );
auto inval = *reinterpret_cast< uint32_t* >( &copy.data[0x10] );
auto inval1 = *reinterpret_cast< uint32_t* >( &copy.data[0x14] );
auto status = *reinterpret_cast< uint64_t* >( &copy.data[0x10] );
const auto& inval = packet.data().status1;
const auto& inval1 = packet.data().status2;
const auto& status = packet.data().status;
const auto& selectRegion = packet.data().language;
auto selectRegion = copy.data[0x21];
player.setSearchInfo( selectRegion, 0, reinterpret_cast< char* >( &copy.data[0x22] ) );
player.setSearchInfo( selectRegion, 0, packet.data().searchComment );
player.setOnlineStatusMask( status );
@ -261,8 +260,8 @@ void Core::Network::GameConnection::zoneLineHandler( const Core::Network::Packet
{
auto pTeriMgr = g_fw.get< TerritoryMgr >();
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
auto zoneLineId = *reinterpret_cast< uint32_t* >( &copy.data[0x10] );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcZoneLineHandler >( inPacket );
const auto& zoneLineId = packet.data().zoneLineId;
player.sendDebug( "Walking ZoneLine " + std::to_string( zoneLineId ) );
@ -305,20 +304,18 @@ void Core::Network::GameConnection::zoneLineHandler( const Core::Network::Packet
void Core::Network::GameConnection::discoveryHandler( const Core::Network::Packets::FFXIVARR_PACKET_RAW& inPacket,
Entity::Player& player )
{
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
auto ref_position_id = *reinterpret_cast< uint32_t* >( &copy.data[0x10] );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcDiscoveryHandler >( inPacket );
const auto& positionRef = packet.data().positionRef;
auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >();
auto pQR = pDb->query( "SELECT id, map_id, discover_id "
"FROM discoveryinfo "
"WHERE id = " + std::to_string( ref_position_id ) + ";" );
"WHERE id = " + std::to_string( positionRef ) + ";" );
if( !pQR->next() )
{
player.sendNotice( "Discovery ref pos ID: " + std::to_string( ref_position_id ) + " not found. " );
player.sendNotice( "Discovery ref pos ID: " + std::to_string( positionRef ) + " not found. " );
return;
}
@ -327,7 +324,7 @@ void Core::Network::GameConnection::discoveryHandler( const Core::Network::Packe
discoveryPacket->data().map_part_id = pQR->getUInt( 3 );
player.queuePacket( discoveryPacket );
player.sendNotice( "Discovery ref pos ID: " + std::to_string( ref_position_id ) );
player.sendNotice( "Discovery ref pos ID: " + std::to_string( positionRef ) );
player.discover( pQR->getUInt16( 2 ), pQR->getUInt16( 3 ) );
@ -371,10 +368,9 @@ void Core::Network::GameConnection::blackListHandler( const Core::Network::Packe
void Core::Network::GameConnection::pingHandler( const Core::Network::Packets::FFXIVARR_PACKET_RAW& inPacket,
Entity::Player& player )
{
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
auto inVal = *reinterpret_cast< uint32_t* >( &copy.data[0x10] );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcPingHandler >( inPacket );
queueOutPacket( boost::make_shared< PingPacket>( player, inVal ) );
queueOutPacket( boost::make_shared< Server::PingPacket >( player, packet.data().timestamp ) );
player.setLastPing( static_cast< uint32_t >( time( nullptr ) ) );
}
@ -465,23 +461,19 @@ void Core::Network::GameConnection::chatHandler( const Core::Network::Packets::F
{
auto pDebugCom = g_fw.get< DebugCommandHandler >();
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
const auto packet = ZoneChannelPacket< Client::FFXIVIpcChatHandler >( inPacket );
std::string chatString( reinterpret_cast< char* >( &copy.data[0x2a] ) );
auto sourceId = *reinterpret_cast< uint32_t* >( &copy.data[0x14] );
if( chatString.at( 0 ) == '!' )
if( packet.data().message[0] == '!' )
{
// execute game console command
pDebugCom->execCommand( const_cast< char * >( chatString.c_str() ) + 1, player );
pDebugCom->execCommand( const_cast< char* >( packet.data().message ) + 1, player );
return;
}
ChatType chatType = static_cast< ChatType >( inPacket.data[0x28] );
auto chatType = packet.data().chatType;
//ToDo, need to implement sending GM chat types.
auto chatPacket = boost::make_shared< ChatPacket >( player, chatType, chatString );
auto chatPacket = boost::make_shared< Server::ChatPacket >( player, chatType, packet.data().message );
switch( chatType )
{
@ -537,19 +529,16 @@ void Core::Network::GameConnection::logoutHandler( const Core::Network::Packets:
void Core::Network::GameConnection::tellHandler( const Core::Network::Packets::FFXIVARR_PACKET_RAW& inPacket,
Entity::Player& player )
{
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
std::string targetPcName( reinterpret_cast< char* >( &copy.data[0x14] ) );
std::string msg( reinterpret_cast< char* >( &copy.data[0x34] ) );
const auto packet = ZoneChannelPacket< Client::FFXIVIpcTellHandler >( inPacket );
auto pZoneServer = g_fw.get< ServerZone >();
auto pSession = pZoneServer->getSession( targetPcName );
auto pSession = pZoneServer->getSession( packet.data().targetPCName );
if( !pSession )
{
auto tellErrPacket = makeZonePacket< FFXIVIpcTellErrNotFound >( player.getId() );
strcpy( tellErrPacket->data().receipientName, targetPcName.c_str() );
strcpy( tellErrPacket->data().receipientName, packet.data().targetPCName );
sendSinglePacket( tellErrPacket );
return;
}
@ -578,7 +567,7 @@ void Core::Network::GameConnection::tellHandler( const Core::Network::Packets::F
}
auto tellPacket = makeChatPacket< FFXIVIpcTell >( player.getId() );
strcpy( tellPacket->data().msg, msg.c_str() );
strcpy( tellPacket->data().msg, packet.data().message );
strcpy( tellPacket->data().receipientName, player.getName().c_str() );
// TODO: do these have a meaning?
//tellPacket.data().u1 = 0x92CD7337;

View file

@ -6,6 +6,7 @@
#include <Network/GamePacketNew.h>
#include <Network/PacketContainer.h>
#include <Network/CommonActorControl.h>
#include <Network/PacketDef/Zone/ClientZoneDef.h>
#include <Logging/Logger.h>
#include "Network/GameConnection.h"
@ -38,14 +39,12 @@ using namespace Core::Network::ActorControl;
void Core::Network::GameConnection::skillHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket,
Entity::Player& player )
{
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
const auto packet = ZoneChannelPacket< Client::FFXIVIpcSkillHandler >( inPacket );
uint8_t type = inPacket.data[0x11];
auto action = *reinterpret_cast< uint32_t* >( &copy.data[0x14] );
auto useCount = *reinterpret_cast< uint32_t* >( &copy.data[0x18] );
auto targetId = *reinterpret_cast< uint64_t* >( &copy.data[0x20] );
const auto& type = packet.data().type;
const auto& action = packet.data().actionId;
const auto& useCount = packet.data().useCount;
const auto& targetId = packet.data().targetId;
player.sendDebug( "Skill type:" + std::to_string( type ) );

View file

@ -76,7 +76,7 @@ bool Core::Scripting::ScriptMgr::init()
scriptsLoaded++;
}
pLog->info( "ScriptMgr: Loaded " + std::to_string( scriptsLoaded ) + "/" + std::to_string( scriptsFound ) + " scripts successfully" );
pLog->info( "ScriptMgr: Loaded " + std::to_string( scriptsLoaded ) + "/" + std::to_string( scriptsFound ) + " modules" );
watchDirectories();