diff --git a/src/common/Forwards.h b/src/common/Forwards.h index 2ebc1822..663d5468 100644 --- a/src/common/Forwards.h +++ b/src/common/Forwards.h @@ -1,5 +1,5 @@ -#ifndef _COMMON_FORWARDS_H -#define _COMMON_FORWARDS_H +#ifndef COMMON_FORWARDS_H +#define COMMON_FORWARDS_H #include diff --git a/src/common/Network/GamePacketNew.h b/src/common/Network/GamePacketNew.h index bc3f3b39..f2cc6303 100644 --- a/src/common/Network/GamePacketNew.h +++ b/src/common/Network/GamePacketNew.h @@ -1,5 +1,5 @@ -#ifndef _GAMEPACKETNEW_H -#define _GAMEPACKETNEW_H +#ifndef _GAMEPACKET_NEW_H +#define _GAMEPACKET_NEW_H #include #include @@ -27,6 +27,10 @@ using ZoneChannelPacket = FFXIVIpcPacket< T, ServerZoneIpcType >; template< class T > using ChatChannelPacket = FFXIVIpcPacket< T, ServerChatIpcType >; +template< class T > +using LobbyChannelPacket = FFXIVIpcPacket< T, ServerLobbyIpcType >; + + template< class T, typename... Args > boost::shared_ptr< ZoneChannelPacket< T > > makeZonePacket( Args... args ) { @@ -39,6 +43,12 @@ boost::shared_ptr< ChatChannelPacket< T > > makeChatPacket( Args... args ) return boost::make_shared< ChatChannelPacket< T > >( args... ); } +template< class T, typename... Args > +boost::shared_ptr< LobbyChannelPacket< T > > makeLobbyPacket( Args... args ) +{ + return boost::make_shared< LobbyChannelPacket< T > >( args... ); +} + /** * The base implementation of a game packet. Needed for parsing packets. */ diff --git a/src/common/Network/PacketContainer.h b/src/common/Network/PacketContainer.h index dc020f19..6d1995f5 100644 --- a/src/common/Network/PacketContainer.h +++ b/src/common/Network/PacketContainer.h @@ -6,12 +6,13 @@ #include "Common.h" #include "CommonNetwork.h" #include "GamePacketNew.h" +#include "Forwards.h" namespace Core { namespace Network { namespace Packets { -class GamePacket; +typedef boost::shared_ptr< FFXIVPacketBase > FFXIVPacketBasePtr; class PacketContainer { diff --git a/src/servers/sapphire_lobby/Forwards.h b/src/servers/sapphire_lobby/Forwards.h index 8771e953..43d6703b 100644 --- a/src/servers/sapphire_lobby/Forwards.h +++ b/src/servers/sapphire_lobby/Forwards.h @@ -27,6 +27,7 @@ namespace Core namespace Packets { TYPE_FORWARD( GamePacket ); + TYPE_FORWARD( FFXIVPacketBase ); } } diff --git a/src/servers/sapphire_lobby/GameConnection.cpp b/src/servers/sapphire_lobby/GameConnection.cpp index 8c03bd9b..eff55a8c 100644 --- a/src/servers/sapphire_lobby/GameConnection.cpp +++ b/src/servers/sapphire_lobby/GameConnection.cpp @@ -107,11 +107,10 @@ void Core::Network::GameConnection::OnError( const boost::system::error_code & e void Core::Network::GameConnection::sendError( uint64_t sequence, uint32_t errorcode, uint16_t messageId, uint32_t tmpId ) { - GamePacketNew< FFXIVIpcLobbyError, ServerLobbyIpcType > errorPacket( tmpId ); - - errorPacket.data().seq = sequence; - errorPacket.data().error_id = errorcode; - errorPacket.data().message_id = messageId; + auto errorPacket = makeLobbyPacket< FFXIVIpcLobbyError >( tmpId ); + errorPacket->data().seq = sequence; + errorPacket->data().error_id = errorcode; + errorPacket->data().message_id = messageId; Packets::LobbyPacketContainer pRP( m_encKey ); pRP.addPacket( errorPacket ); @@ -126,20 +125,19 @@ void Core::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet, ui g_log.info( "[" + std::to_string( m_pSession->getAccountID() ) + "] ReqCharList" ); Packets::LobbyPacketContainer pRP( m_encKey ); - GamePacketNew< FFXIVIpcServerList, ServerLobbyIpcType > serverListPacket( tmpId ); - serverListPacket.data().seq = 1; - serverListPacket.data().offset = 0; - serverListPacket.data().numServers = 1; - serverListPacket.data().server[0].id = g_serverLobby.getConfig()->getValue( "Lobby.WorldID", 1 ); - serverListPacket.data().server[0].index = 0; - serverListPacket.data().final = 1; - strcpy( serverListPacket.data().server[0].name, g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); - + auto serverListPacket = makeLobbyPacket< FFXIVIpcServerList >( tmpId ); + serverListPacket->data().seq = 1; + serverListPacket->data().offset = 0; + serverListPacket->data().numServers = 1; + serverListPacket->data().server[0].id = g_serverLobby.getConfig()->getValue( "Lobby.WorldID", 1 ); + serverListPacket->data().server[0].index = 0; + serverListPacket->data().final = 1; + strcpy( serverListPacket->data().server[0].name, + g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); pRP.addPacket( serverListPacket ); - GamePacketNew< FFXIVIpcRetainerList, ServerLobbyIpcType > retainerListPacket( tmpId ); - retainerListPacket.data().padding[8] = 1; - + auto retainerListPacket = makeLobbyPacket< FFXIVIpcRetainerList >( tmpId ); + retainerListPacket->data().padding[8] = 1; pRP.addPacket( retainerListPacket ); sendPacket( pRP ); @@ -150,11 +148,10 @@ void Core::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet, ui for( uint8_t i = 0; i < 4; i++ ) { - GamePacketNew< FFXIVIpcCharList, ServerLobbyIpcType > charListPacket( tmpId ); - - charListPacket.data().seq = sequence; - charListPacket.data().numInPacket = 2; - charListPacket.data().counter = i * 4; + auto charListPacket = makeLobbyPacket< FFXIVIpcCharList >( tmpId ); + charListPacket->data().seq = sequence; + charListPacket->data().numInPacket = 2; + charListPacket->data().counter = i * 4; for( uint8_t j = 0; j < 2; j++ ) @@ -173,7 +170,7 @@ void Core::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet, ui strcpy( details.nameChara, get< 0 >( charEntry ).c_str() ); strcpy( details.nameServer, g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); - charListPacket.data().charaDetails[j] = details; + charListPacket->data().charaDetails[j] = details; g_log.debug( "[" + std::to_string( charIndex ) + "] " + std::to_string( details.index ) + " - " + get< 0 >( charEntry ) + " - " + @@ -188,12 +185,12 @@ void Core::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet, ui // TODO: Eventually move to account info storage if( i == 3 ) { - charListPacket.data().entitledExpansion = 2; - charListPacket.data().maxCharOnWorld = 8; - charListPacket.data().unknown8 = 8; - charListPacket.data().veteranRank = 12; - charListPacket.data().counter = ( i * 4 ) + 1; - charListPacket.data().unknown4 = 128; + charListPacket->data().entitledExpansion = 2; + charListPacket->data().maxCharOnWorld = 8; + charListPacket->data().unknown8 = 8; + charListPacket->data().veteranRank = 12; + charListPacket->data().counter = ( i * 4 ) + 1; + charListPacket->data().unknown4 = 128; } Packets::LobbyPacketContainer pRP( m_encKey ); @@ -234,16 +231,14 @@ void Core::Network::GameConnection::enterWorld( FFXIVARR_PACKET_RAW& packet, uin Packets::LobbyPacketContainer pRP( m_encKey ); - GamePacketNew< FFXIVIpcEnterWorld, ServerLobbyIpcType > enterWorldPacket( tmpId ); - - enterWorldPacket.data().contentId = lookupId; - - enterWorldPacket.data().seq = sequence; - strcpy( enterWorldPacket.data().host, g_serverLobby.getConfig()->getValue< std::string >( "GlobalNetwork.ZoneHost" ).c_str() ); - enterWorldPacket.data().port = g_serverLobby.getConfig()->getValue< uint16_t >( "GlobalNetwork.ZonePort" ); - enterWorldPacket.data().charId = logInCharId; - memcpy( enterWorldPacket.data().sid, m_pSession->getSessionId(), 66 ); - + auto enterWorldPacket = makeLobbyPacket< FFXIVIpcEnterWorld >( tmpId ); + enterWorldPacket->data().contentId = lookupId; + enterWorldPacket->data().seq = sequence; + strcpy( enterWorldPacket->data().host, + g_serverLobby.getConfig()->getValue< std::string >( "GlobalNetwork.ZoneHost" ).c_str() ); + enterWorldPacket->data().port = g_serverLobby.getConfig()->getValue< uint16_t >( "GlobalNetwork.ZonePort" ); + enterWorldPacket->data().charId = logInCharId; + memcpy( enterWorldPacket->data().sid, m_pSession->getSessionId(), 66 ); pRP.addPacket( enterWorldPacket ); sendPacket( pRP ); } @@ -265,13 +260,13 @@ bool Core::Network::GameConnection::sendServiceAccountList( FFXIVARR_PACKET_RAW& { g_log.Log( LoggingSeverity::info, "Found session linked to accountId: " + std::to_string( pSession->getAccountID() ) ); m_pSession = pSession; - GamePacketNew< FFXIVIpcServiceIdInfo, ServerLobbyIpcType > serviceIdInfoPacket( tmpId ); - sprintf( serviceIdInfoPacket.data().serviceAccount[0].name, "FINAL FANTASY XIV" ); - serviceIdInfoPacket.data().numServiceAccounts = 1; - serviceIdInfoPacket.data().u1 = 3; - serviceIdInfoPacket.data().u2 = 0x99; - serviceIdInfoPacket.data().serviceAccount[0].id = 0x002E4A2B; + auto serviceIdInfoPacket = makeLobbyPacket< FFXIVIpcServiceIdInfo >( tmpId ); + sprintf( serviceIdInfoPacket->data().serviceAccount[0].name, "FINAL FANTASY XIV" ); + serviceIdInfoPacket->data().numServiceAccounts = 1; + serviceIdInfoPacket->data().u1 = 3; + serviceIdInfoPacket->data().u2 = 0x99; + serviceIdInfoPacket->data().serviceAccount[0].id = 0x002E4A2B; Packets::LobbyPacketContainer pRP( m_encKey ); pRP.addPacket( serviceIdInfoPacket ); @@ -316,18 +311,17 @@ bool Core::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW& pac return true; } - GamePacketNew< FFXIVIpcCharCreate, ServerLobbyIpcType > charCreatePacket( tmpId ); - - charCreatePacket.data().content_id = newContentId; - strcpy( charCreatePacket.data().name, name.c_str() ); - strcpy( charCreatePacket.data().world, g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); - charCreatePacket.data().type = 1; - charCreatePacket.data().seq = sequence; - charCreatePacket.data().unknown = 1; - charCreatePacket.data().unknown_2 = 1; - charCreatePacket.data().unknown_7 = 1; - charCreatePacket.data().unknown_8 = 1; - + auto charCreatePacket = makeLobbyPacket< FFXIVIpcCharCreate >( tmpId ); + charCreatePacket->data().content_id = newContentId; + strcpy( charCreatePacket->data().name, name.c_str() ); + strcpy( charCreatePacket->data().world, + g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); + charCreatePacket->data().type = 1; + charCreatePacket->data().seq = sequence; + charCreatePacket->data().unknown = 1; + charCreatePacket->data().unknown_2 = 1; + charCreatePacket->data().unknown_7 = 1; + charCreatePacket->data().unknown_8 = 1; pRP.addPacket( charCreatePacket ); sendPacket( pRP ); } @@ -340,18 +334,17 @@ bool Core::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW& pac { Packets::LobbyPacketContainer pRP( m_encKey ); - GamePacketNew< FFXIVIpcCharCreate, ServerLobbyIpcType > charCreatePacket( tmpId ); - - charCreatePacket.data().content_id = newContentId; - strcpy( charCreatePacket.data().name, name.c_str() ); - strcpy( charCreatePacket.data().world, g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); - charCreatePacket.data().type = 2; - charCreatePacket.data().seq = sequence; - charCreatePacket.data().unknown = 1; - charCreatePacket.data().unknown_2 = 1; - charCreatePacket.data().unknown_7 = 1; - charCreatePacket.data().unknown_8 = 1; - + auto charCreatePacket = makeLobbyPacket< FFXIVIpcCharCreate >( tmpId ); + charCreatePacket->data().content_id = newContentId; + strcpy( charCreatePacket->data().name, name.c_str() ); + strcpy( charCreatePacket->data().world, + g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); + charCreatePacket->data().type = 2; + charCreatePacket->data().seq = sequence; + charCreatePacket->data().unknown = 1; + charCreatePacket->data().unknown_2 = 1; + charCreatePacket->data().unknown_7 = 1; + charCreatePacket->data().unknown_8 = 1; pRP.addPacket( charCreatePacket ); sendPacket( pRP ); } @@ -370,18 +363,17 @@ bool Core::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW& pac if( g_restConnector.deleteCharacter( ( char* )m_pSession->getSessionId(), name ) ) { - GamePacketNew< FFXIVIpcCharCreate, ServerLobbyIpcType > charCreatePacket( tmpId ); - - //charCreatePacket.data().content_id = deletePlayer.getContentId(); - charCreatePacket.data().content_id = 0; - strcpy( charCreatePacket.data().name, name.c_str() ); - strcpy( charCreatePacket.data().world, g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); - charCreatePacket.data().type = 4; - charCreatePacket.data().seq = sequence; - charCreatePacket.data().unknown = 1; - charCreatePacket.data().unknown_2 = 1; - charCreatePacket.data().unknown_7 = 1; - charCreatePacket.data().unknown_8 = 1; + auto charCreatePacket = makeLobbyPacket< FFXIVIpcCharCreate >( tmpId ); + //charCreatePacket->data().content_id = deletePlayer.getContentId(); + charCreatePacket->data().content_id = 0; + strcpy( charCreatePacket->data().name, name.c_str() ); + strcpy( charCreatePacket->data().world, g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); + charCreatePacket->data().type = 4; + charCreatePacket->data().seq = sequence; + charCreatePacket->data().unknown = 1; + charCreatePacket->data().unknown_2 = 1; + charCreatePacket->data().unknown_7 = 1; + charCreatePacket->data().unknown_8 = 1; Packets::LobbyPacketContainer pRP( m_encKey ); pRP.addPacket( charCreatePacket ); @@ -454,14 +446,7 @@ void Core::Network::GameConnection::sendPackets( Packets::PacketContainer * pPac Send( sendBuffer ); } -void Core::Network::GameConnection::sendSinglePacket( Packets::GamePacket * pPacket ) -{ - PacketContainer pRP = PacketContainer(); - pRP.addPacket( *pPacket ); - sendPackets( &pRP ); -} - -void Core::Network::GameConnection::sendSinglePacket( Packets::GamePacket & pPacket ) +void Core::Network::GameConnection::sendSinglePacket( FFXIVPacketBasePtr pPacket ) { PacketContainer pRP = PacketContainer(); pRP.addPacket( pPacket ); @@ -505,19 +490,14 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets: generateEncryptionKey( *reinterpret_cast< uint32_t* >( &inPacket.data[100] ), key_phrase ); m_bEncryptionInitialized = true; - std::vector< uint8_t > samplePacket( 0x290 ); - memset( &samplePacket[0], 0, 0x290 ); - - *reinterpret_cast< uint16_t* >( &samplePacket[0] ) = 0x290; - *reinterpret_cast< uint8_t* >( &samplePacket[0] + 0x0C ) = 0x0A; - *reinterpret_cast< uint32_t* >( &samplePacket[0] + 0x10 ) = 0xE0003C2A; + auto pe1 = boost::make_shared< FFXIVRawPacket >( 0x0A, 0x290, 0, 0 ); + *reinterpret_cast< uint32_t* >(&pe1->data()[0]) = 0xE0003C2A; BlowFish blowfish; blowfish.initialize( m_encKey, 0x10 ); - blowfish.Encode( &samplePacket[0] + 0x10, &samplePacket[0] + 0x10, 0x280 ); + blowfish.Encode( &pe1->data()[0], &pe1->data()[0], 0x280 ); - auto packet = GamePacket( reinterpret_cast< char* >( &samplePacket[0] ), static_cast< uint16_t >( samplePacket.size() ) ); - sendSinglePacket( packet ); + sendSinglePacket( pe1 ); break; } @@ -533,10 +513,10 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets: uint32_t id = *reinterpret_cast< uint32_t* >( &inPacket.data[0] ); uint32_t timeStamp = *reinterpret_cast< uint32_t* >( &inPacket.data[4] ); - GamePacket pPe( 0x00, 0x18, 0, 0, 0x08 ); - pPe.setValAt< uint32_t >( 0x10, id ); - pPe.setValAt< uint32_t >( 0x14, timeStamp ); - sendSinglePacket( &pPe ); + auto pe4 = boost::make_shared< FFXIVRawPacket >( 0x08, 0x18, 0, 0 ); + *(unsigned int*)(&pe4->data()[0]) = id; + *(unsigned int*)(&pe4->data()[4]) = timeStamp; + sendSinglePacket( pe4 ); break; } diff --git a/src/servers/sapphire_lobby/GameConnection.h b/src/servers/sapphire_lobby/GameConnection.h index 54d3f915..75830060 100644 --- a/src/servers/sapphire_lobby/GameConnection.h +++ b/src/servers/sapphire_lobby/GameConnection.h @@ -65,15 +65,14 @@ public: void handleGamePacket( Packets::FFXIVARR_PACKET_RAW &pPacket ); - void handlePacket( Packets::GamePacketPtr pPacket ); + void handlePacket( Packets::FFXIVPacketBasePtr pPacket ); void sendPackets( Packets::PacketContainer * pPacket ); void sendPacket( Packets::LobbyPacketContainer& pLpc ); - void sendSinglePacket( Packets::GamePacket * pPacket ); - - void sendSinglePacket( Packets::GamePacket & pPacket ); + void sendSinglePacket( Packets::FFXIVPacketBasePtr pPacket ); + }; diff --git a/src/servers/sapphire_lobby/LobbyPacketContainer.cpp b/src/servers/sapphire_lobby/LobbyPacketContainer.cpp index 43c71de5..11e23a10 100644 --- a/src/servers/sapphire_lobby/LobbyPacketContainer.cpp +++ b/src/servers/sapphire_lobby/LobbyPacketContainer.cpp @@ -1,58 +1,56 @@ #include "LobbyPacketContainer.h" +#include #include #include #include +#include -namespace Core { - namespace Network { - namespace Packets { +using namespace Core::Common; +using namespace Core::Network::Packets; - LobbyPacketContainer::LobbyPacketContainer( uint8_t* encKey ) - { - memset( &m_header, 0, sizeof( Core::Network::Packets::FFXIVARR_PACKET_HEADER ) ); - m_header.size = sizeof( Core::Network::Packets::FFXIVARR_PACKET_HEADER ); +Core::Network::Packets::LobbyPacketContainer::LobbyPacketContainer( uint8_t* encKey ) +{ + memset( &m_header, 0, sizeof( Core::Network::Packets::FFXIVARR_PACKET_HEADER ) ); + m_header.size = sizeof( Core::Network::Packets::FFXIVARR_PACKET_HEADER ); - m_encKey = encKey; + m_encKey = encKey; - memset( m_dataBuf, 0, 0x1570 ); - } - - LobbyPacketContainer::~LobbyPacketContainer() - { - m_entryList.clear(); - } - - void LobbyPacketContainer::addPacket( GamePacketPtr pEntry ) - { - memcpy( m_dataBuf + m_header.size, pEntry->getData(), pEntry->getSize() ); - - // encryption key is set, we want to encrypt this packet - if( m_encKey != NULL ) - { - BlowFish blowfish; - blowfish.initialize( m_encKey, 0x10 ); - blowfish.Encode( m_dataBuf + m_header.size + 0x10, m_dataBuf + m_header.size + 0x10, pEntry->getSize() - 0x10 ); - } - - m_header.size += pEntry->getSize(); - m_header.count++; - } - - uint16_t LobbyPacketContainer::getSize() const - { - return m_header.size; - } - - uint8_t* LobbyPacketContainer::getRawData( bool addstuff ) - { - if( addstuff ) - { - m_header.unknown_0 = 0xff41a05252; - m_header.timestamp = Core::Util::getTimeMs(); - } - memcpy( m_dataBuf, &m_header, sizeof( Core::Network::Packets::FFXIVARR_PACKET_HEADER ) ); - return m_dataBuf; - } - } - } + memset( m_dataBuf, 0, 0x1570 ); +} + +Core::Network::Packets::LobbyPacketContainer::~LobbyPacketContainer() +{ + m_entryList.clear(); +} + +void Core::Network::Packets::LobbyPacketContainer::addPacket( FFXIVPacketBasePtr pEntry ) +{ + memcpy( m_dataBuf + m_header.size, &pEntry->getData()[0], pEntry->getSize() ); + + // encryption key is set, we want to encrypt this packet + if( m_encKey != nullptr ) + { + BlowFish blowfish; + blowfish.initialize( m_encKey, 0x10 ); + blowfish.Encode( m_dataBuf + m_header.size + 0x10, m_dataBuf + m_header.size + 0x10, pEntry->getSize() - 0x10 ); + } + + m_header.size += pEntry->getSize(); + m_header.count++; +} + +uint16_t Core::Network::Packets::LobbyPacketContainer::getSize() const +{ + return m_header.size; +} + +uint8_t* Core::Network::Packets::LobbyPacketContainer::getRawData( bool addstuff ) +{ + if( addstuff ) + { + m_header.unknown_0 = 0xff41a05252; + m_header.timestamp = Core::Util::getTimeMs(); + } + memcpy( m_dataBuf, &m_header, sizeof( Core::Network::Packets::FFXIVARR_PACKET_HEADER ) ); + return m_dataBuf; } diff --git a/src/servers/sapphire_lobby/LobbyPacketContainer.h b/src/servers/sapphire_lobby/LobbyPacketContainer.h index c0425a4f..6ac7ea77 100644 --- a/src/servers/sapphire_lobby/LobbyPacketContainer.h +++ b/src/servers/sapphire_lobby/LobbyPacketContainer.h @@ -1,5 +1,5 @@ -#ifndef _LobbyPacketContainer_H_ -#define _LobbyPacketContainer_H_ +#ifndef LOBBY_PACKET_CONTAINER_H_ +#define LOBBY_PACKET_CONTAINER_H_ #include #include @@ -10,34 +10,35 @@ #include "Forwards.h" namespace Core { - namespace Network { - namespace Packets { - class GamePacket; +namespace Network { +namespace Packets { - class LobbyPacketContainer - { - public: - LobbyPacketContainer( uint8_t* encKey = nullptr ); - ~LobbyPacketContainer(); +typedef boost::shared_ptr< FFXIVPacketBase > FFXIVPacketBasePtr; - void addPacket( GamePacketPtr pEntry ); +class LobbyPacketContainer +{ +public: + LobbyPacketContainer( uint8_t* encKey = nullptr ); + ~LobbyPacketContainer(); - uint16_t getSize() const; - - uint8_t* getRawData( bool addstuff = true ); - - private: - Core::Network::Packets::FFXIVARR_PACKET_HEADER m_header; + void addPacket( FFXIVPacketBasePtr pEntry ); - uint8_t * m_encKey; + uint16_t getSize() const; - std::vector m_entryList; + uint8_t* getRawData( bool addstuff = true ); - uint8_t m_dataBuf[0x2000]; +private: + Core::Network::Packets::FFXIVARR_PACKET_HEADER m_header; - }; + uint8_t* m_encKey; - } - } + std::vector< FFXIVPacketBasePtr > m_entryList; + + uint8_t m_dataBuf[0x2000]; + +}; + +} +} } #endif diff --git a/src/servers/sapphire_zone/Actor/Chara.cpp b/src/servers/sapphire_zone/Actor/Chara.cpp index 8c75068b..effd35c3 100644 --- a/src/servers/sapphire_zone/Actor/Chara.cpp +++ b/src/servers/sapphire_zone/Actor/Chara.cpp @@ -396,25 +396,24 @@ void Core::Entity::Chara::autoAttack( CharaPtr pTarget ) uint16_t damage = static_cast< uint16_t >( 10 + rand() % 12 ); uint32_t variation = static_cast< uint32_t >( 0 + rand() % 4 ); - FFXIVPacketBasePtr packet = boost::make_shared< ZoneChannelPacket< FFXIVIpcEffect > >( getId() ); - auto ipcEffect = dynamic_cast< ZoneChannelPacket< FFXIVIpcEffect >& >( *packet ); - ipcEffect.data().targetId = pTarget->getId(); - ipcEffect.data().actionAnimationId = 0x366; - ipcEffect.data().unknown_2 = variation; -// effectPacket.data().unknown_3 = 1; - ipcEffect.data().actionTextId = 0x366; - ipcEffect.data().numEffects = 1; - ipcEffect.data().rotation = Math::Util::floatToUInt16Rot( getRot() ); - ipcEffect.data().effectTarget = pTarget->getId(); - ipcEffect.data().effects[0].value = damage; - ipcEffect.data().effects[0].effectType = ActionEffectType::Damage; - ipcEffect.data().effects[0].hitSeverity = static_cast< ActionHitSeverityType >( variation ); - ipcEffect.data().effects[0].unknown_3 = 7; + auto ipcEffect = makeZonePacket< FFXIVIpcEffect >( getId() ); + ipcEffect->data().targetId = pTarget->getId(); + ipcEffect->data().actionAnimationId = 0x366; + ipcEffect->data().unknown_2 = variation; +// effectPacket->data().unknown_3 = 1; + ipcEffect->data().actionTextId = 0x366; + ipcEffect->data().numEffects = 1; + ipcEffect->data().rotation = Math::Util::floatToUInt16Rot( getRot() ); + ipcEffect->data().effectTarget = pTarget->getId(); + ipcEffect->data().effects[0].value = damage; + ipcEffect->data().effects[0].effectType = ActionEffectType::Damage; + ipcEffect->data().effects[0].hitSeverity = static_cast< ActionHitSeverityType >( variation ); + ipcEffect->data().effects[0].unknown_3 = 7; - sendToInRangeSet( packet ); + sendToInRangeSet( ipcEffect ); if( isPlayer() ) - getAsPlayer()->queuePacket( packet ); + getAsPlayer()->queuePacket( ipcEffect ); pTarget->takeDamage( damage ); } @@ -441,16 +440,16 @@ void Core::Entity::Chara::handleScriptSkill( uint32_t type, uint16_t actionId, u // Todo: Effect packet generator. 90% of this is basically setting params and it's basically unreadable. // Prepare packet. This is seemingly common for all packets in the action handler. - FFXIVPacketBasePtr packet = boost::make_shared< ZoneChannelPacket< FFXIVIpcEffect > >( getId() ); - auto effectPacket = dynamic_cast< ZoneChannelPacket< FFXIVIpcEffect >& >( *packet ); - effectPacket.data().targetId = target.getId(); - effectPacket.data().actionAnimationId = actionId; - effectPacket.data().unknown_62 = 1; // Affects displaying action name next to number in floating text - effectPacket.data().unknown_2 = 1; // This seems to have an effect on the "double-cast finish" animation - effectPacket.data().actionTextId = actionId; - effectPacket.data().numEffects = 1; - effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRot() ); - effectPacket.data().effectTarget = target.getId(); + + auto effectPacket = makeZonePacket< FFXIVIpcEffect >( getId() ); + effectPacket->data().targetId = target.getId(); + effectPacket->data().actionAnimationId = actionId; + effectPacket->data().unknown_62 = 1; // Affects displaying action name next to number in floating text + effectPacket->data().unknown_2 = 1; // This seems to have an effect on the "double-cast finish" animation + effectPacket->data().actionTextId = actionId; + effectPacket->data().numEffects = 1; + effectPacket->data().rotation = Math::Util::floatToUInt16Rot( getRot() ); + effectPacket->data().effectTarget = target.getId(); // Todo: for each actor, calculate how much damage the calculated value should deal to them - 2-step damage calc. we only have 1-step switch( type ) @@ -458,10 +457,10 @@ void Core::Entity::Chara::handleScriptSkill( uint32_t type, uint16_t actionId, u case ActionEffectType::Damage: { - effectPacket.data().effects[0].value = static_cast< uint16_t >( param1 ); - effectPacket.data().effects[0].effectType = ActionEffectType::Damage; - effectPacket.data().effects[0].hitSeverity = ActionHitSeverityType::NormalDamage; - effectPacket.data().effects[0].unknown_3 = 7; + effectPacket->data().effects[0].value = static_cast< uint16_t >( param1 ); + effectPacket->data().effects[0].effectType = ActionEffectType::Damage; + effectPacket->data().effects[0].hitSeverity = ActionHitSeverityType::NormalDamage; + effectPacket->data().effects[0].unknown_3 = 7; if( actionInfoPtr->castType == 1 && actionInfoPtr->effectRange != 0 || actionInfoPtr->castType != 1 ) { @@ -469,7 +468,7 @@ void Core::Entity::Chara::handleScriptSkill( uint32_t type, uint16_t actionId, u if ( isPlayer() && !ActionCollision::isActorApplicable( target, TargetFilter::Enemies ) ) break; - sendToInRangeSet( packet, true ); + sendToInRangeSet( effectPacket, true ); if ( target.isAlive() ) target.onActionHostile( *this ); @@ -485,11 +484,11 @@ void Core::Entity::Chara::handleScriptSkill( uint32_t type, uint16_t actionId, u for( const auto& pHitActor : actorsCollided ) { - effectPacket.data().targetId = pHitActor->getId(); - effectPacket.data().effectTarget = pHitActor->getId(); + effectPacket->data().targetId = pHitActor->getId(); + effectPacket->data().effectTarget = pHitActor->getId(); // todo: send to range of what? ourselves? when mob script hits this is going to be lacking - sendToInRangeSet( packet, true ); + sendToInRangeSet( effectPacket, true ); if( pHitActor->getAsChara()->isAlive() ) @@ -516,16 +515,16 @@ void Core::Entity::Chara::handleScriptSkill( uint32_t type, uint16_t actionId, u { uint32_t calculatedHeal = Math::CalcBattle::calculateHealValue( getAsPlayer(), static_cast< uint32_t >( param1 ) ); - effectPacket.data().effects[0].value = calculatedHeal; - effectPacket.data().effects[0].effectType = ActionEffectType::Heal; - effectPacket.data().effects[0].hitSeverity = ActionHitSeverityType::NormalHeal; + effectPacket->data().effects[0].value = calculatedHeal; + effectPacket->data().effects[0].effectType = ActionEffectType::Heal; + effectPacket->data().effects[0].hitSeverity = ActionHitSeverityType::NormalHeal; if( actionInfoPtr->castType == 1 && actionInfoPtr->effectRange != 0 || actionInfoPtr->castType != 1 ) { if( isPlayer() && !ActionCollision::isActorApplicable( target, TargetFilter::Allies ) ) break; - sendToInRangeSet( packet, true ); + sendToInRangeSet( effectPacket, true ); target.heal( calculatedHeal ); } else @@ -538,10 +537,10 @@ void Core::Entity::Chara::handleScriptSkill( uint32_t type, uint16_t actionId, u for( auto pHitActor : actorsCollided ) { - effectPacket.data().targetId = target.getId(); - effectPacket.data().effectTarget = pHitActor->getId(); + effectPacket->data().targetId = target.getId(); + effectPacket->data().effectTarget = pHitActor->getId(); - sendToInRangeSet( packet, true ); + sendToInRangeSet( effectPacket, true ); pHitActor->getAsChara()->heal( calculatedHeal ); // Debug @@ -574,24 +573,23 @@ void Core::Entity::Chara::addStatusEffect( StatusEffect::StatusEffectPtr pEffect pEffect->applyStatus(); m_statusEffectMap[nextSlot] = pEffect; - FFXIVPacketBasePtr packet = boost::make_shared< ZoneChannelPacket< FFXIVIpcAddStatusEffect > >( getId() ); - auto statusEffectAdd = dynamic_cast< ZoneChannelPacket< FFXIVIpcAddStatusEffect >& >( *packet ); + auto statusEffectAdd = makeZonePacket< FFXIVIpcAddStatusEffect >( getId() ); + + statusEffectAdd->data().actor_id = pEffect->getTargetActorId(); + statusEffectAdd->data().actor_id1 = pEffect->getSrcActorId(); + statusEffectAdd->data().current_hp = getHp(); + statusEffectAdd->data().current_mp = getMp(); + statusEffectAdd->data().current_tp = getTp(); + statusEffectAdd->data().duration = static_cast< float >( pEffect->getDuration() ) / 1000; + statusEffectAdd->data().effect_id = pEffect->getId(); + statusEffectAdd->data().effect_index = nextSlot; + statusEffectAdd->data().max_hp = getMaxHp(); + statusEffectAdd->data().max_mp = getMaxMp(); + statusEffectAdd->data().max_something = 1; + //statusEffectAdd->data().unknown2 = 28; + statusEffectAdd->data().param = pEffect->getParam(); - statusEffectAdd.data().actor_id = pEffect->getTargetActorId(); - statusEffectAdd.data().actor_id1 = pEffect->getSrcActorId(); - statusEffectAdd.data().current_hp = getHp(); - statusEffectAdd.data().current_mp = getMp(); - statusEffectAdd.data().current_tp = getTp(); - statusEffectAdd.data().duration = static_cast< float >( pEffect->getDuration() ) / 1000; - statusEffectAdd.data().effect_id = pEffect->getId(); - statusEffectAdd.data().effect_index = nextSlot; - statusEffectAdd.data().max_hp = getMaxHp(); - statusEffectAdd.data().max_mp = getMaxMp(); - statusEffectAdd.data().max_something = 1; - //statusEffectAdd.data().unknown2 = 28; - statusEffectAdd.data().param = pEffect->getParam(); - - sendToInRangeSet( packet, isPlayer() ); + sendToInRangeSet( statusEffectAdd, isPlayer() ); } /*! \param StatusEffectPtr to be applied to the actor */ @@ -671,7 +669,8 @@ void Core::Entity::Chara::sendStatusEffectUpdate() { uint64_t currentTimeMs = Util::getTimeMs(); - auto statusEffectList = boost::make_shared< ZoneChannelPacket< FFXIVIpcStatusEffectList > >( getId() ); + + auto statusEffectList = makeZonePacket< FFXIVIpcStatusEffectList >( getId() ); statusEffectList->data().classId = static_cast< uint8_t >( getClass() ); statusEffectList->data().level = getLevel(); statusEffectList->data().level1 = getLevel(); diff --git a/src/servers/sapphire_zone/Actor/EventObject.cpp b/src/servers/sapphire_zone/Actor/EventObject.cpp index d31e78ab..e3873863 100644 --- a/src/servers/sapphire_zone/Actor/EventObject.cpp +++ b/src/servers/sapphire_zone/Actor/EventObject.cpp @@ -3,6 +3,10 @@ #include "Zone/InstanceContent.h" #include "Actor/Player.h" +#include "Network/PacketWrappers/ActorControlPacket142.h" +#include "Network/PacketWrappers/ActorControlPacket143.h" +#include "Network/PacketWrappers/ActorControlPacket144.h" + #include #include #include @@ -78,27 +82,14 @@ void Core::Entity::EventObject::setState( uint8_t state ) for( const auto& player : m_inRangePlayers ) { - FFXIVPacketBasePtr packet = boost::make_shared< ZoneChannelPacket< FFXIVIpcActorControl142 > >( getId(), player->getId() ); - auto eobjUpdatePacket = dynamic_cast< ZoneChannelPacket< FFXIVIpcActorControl142 >& >( *packet ); - - eobjUpdatePacket.data().category = Common::ActorControlType::DirectorEObjMod; - eobjUpdatePacket.data().param1 = state; - - player->queuePacket( packet ); + player->queuePacket( boost::make_shared< ActorControlPacket142 >( getId(), DirectorEObjMod, state ) ); } } void Core::Entity::EventObject::setAnimationFlag( uint32_t flag, uint32_t animationFlag ) { for( const auto& player : m_inRangePlayers ) { - FFXIVPacketBasePtr packet = boost::make_shared< ZoneChannelPacket< FFXIVIpcActorControl142 > >( getId(), player->getId() ); - auto eobjUpdatePacket = dynamic_cast< ZoneChannelPacket< FFXIVIpcActorControl142 >& >( *packet ); - - eobjUpdatePacket.data().category = Common::ActorControlType::EObjAnimation; - eobjUpdatePacket.data().param1 = flag; - eobjUpdatePacket.data().param2 = animationFlag; - - player->queuePacket( packet ); + player->queuePacket( boost::make_shared< ActorControlPacket142 >( getId(), EObjAnimation, flag, animationFlag ) ); } } @@ -122,19 +113,17 @@ void Core::Entity::EventObject::spawn( Core::Entity::PlayerPtr pTarget ) pLog->debug( "Spawning EObj: id:" + std::to_string( getId() ) + " name:" + getName() ); - FFXIVPacketBasePtr packet = boost::make_shared< ZoneChannelPacket< FFXIVIpcObjectSpawn > >( getId(), pTarget->getId() ); - auto eobjStatePacket = dynamic_cast< ZoneChannelPacket< FFXIVIpcObjectSpawn >& >( *packet ); - - eobjStatePacket.data().spawnIndex = spawnIndex; - eobjStatePacket.data().objKind = getObjKind(); - eobjStatePacket.data().state = getState(); - eobjStatePacket.data().objId = getObjectId(); - eobjStatePacket.data().gimmickId = getGimmickId(); - eobjStatePacket.data().position = getPos(); - eobjStatePacket.data().scale = getScale(); - eobjStatePacket.data().actorId = getId(); - eobjStatePacket.data().rotation = Math::Util::floatToUInt16Rot( getRot() ); - pTarget->queuePacket( packet ); + auto eobjStatePacket = makeZonePacket< FFXIVIpcObjectSpawn >( getId(), pTarget->getId() ); + eobjStatePacket->data().spawnIndex = spawnIndex; + eobjStatePacket->data().objKind = getObjKind(); + eobjStatePacket->data().state = getState(); + eobjStatePacket->data().objId = getObjectId(); + eobjStatePacket->data().gimmickId = getGimmickId(); + eobjStatePacket->data().position = getPos(); + eobjStatePacket->data().scale = getScale(); + eobjStatePacket->data().actorId = getId(); + eobjStatePacket->data().rotation = Math::Util::floatToUInt16Rot( getRot() ); + pTarget->queuePacket( eobjStatePacket ); } diff --git a/src/servers/sapphire_zone/Actor/Player.cpp b/src/servers/sapphire_zone/Actor/Player.cpp index 9fd0e496..8ea0a7b8 100644 --- a/src/servers/sapphire_zone/Actor/Player.cpp +++ b/src/servers/sapphire_zone/Actor/Player.cpp @@ -204,14 +204,12 @@ uint64_t Core::Entity::Player::getOnlineStatusMask() const void Core::Entity::Player::prepareZoning( uint16_t targetZone, bool fadeOut, uint8_t fadeOutTime, uint16_t animation ) { - FFXIVPacketBasePtr packet = boost::make_shared< ZoneChannelPacket< FFXIVIpcPrepareZoning > >( getId() ); - auto preparePacket = dynamic_cast< ZoneChannelPacket< FFXIVIpcPrepareZoning >& >( *packet ); - - preparePacket.data().targetZone = targetZone; - preparePacket.data().fadeOutTime = fadeOutTime; - preparePacket.data().animation = animation; - preparePacket.data().fadeOut = static_cast< uint8_t >( fadeOut ? 1 : 0 ); - queuePacket( packet ); + auto preparePacket = makeZonePacket< FFXIVIpcPrepareZoning >( getId() ); + preparePacket->data().targetZone = targetZone; + preparePacket->data().fadeOutTime = fadeOutTime; + preparePacket->data().animation = animation; + preparePacket->data().fadeOut = static_cast< uint8_t >( fadeOut ? 1 : 0 ); + queuePacket( preparePacket ); } void Core::Entity::Player::calculateStats()