diff --git a/src/common/Database/ZoneDbConnection.cpp b/src/common/Database/ZoneDbConnection.cpp index ad303c97..9b07ae09 100644 --- a/src/common/Database/ZoneDbConnection.cpp +++ b/src/common/Database/ZoneDbConnection.cpp @@ -329,6 +329,10 @@ void Sapphire::Db::ZoneDbConnection::doPrepareStatements() "UPDATE infolinkshell SET CharacterIdList = ?, LinkshellName = ?, LeaderIdList = ?, InviteIdList = ?, MasterCharacterId = ? WHERE LinkshellId = ?;", CONNECTION_BOTH ); + prepareStatement( LINKSHELL_DEL, + "DELETE FROM infolinkshell WHERE LinkshellId = ?;", + CONNECTION_BOTH ); + /*prepareStatement( LAND_INS, "INSERT INTO land ( LandSetId ) VALUES ( ? );", CONNECTION_BOTH ); diff --git a/src/common/Database/ZoneDbConnection.h b/src/common/Database/ZoneDbConnection.h index 2784f5a4..bc51e3e5 100644 --- a/src/common/Database/ZoneDbConnection.h +++ b/src/common/Database/ZoneDbConnection.h @@ -108,6 +108,7 @@ namespace Sapphire::Db LINKSHELL_SEL_ALL, LINKSHELL_INS, LINKSHELL_UP, + LINKSHELL_DEL, MAX_STATEMENTS diff --git a/src/scripts/common/CmnDefLinkShell.cpp b/src/scripts/common/CmnDefLinkShell.cpp index 7a308f9b..eac7a0c2 100644 --- a/src/scripts/common/CmnDefLinkShell.cpp +++ b/src/scripts/common/CmnDefLinkShell.cpp @@ -48,12 +48,12 @@ public: if( !ls ) { eventMgr().resumeScene( player, result.eventId, result.sceneId, { 0x15a }, false ); - linkshellMgr().finishLinkshellCreation( result.resultString, 0x15a, player ); + linkshellMgr().finishLinkshellAction( result.resultString, 0x15a, player, 1 ); } else { eventMgr().resumeScene( player, result.eventId, result.sceneId, { 0 }, true ); - linkshellMgr().finishLinkshellCreation( result.resultString, 0, player ); + linkshellMgr().finishLinkshellAction( result.resultString, 0, player, 1 ); } }; @@ -64,7 +64,22 @@ public: // rename linkshell void Scene00003( Entity::Player& player ) { - eventMgr().playScene( player, getId(), 3, HIDE_HOTBAR ); + auto callback = [ this ]( Entity::Player& player, const Event::SceneResult& result ) + { + auto ls = linkshellMgr().renameLinkshell( result.intResult, result.resultString, player ); + if( !ls ) + { + eventMgr().resumeScene( player, result.eventId, result.sceneId, { 0x15a }, false ); + linkshellMgr().finishLinkshellAction( result.resultString, 0x15a, player, 3 ); + } + else + { + eventMgr().resumeScene( player, result.eventId, result.sceneId, { 0 }, true ); + linkshellMgr().finishLinkshellAction( result.resultString, 0, player, 3 ); + } + + }; + eventMgr().playScene( player, getId(), 3, HIDE_HOTBAR, callback ); } // remove linkshell diff --git a/src/world/Event/EventHandler.h b/src/world/Event/EventHandler.h index 924d1b58..89627e64 100644 --- a/src/world/Event/EventHandler.h +++ b/src/world/Event/EventHandler.h @@ -15,6 +15,7 @@ namespace Sapphire::Event uint8_t numOfResults; std::vector< uint32_t > results; std::string resultString; + uint64_t intResult; uint32_t getResult( uint32_t index ) const; }; diff --git a/src/world/Linkshell/Linkshell.cpp b/src/world/Linkshell/Linkshell.cpp index 75675d75..b49cd2e5 100644 --- a/src/world/Linkshell/Linkshell.cpp +++ b/src/world/Linkshell/Linkshell.cpp @@ -103,5 +103,10 @@ void Sapphire::Linkshell::setMasterId( uint64_t masterId ) m_masterCharacterId = masterId; } +void Sapphire::Linkshell::setName( std::string name ) +{ + m_name = std::move( name ); +} + diff --git a/src/world/Linkshell/Linkshell.h b/src/world/Linkshell/Linkshell.h index a286c330..d100f61a 100644 --- a/src/world/Linkshell/Linkshell.h +++ b/src/world/Linkshell/Linkshell.h @@ -37,6 +37,7 @@ namespace Sapphire uint64_t getId() const; const std::string& getName() const; + void setName( std::string name ); uint64_t getMasterId() const; diff --git a/src/world/Manager/EventMgr.cpp b/src/world/Manager/EventMgr.cpp index 0cec41a2..32b100c0 100644 --- a/src/world/Manager/EventMgr.cpp +++ b/src/world/Manager/EventMgr.cpp @@ -348,6 +348,42 @@ void EventMgr::handleReturnStringEventScene( Entity::Player& player, uint32_t ev } +void EventMgr::handleReturnIntAndStringEventScene( Entity::Player& player, uint32_t eventId, uint16_t sceneId, const std::string& resultString, uint64_t resultInt ) +{ + std::string eventName = getEventName( eventId ); + + PlayerMgr::sendDebug( player, "eventId: {0} ({0:08X}) scene: {1}, string: {2}, resultInt: {3}", eventId, sceneId, resultString, resultInt ); + + auto eventType = static_cast< uint16_t >( eventId >> 16 ); + auto pEvent = player.getEvent( eventId ); + + if( pEvent ) + { + pEvent->setPlayedScene( false ); + // try to retrieve a stored callback + // if there is one, proceed to call it + Event::SceneResult result; + result.actorId = pEvent->getActorId(); + result.eventId = eventId; + result.sceneId = sceneId; + result.resultString = resultString; + result.intResult = resultInt; + + auto eventCallback = pEvent->getEventReturnCallback(); + if( eventCallback ) + { + eventCallback( player, result ); + } + + // we might have a scene chain callback instead so check for that too + else if( auto chainCallback = pEvent->getSceneChainCallback() ) + chainCallback( player ); + + } + +} + + void EventMgr::checkEvent( Sapphire::Entity::Player &player, uint32_t eventId ) { auto pEvent = player.getEvent( eventId ); diff --git a/src/world/Manager/EventMgr.h b/src/world/Manager/EventMgr.h index f55cc0dd..9530b7da 100644 --- a/src/world/Manager/EventMgr.h +++ b/src/world/Manager/EventMgr.h @@ -22,6 +22,7 @@ namespace Sapphire::World::Manager uint8_t numOfResults, const std::vector< uint32_t >& results ); void handleReturnStringEventScene( Entity::Player& player, uint32_t eventId, uint16_t sceneId, const std::string& resultString ); + void handleReturnIntAndStringEventScene( Entity::Player& player, uint32_t eventId, uint16_t sceneId, const std::string& resultString, uint64_t resultInt ); void checkEvent( Entity::Player& player, uint32_t eventId ); diff --git a/src/world/Manager/LinkshellMgr.cpp b/src/world/Manager/LinkshellMgr.cpp index bd0ad4b0..26fd9e3d 100644 --- a/src/world/Manager/LinkshellMgr.cpp +++ b/src/world/Manager/LinkshellMgr.cpp @@ -218,11 +218,11 @@ 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 ) +void Sapphire::World::Manager::LinkshellMgr::finishLinkshellAction( const std::string& name, uint32_t result, Entity::Player& player, uint8_t action ) { auto& server = Common::Service< World::WorldServer >::ref(); - auto linkshellResult = makeLinkshellResult( player, 0, 0, 1, result, 0, name, "" ); + auto linkshellResult = makeLinkshellResult( player, 0, 0, action, result, 0, name, "" ); server.queueForPlayer( player.getCharacterId(), linkshellResult ); } @@ -482,3 +482,25 @@ void LinkshellMgr::changeMaster( Sapphire::Entity::Player &sourcePlayer, Sapphir server.queueForPlayer( sourcePlayer.getCharacterId(), linkshellResult1 ); } + +bool LinkshellMgr::renameLinkshell( uint64_t linkshellId, const std::string &name, Sapphire::Entity::Player &player ) +{ + auto& server = Common::Service< World::WorldServer >::ref(); + + auto lsPtr = getLinkshellById( linkshellId ); + + if( !lsPtr ) + { + Logger::warn( "Failed to rename linkshell - linkshell not found!" ); + return false; + } + + // can't rename to an already existing name + if( getLinkshellByName( name ) ) + return false; + + lsPtr->setName( name ); + writeLinkshell( lsPtr->getId() ); + + return true; +} diff --git a/src/world/Manager/LinkshellMgr.h b/src/world/Manager/LinkshellMgr.h index bf7a25e7..398fd09f 100644 --- a/src/world/Manager/LinkshellMgr.h +++ b/src/world/Manager/LinkshellMgr.h @@ -36,7 +36,9 @@ namespace Sapphire::World::Manager // create new linkshell entry and insert into db LinkshellPtr createLinkshell( const std::string& name, Entity::Player& player ); - void finishLinkshellCreation( const std::string& name, uint32_t result, Entity::Player& player ); + bool renameLinkshell( uint64_t linkshellId, const std::string& name, Entity::Player& player ); + + void finishLinkshellAction( const std::string& name, uint32_t result, Entity::Player& player, uint8_t action ); void invitePlayer( Entity::Player& sourcePlayer, Entity::Player& invitedPlayer, uint64_t linkshellId ); void kickPlayer( Entity::Player& sourcePlayer, Entity::Player& kickedPlayer, uint64_t linkshellId ); diff --git a/src/world/Network/GameConnection.cpp b/src/world/Network/GameConnection.cpp index e4f9ca15..631bb5c4 100644 --- a/src/world/Network/GameConnection.cpp +++ b/src/world/Network/GameConnection.cpp @@ -118,6 +118,8 @@ Sapphire::Network::GameConnection::GameConnection( Sapphire::Network::HivePtr pH setZoneHandler( YieldEventSceneString16, "YieldEventSceneString16", &GameConnection::yieldEventString ); setZoneHandler( YieldEventSceneString32, "YieldEventSceneString32", &GameConnection::yieldEventString ); + setZoneHandler( YieldEventSceneIntAndString, "YieldEventSceneIntAndString", &GameConnection::yieldEventSceneIntAndString ); + setZoneHandler( RequestPenalties, "RequestPenalties", &GameConnection::cfRequestPenalties ); setZoneHandler( FindContent, "FindContent", &GameConnection::findContent ); setZoneHandler( Find5Contents, "Find5Contents", &GameConnection::find5Contents ); diff --git a/src/world/Network/GameConnection.h b/src/world/Network/GameConnection.h index 428219d5..cea4bfc7 100644 --- a/src/world/Network/GameConnection.h +++ b/src/world/Network/GameConnection.h @@ -166,6 +166,7 @@ namespace Sapphire::Network DECLARE_HANDLER( startUiEvent ); DECLARE_HANDLER( yieldEventString ); + DECLARE_HANDLER( yieldEventSceneIntAndString ); DECLARE_HANDLER( logoutHandler ); diff --git a/src/world/Network/Handlers/EventHandlers.cpp b/src/world/Network/Handlers/EventHandlers.cpp index 4f28c159..3fd7d7d6 100644 --- a/src/world/Network/Handlers/EventHandlers.cpp +++ b/src/world/Network/Handlers/EventHandlers.cpp @@ -323,6 +323,19 @@ void Sapphire::Network::GameConnection::yieldEventString( const Packets::FFXIVAR } +void Sapphire::Network::GameConnection::yieldEventSceneIntAndString( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) +{ + auto &server = Common::Service< World::WorldServer >::ref(); + auto &eventMgr = Common::Service< World::Manager::EventMgr >::ref(); + + std::string inString; + const auto packet = ZoneChannelPacket< FFXIVIpcYieldEventSceneIntAndString >( inPacket ); + auto& data = packet.data(); + inString = std::string( data.str ); + + eventMgr.handleReturnIntAndStringEventScene( player, data.handlerId, data.sceneId, inString, data.integer ); +} + void Sapphire::Network::GameConnection::startUiEvent( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) { diff --git a/src/world/Network/Handlers/PacketCommandHandler.cpp b/src/world/Network/Handlers/PacketCommandHandler.cpp index efa20b9f..028bdcb6 100644 --- a/src/world/Network/Handlers/PacketCommandHandler.cpp +++ b/src/world/Network/Handlers/PacketCommandHandler.cpp @@ -119,7 +119,7 @@ void Sapphire::Network::GameConnection::commandHandler( const Packets::FFXIVARR_ } case PacketCommand::COMPANION: { - player.setCompanion( static_cast< uint16_t >( param1 )); + player.setCompanion( static_cast< uint16_t >( param1 ) ); break; } case PacketCommand::REQUEST_STATUS_RESET: // Remove status (clicking it off)