From ac0e246e119f398b958e1310ef0bc373937d0231 Mon Sep 17 00:00:00 2001 From: collett Date: Mon, 9 Aug 2021 21:19:57 +0900 Subject: [PATCH] duty register rework --- src/common/Network/PacketDef/Ipcs.h | 2 +- .../Network/PacketDef/Zone/ClientZoneDef.h | 6 + src/world/Network/GameConnection.cpp | 2 +- src/world/Network/Handlers/CFHandlers.cpp | 139 +++++++++--------- 4 files changed, 79 insertions(+), 70 deletions(-) diff --git a/src/common/Network/PacketDef/Ipcs.h b/src/common/Network/PacketDef/Ipcs.h index 8cfc59ed..e3f2c39f 100644 --- a/src/common/Network/PacketDef/Ipcs.h +++ b/src/common/Network/PacketDef/Ipcs.h @@ -320,7 +320,7 @@ namespace Sapphire::Network::Packets FinishLoadingHandler = 0x0217, // updated 5.58 - CFCommenceHandler = 0xF118, // updated 5.35 hotfix + CFCommenceHandler = 0x02A3, // updated 5.58 CFCancelHandler = 0x00A9, // updated 5.58 CFRegisterDuty = 0x036A, // updated 5.58 diff --git a/src/common/Network/PacketDef/Zone/ClientZoneDef.h b/src/common/Network/PacketDef/Zone/ClientZoneDef.h index ee7364b7..772f6a1c 100644 --- a/src/common/Network/PacketDef/Zone/ClientZoneDef.h +++ b/src/common/Network/PacketDef/Zone/ClientZoneDef.h @@ -452,6 +452,12 @@ struct FFXIVIpcSaveDataEventHandler : Common::EventSaveData data; }; +struct FFXIVIpcCFCommenceHandler : + FFXIVIpcBasePacket< CFCommenceHandler > +{ + uint64_t param; +}; + } #endif //_CORE_NETWORK_PACKETS_ZONE_CLIENT_IPC_H diff --git a/src/world/Network/GameConnection.cpp b/src/world/Network/GameConnection.cpp index 89a3bbbf..9f45b926 100644 --- a/src/world/Network/GameConnection.cpp +++ b/src/world/Network/GameConnection.cpp @@ -121,7 +121,7 @@ Sapphire::Network::GameConnection::GameConnection( Sapphire::Network::HivePtr pH setZoneHandler( ClientZoneIpcType::CFRegisterDuty, "CFRegisterDuty", &GameConnection::cfRegisterDuty ); setZoneHandler( ClientZoneIpcType::CFRegisterRoulette, "CFRegisterRoulette", &GameConnection::cfRegisterRoulette ); setZoneHandler( ClientZoneIpcType::CFCommenceHandler, "CFDutyAccepted", &GameConnection::cfDutyAccepted ); - setZoneHandler( ClientZoneIpcType::CFCancelHandler, "CFCancel", &GameConnection::cfCancel ); + //setZoneHandler( ClientZoneIpcType::CFCancelHandler, "CFCancel", &GameConnection::cfCancel ); setZoneHandler( ClientZoneIpcType::ReqEquipDisplayFlagsChange, "ReqEquipDisplayFlagsChange", &GameConnection::reqEquipDisplayFlagsHandler ); diff --git a/src/world/Network/Handlers/CFHandlers.cpp b/src/world/Network/Handlers/CFHandlers.cpp index c6e9c36d..70d26695 100644 --- a/src/world/Network/Handlers/CFHandlers.cpp +++ b/src/world/Network/Handlers/CFHandlers.cpp @@ -12,6 +12,7 @@ #include "Network/GameConnection.h" #include "Network/PacketWrappers/ServerNoticePacket.h" #include "Network/PacketWrappers/PlayerStateFlagsPacket.h" +#include "Network/PacketDef/Zone/ClientZoneDef.h" #include "Session.h" @@ -43,9 +44,6 @@ void Sapphire::Network::GameConnection::cfRegisterDuty( const Packets::FFXIVARR_ Entity::Player& player ) { Packets::FFXIVARR_PACKET_RAW copy = inPacket; - auto& teriMgr = Common::Service< TerritoryMgr >::ref(); - auto& exdData = Common::Service< Data::ExdDataGenerated >::ref(); - std::vector< uint16_t > selectedContent; for( uint32_t offset = 0x1E; offset <= 0x26; offset += 0x2 ) @@ -54,96 +52,101 @@ void Sapphire::Network::GameConnection::cfRegisterDuty( const Packets::FFXIVARR_ if( id == 0 ) break; - player.sendDebug( "got contentId#{0}", id ); + player.sendDebug( "got contentFinderConditionId#{0}", id ); selectedContent.push_back( id ); } // todo: rand bias problem, will do for now tho auto index = static_cast< uint32_t >( std::rand() ) % selectedContent.size(); - auto contentId = selectedContent.at( index ); + auto contentFinderConditionId = selectedContent.at( index ); - player.sendDebug( "Duty register request for contentid#{0}", contentId ); - - // let's cancel it because otherwise you can't register it again - /* - auto cfCancelPacket = makeZonePacket< FFXIVIpcCFNotify >( player.getId() ); - cfCancelPacket->data().state1 = 3; - cfCancelPacket->data().state2 = 1; // Your registration is withdrawn. - queueOutPacket( cfCancelPacket ); - */ - auto packet = makeZonePacket< FFXIVIpcCFCancel >( player.getId() ); - packet->data().cancelReason = 890; - queueOutPacket( packet ); - - /*auto cfCondition = exdData.get< Sapphire::Data::ContentFinderCondition >( contentId ); - if( !cfCondition ) - return;*/ - - auto instance = teriMgr.createInstanceContent( /*cfCondition->content*/ contentId ); - if( !instance ) - return; - - auto pInstance = instance->getAsInstanceContent(); - pInstance->bindPlayer( player.getId() ); - - player.sendDebug( "Created instance with id#", instance->getGuId() ); - - auto sourceZoneGuId = player.getCurrentTerritory()->getGuId(); - player.setInstance( instance ); - - if( player.isPartyLeader() ) - { - player.foreachPartyMember( [ &player, &pInstance, sourceZoneGuId ]( Entity::PlayerPtr m ) - { - if( m->getId() == player.getId() ) - return; - if( m->hasStateFlag( PlayerStateFlag::InNpcEvent ) ) - { - player.sendUrgent( "Cannot teleport {} to the instance, target in event.", m->getName() ); - m->sendUrgent( "Too busy to join instance created by {}.", player.getName() ); - return; - } - if( m->getCurrentTerritory()->getGuId() != sourceZoneGuId ) - { - player.sendUrgent( "Cannot teleport {} to the instance, target in different zone.", m->getName() ); - m->sendUrgent( "Too far to join instance created by {}.", player.getName() ); - return; - } - player.sendUrgent( "Teleporting {} to the instance...", m->getName() ); - m->sendUrgent( "Joining instance created by {}.", player.getName() ); - pInstance->bindPlayer( m->getId() ); - m->setInstance( pInstance ); - } ); - } + player.sendDebug( "Duty register request for contentFinderConditionId#{0}", contentFinderConditionId ); + player.m_cfNotifiedContent = contentFinderConditionId; + auto notify = makeZonePacket< FFXIVIpcCFNotify >( player.getId() ); + notify->data().state1 = 8195; + notify->data().param3 = 1; + notify->data().param4 = contentFinderConditionId; + player.queuePacket( notify ); } void Sapphire::Network::GameConnection::cfRegisterRoulette( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) { - /* - auto cfCancelPacket = makeZonePacket< FFXIVIpcCFNotify >( player.getId() ); - cfCancelPacket->data().state1 = 3; - cfCancelPacket->data().state2 = 1; // Your registration is withdrawn. - queueOutPacket( cfCancelPacket ); - */ auto packet = makeZonePacket< FFXIVIpcCFCancel >( player.getId() ); packet->data().cancelReason = 890; queueOutPacket( packet ); - player.sendDebug( "Roulette register" ); + player.sendDebug( "Roulette register not implemented." ); } void Sapphire::Network::GameConnection::cfDutyAccepted( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) { - player.sendDebug( "TODO: Duty accept" ); -} + const auto packetIn = ZoneChannelPacket< Client::FFXIVIpcCFCommenceHandler >( inPacket ); + if( packetIn.data().param == 0 ) + { + // accept + if( player.m_cfNotifiedContent > 0 ) + { + auto& teriMgr = Common::Service< TerritoryMgr >::ref(); + auto instance = teriMgr.createInstanceContent( player.m_cfNotifiedContent ); + if( !instance ) + return; + + auto pInstance = instance->getAsInstanceContent(); + pInstance->bindPlayer( player.getId() ); + + player.sendDebug( "Created instance with id#{}", instance->getGuId() ); + + player.prepareZoning( pInstance->getTerritoryTypeId(), true, 1, 0, 0, 1, 9 ); + + auto sourceZoneGuId = player.getCurrentTerritory()->getGuId(); + player.setInstance( instance ); + + if( player.isPartyLeader() ) + { + player.foreachPartyMember( [ &player, &pInstance, sourceZoneGuId ]( Entity::PlayerPtr m ) + { + if( m->getId() == player.getId() ) + return; + if( m->hasStateFlag( PlayerStateFlag::InNpcEvent ) ) + { + player.sendUrgent( "Cannot teleport {} to the instance, target in event.", m->getName() ); + m->sendUrgent( "Too busy to join instance created by {}.", player.getName() ); + return; + } + if( m->getCurrentTerritory()->getGuId() != sourceZoneGuId ) + { + player.sendUrgent( "Cannot teleport {} to the instance, target in different zone.", m->getName() ); + m->sendUrgent( "Too far to join instance created by {}.", player.getName() ); + return; + } + m->prepareZoning( pInstance->getTerritoryTypeId(), true, 1, 0, 0, 1, 9 ); + player.sendUrgent( "Teleporting {} to the instance...", m->getName() ); + m->sendUrgent( "Joining instance created by {}.", player.getName() ); + pInstance->bindPlayer( m->getId() ); + m->setInstance( pInstance ); + } ); + } + } + } + else + { + // cancel + player.m_cfNotifiedContent = 0; + auto packet = makeZonePacket< FFXIVIpcCFCancel >( player.getId() ); + packet->data().cancelReason = 890; + queueOutPacket( packet ); + } +} +/* void Sapphire::Network::GameConnection::cfCancel( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) { auto packet = makeZonePacket< FFXIVIpcCFCancel >( player.getId() ); packet->data().cancelReason = 890; queueOutPacket( packet ); -} \ No newline at end of file +} +*/ \ No newline at end of file