From fed653ed62ae7140efd9f5d3ad79b994272afe4a Mon Sep 17 00:00:00 2001 From: Mordred Date: Thu, 9 Dec 2021 22:10:14 +0100 Subject: [PATCH] Fix create linkshell event with existing name --- src/scripts/action/common/ActionSprint3.cpp | 3 +- src/scripts/common/CmnDefLinkShell.cpp | 4 +-- src/world/Manager/EventMgr.cpp | 6 ++-- src/world/Manager/EventMgr.h | 2 +- src/world/Manager/LinkshellMgr.cpp | 33 +++++++++------------ 5 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/scripts/action/common/ActionSprint3.cpp b/src/scripts/action/common/ActionSprint3.cpp index 9b40bd6e..aea3c57f 100644 --- a/src/scripts/action/common/ActionSprint3.cpp +++ b/src/scripts/action/common/ActionSprint3.cpp @@ -2,8 +2,7 @@ #include #include -class ActionSprint3 : - public Sapphire::ScriptAPI::ActionScript +class ActionSprint3 : public Sapphire::ScriptAPI::ActionScript { public: ActionSprint3() : diff --git a/src/scripts/common/CmnDefLinkShell.cpp b/src/scripts/common/CmnDefLinkShell.cpp index 445dfa86..7a308f9b 100644 --- a/src/scripts/common/CmnDefLinkShell.cpp +++ b/src/scripts/common/CmnDefLinkShell.cpp @@ -47,12 +47,12 @@ public: auto ls = linkshellMgr().createLinkshell( result.resultString, player ); if( !ls ) { - eventMgr().resumeScene( player, result.eventId, result.sceneId, { 0x15a } ); + eventMgr().resumeScene( player, result.eventId, result.sceneId, { 0x15a }, false ); linkshellMgr().finishLinkshellCreation( result.resultString, 0x15a, player ); } else { - eventMgr().resumeScene( player, result.eventId, result.sceneId, { 0 } ); + eventMgr().resumeScene( player, result.eventId, result.sceneId, { 0 }, true ); linkshellMgr().finishLinkshellCreation( result.resultString, 0, player ); } diff --git a/src/world/Manager/EventMgr.cpp b/src/world/Manager/EventMgr.cpp index 85dbb1e6..0cec41a2 100644 --- a/src/world/Manager/EventMgr.cpp +++ b/src/world/Manager/EventMgr.cpp @@ -542,13 +542,15 @@ void EventMgr::playScene( Entity::Player& player, uint32_t eventId, uint32_t sce sendEventPlay( player, eventId, scene, flags ); } -void EventMgr::resumeScene( Entity::Player& player, uint32_t eventId, uint32_t scene, std::vector< uint32_t > values ) +void EventMgr::resumeScene( Entity::Player& player, uint32_t eventId, uint32_t scene, std::vector< uint32_t > values, bool resetCallback ) { auto pEvent = bootstrapSceneEvent( player, eventId, 0 ); if( !pEvent ) return; - pEvent->setEventReturnCallback( nullptr ); + if( resetCallback ) + pEvent->setEventReturnCallback( nullptr ); + auto resumeEvent = makeZonePacket< FFXIVIpcResumeEventScene2 >( player.getId() ); resumeEvent->data().handlerId = eventId; resumeEvent->data().sceneId = static_cast< uint8_t >( scene ); diff --git a/src/world/Manager/EventMgr.h b/src/world/Manager/EventMgr.h index 2354bae1..f55cc0dd 100644 --- a/src/world/Manager/EventMgr.h +++ b/src/world/Manager/EventMgr.h @@ -41,7 +41,7 @@ namespace Sapphire::World::Manager Event::EventHandler::SceneReturnCallback eventReturnCallback = nullptr ); /*! resume a subevent */ - void resumeScene( Entity::Player& player, uint32_t eventId, uint32_t scene, std::vector< uint32_t > values ); + void resumeScene( Entity::Player& player, uint32_t eventId, uint32_t scene, std::vector< uint32_t > values, bool resetCallback ); /*! play a subevent */ void playScene( Entity::Player& player, uint32_t eventId, uint32_t scene, uint32_t flags, diff --git a/src/world/Manager/LinkshellMgr.cpp b/src/world/Manager/LinkshellMgr.cpp index f60fa925..0ca6e66f 100644 --- a/src/world/Manager/LinkshellMgr.cpp +++ b/src/world/Manager/LinkshellMgr.cpp @@ -152,10 +152,6 @@ Sapphire::LinkshellPtr Sapphire::World::Manager::LinkshellMgr::getLinkshellById( Sapphire::LinkshellPtr Sapphire::World::Manager::LinkshellMgr::createLinkshell( const std::string& name, Entity::Player& player ) { - auto& chatChannelMgr = Common::Service< Manager::ChatChannelMgr >::ref(); - auto chatChannelId = chatChannelMgr.createChatChannel( Common::ChatChannelType::LinkshellChat ); - chatChannelMgr.addPlayerToChannel( chatChannelId, player ); - uint64_t linkshellId = 1; if( !m_linkshellIdMap.empty() ) @@ -169,6 +165,10 @@ Sapphire::LinkshellPtr Sapphire::World::Manager::LinkshellMgr::createLinkshell( if( lsIt != m_linkshellNameMap.end() ) return nullptr; + auto& chatChannelMgr = Common::Service< Manager::ChatChannelMgr >::ref(); + auto chatChannelId = chatChannelMgr.createChatChannel( Common::ChatChannelType::LinkshellChat ); + chatChannelMgr.addPlayerToChannel( chatChannelId, player ); + uint64_t masterId = player.getCharacterId(); // TODO: remove this messy set @@ -187,7 +187,6 @@ Sapphire::LinkshellPtr Sapphire::World::Manager::LinkshellMgr::createLinkshell( // TODO: handle player pkt // prepare binary data for SQL - std::vector< uint64_t > members( 128, 0 ); std::vector< uint64_t > leaders( 128, 0 ); std::vector< uint64_t > invites( 128, 0 ); @@ -204,10 +203,7 @@ Sapphire::LinkshellPtr Sapphire::World::Manager::LinkshellMgr::createLinkshell( std::vector< uint8_t > invVec( sizeof( invites ) ); memcpy( invVec.data(), invites.data(), sizeof( invites ) ); - // TODO: insert in SQL - auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref(); - auto stmt = db.getPreparedStatement( Db::ZoneDbStatements::CHARA_LINKSHELL_INS ); stmt->setUInt64( 1, linkshellId ); stmt->setUInt64( 2, masterId ); @@ -220,11 +216,12 @@ Sapphire::LinkshellPtr Sapphire::World::Manager::LinkshellMgr::createLinkshell( return lsPtr; } + void Sapphire::World::Manager::LinkshellMgr::finishLinkshellCreation( const std::string& name, uint32_t result, Entity::Player& player ) { auto& server = Common::Service< World::WorldServer >::ref(); - auto linkshellResult = makeLinkshellResult( player, 0, 0, 1, 0, 0, name, "" ); + auto linkshellResult = makeLinkshellResult( player, 0, 0, 1, result, 0, name, "" ); server.queueForPlayer( player.getCharacterId(), linkshellResult ); } @@ -233,18 +230,16 @@ const std::vector< Sapphire::LinkshellPtr > Sapphire::World::Manager::LinkshellM { std::vector< Sapphire::LinkshellPtr > lsVec; - if( !m_linkshellIdMap.empty() ) + for( const auto &[ key, value ] : m_linkshellIdMap ) { - for( const auto &[ key, value ] : m_linkshellIdMap ) - { - auto& memberList = value->getMemberIdList(); - auto& inviteList = value->getInviteIdList(); + auto& memberList = value->getMemberIdList(); + auto& inviteList = value->getInviteIdList(); - // find player id in LS member list - if( memberList.count( player.getCharacterId() ) || inviteList.count( player.getCharacterId() ) ) - { - lsVec.emplace_back( value ); - } + // find player id in LS member or invite list + if( memberList.count( player.getCharacterId() ) || + inviteList.count( player.getCharacterId() ) ) + { + lsVec.emplace_back( value ); } }