From 47df62f0b4d4c304146d070cbd34b99f7a99af0d Mon Sep 17 00:00:00 2001 From: Mordred Date: Sat, 4 Dec 2021 21:53:04 +0100 Subject: [PATCH] Moved ls logic from packetHandler to linkshellHandler, improved invite logic --- src/common/Common.h | 10 ---- src/world/Manager/LinkshellMgr.cpp | 48 ++++++++++++++++ src/world/Manager/LinkshellMgr.h | 4 ++ .../Network/Handlers/LinkshellHandlers.cpp | 33 +++++++++++ src/world/Network/Handlers/PacketHandlers.cpp | 55 +------------------ 5 files changed, 86 insertions(+), 64 deletions(-) create mode 100644 src/world/Network/Handlers/LinkshellHandlers.cpp diff --git a/src/common/Common.h b/src/common/Common.h index 769cee3f..14cc028d 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -992,16 +992,6 @@ namespace Sapphire::Common ReceivedRequest = 0x30 }; - enum LinkshellHierarchy : int32_t - { - NONE_1 = 0x0, - MASTER = 0x1, - LEADER = 0x2, - MEMBER = 0x3, - INVITE = 0x4, - MAX_0 = 0x7, - }; - namespace Ls { enum LinkshellHierarchyShifted : int32_t diff --git a/src/world/Manager/LinkshellMgr.cpp b/src/world/Manager/LinkshellMgr.cpp index efe4a53d..96d5eddd 100644 --- a/src/world/Manager/LinkshellMgr.cpp +++ b/src/world/Manager/LinkshellMgr.cpp @@ -23,6 +23,8 @@ #include #include +#include "Session.h" + using namespace Sapphire::Common; using namespace Sapphire::Network::Packets; using namespace Sapphire::Network::Packets::WorldPackets::Server; @@ -246,4 +248,50 @@ const std::vector< Sapphire::LinkshellPtr > Sapphire::World::Manager::LinkshellM return lsVec; } +void LinkshellMgr::invitePlayer( const std::string &name, uint64_t linkshellId ) +{ + auto& server = Common::Service< World::WorldServer >::ref(); + + auto invitedPlayer = server.getSession( name ); + auto lsPtr = getLinkshellById( linkshellId ); + + if( !invitedPlayer || !lsPtr ) + return Logger::warn( "Failed to invite player to linkshell - session/linkshell not found!" ); + + lsPtr->addInvite( invitedPlayer->getPlayer()->getCharacterId() ); + writeLinkshell( lsPtr->getId() ); + sendLinkshellList( *invitedPlayer->getPlayer() ); +} + +void LinkshellMgr::sendLinkshellList( Entity::Player& player ) +{ + auto& server = Common::Service< World::WorldServer >::ref(); + + auto linkshellListPacket = makeZonePacket< FFXIVIpcGetLinkshellListResult >( player.getId() ); + + auto lsVec = getPlayerLinkshells( player ); + + for( int i = 0; i < lsVec.size(); ++i ) + { + auto pLs = lsVec[ i ]; + uint32_t hierarchy = 0; + + if( pLs->getMasterId() == player.getCharacterId() ) + hierarchy = Ls::LinkshellHierarchyShifted::Master; + else if( pLs->getLeaderIdList().count( player.getCharacterId() ) ) + hierarchy = Ls::LinkshellHierarchyShifted::Leader; + else if( pLs->getInviteIdList().count( player.getCharacterId() ) ) + hierarchy = Ls::LinkshellHierarchyShifted::Invite; + else + hierarchy = Ls::LinkshellHierarchyShifted::Member; + + linkshellListPacket->data().LinkshellList[ i ].LinkshellID = pLs->getId(); + linkshellListPacket->data().LinkshellList[ i ].ChannelID = pLs->getChatChannel(); + linkshellListPacket->data().LinkshellList[ i ].HierarchyID = hierarchy; + strcpy( linkshellListPacket->data().LinkshellList[ i ].LinkshellName, pLs->getName().c_str() ); + } + + server.queueForPlayer( player.getCharacterId(), linkshellListPacket ); +} + diff --git a/src/world/Manager/LinkshellMgr.h b/src/world/Manager/LinkshellMgr.h index 4b2270e0..7d7dfaef 100644 --- a/src/world/Manager/LinkshellMgr.h +++ b/src/world/Manager/LinkshellMgr.h @@ -38,6 +38,10 @@ namespace Sapphire::World::Manager void finishLinkshellCreation( const std::string& name, uint32_t result, Entity::Player& player ); + void invitePlayer( const std::string& name, uint64_t linkshellId ); + + void sendLinkshellList( Entity::Player& player ); + // get all linkshells associated with player const std::vector< LinkshellPtr > getPlayerLinkshells( Entity::Player& player ) const; diff --git a/src/world/Network/Handlers/LinkshellHandlers.cpp b/src/world/Network/Handlers/LinkshellHandlers.cpp new file mode 100644 index 00000000..68464d60 --- /dev/null +++ b/src/world/Network/Handlers/LinkshellHandlers.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +#include +#include +#include +#include + +#include "Network/GameConnection.h" + +#include "Session.h" +#include "Actor/Player.h" +#include "Manager/LinkshellMgr.h" + +using namespace Sapphire::Common; +using namespace Sapphire::Network::Packets; +using namespace Sapphire::Network::Packets::WorldPackets; +using namespace Sapphire::World::Manager; + +void Sapphire::Network::GameConnection::linkshellListHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) +{ + auto& lsMgr = Common::Service< LinkshellMgr >::ref(); + lsMgr.sendLinkshellList( player ); +} + +void Sapphire::Network::GameConnection::linkshellJoinHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) +{ + const auto lsJoinPacket = ZoneChannelPacket< Client::FFXIVIpcLinkshellJoin >( inPacket ); + auto& lsMgr = Common::Service< LinkshellMgr >::ref(); + auto charName = std::string( lsJoinPacket.data().MemberCharacterName ); + lsMgr.invitePlayer( charName, lsJoinPacket.data().LinkshellID ); +} \ No newline at end of file diff --git a/src/world/Network/Handlers/PacketHandlers.cpp b/src/world/Network/Handlers/PacketHandlers.cpp index 6a7c53b6..3b0d36f9 100644 --- a/src/world/Network/Handlers/PacketHandlers.cpp +++ b/src/world/Network/Handlers/PacketHandlers.cpp @@ -168,60 +168,7 @@ void Sapphire::Network::GameConnection::reqExamineFcInfo( const Packets::FFXIVAR } } -void Sapphire::Network::GameConnection::linkshellListHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, - Entity::Player& player ) -{ - auto linkshellListPacket = makeZonePacket< FFXIVIpcGetLinkshellListResult >( player.getId() ); - - auto& lsMgr = Common::Service< LinkshellMgr >::ref(); - auto& ccMgr = Common::Service< ChatChannelMgr >::ref(); - - auto lsVec = lsMgr.getPlayerLinkshells( player ); - - for( int i = 0; i < lsVec.size(); ++i ) - { - auto pLs = lsVec[ i ]; - uint32_t hierarchy = 0; - - if( pLs->getMasterId() == player.getCharacterId() ) - hierarchy = Ls::LinkshellHierarchyShifted::Master; - else if( pLs->getLeaderIdList().count( player.getCharacterId() ) ) - hierarchy = Ls::LinkshellHierarchyShifted::Leader; - else if( pLs->getInviteIdList().count( player.getCharacterId() ) ) - hierarchy = Ls::LinkshellHierarchyShifted::Invite; - else - hierarchy = Ls::LinkshellHierarchyShifted::Member; - - linkshellListPacket->data().LinkshellList[ i ].LinkshellID = pLs->getId(); - linkshellListPacket->data().LinkshellList[ i ].ChannelID = pLs->getChatChannel(); - linkshellListPacket->data().LinkshellList[ i ].HierarchyID = hierarchy; - strcpy( linkshellListPacket->data().LinkshellList[ i ].LinkshellName, pLs->getName().c_str() ); - } - - queueOutPacket( linkshellListPacket ); -} - -void Sapphire::Network::GameConnection::linkshellJoinHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, - Entity::Player& player ) -{ - const auto lsJoinPacket = ZoneChannelPacket< Client::FFXIVIpcLinkshellJoin >( inPacket ); - - auto& lsMgr = Common::Service< LinkshellMgr >::ref(); - auto& server = Common::Service< World::WorldServer >::ref(); - - auto invitedPlayer = server.getSession( lsJoinPacket.data().MemberCharacterName ); - auto lsPtr = lsMgr.getLinkshellById( lsJoinPacket.data().LinkshellID ); - - if( !invitedPlayer || !lsPtr ) - return Logger::warn( "Failed to invite player to linkshell - session/linkshell not found!" ); - - lsPtr->addInvite( invitedPlayer->getPlayer()->getCharacterId() ); - lsMgr.writeLinkshell( lsPtr->getId() ); - // TODO: send inv packets -} - -void Sapphire::Network::GameConnection::joinChatChannelHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, - Entity::Player& player ) +void Sapphire::Network::GameConnection::joinChatChannelHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) { const auto joinChannelPacket = ZoneChannelPacket< Client::FFXIVIpcJoinChatChannel >( inPacket ); const uint64_t channelIdReq = joinChannelPacket.data().ChannelID;