From a55e912d9f72a152e71a2494d8a3bd87b86efdde Mon Sep 17 00:00:00 2001 From: Mordred Date: Fri, 10 Feb 2023 21:38:08 +0100 Subject: [PATCH] Merge attempt #2 --- src/world/Actor/Player.cpp | 4 ---- src/world/Manager/PlayerMgr.cpp | 13 +++++++++++-- src/world/Manager/PlayerMgr.h | 1 + src/world/Session.cpp | 15 ++++++++------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/world/Actor/Player.cpp b/src/world/Actor/Player.cpp index 14826359..cdbdd059 100644 --- a/src/world/Actor/Player.cpp +++ b/src/world/Actor/Player.cpp @@ -131,11 +131,7 @@ void Player::unload() setLoadingComplete( false ); // unset player for removal setMarkedForRemoval( false ); - // send updates to mgrs - if( getPartyId() != 0 ) - partyMgr.onMemberDisconnect( *this ); - fcMgr.onFcLogout( getCharacterId() ); syncLastDBWrite(); } diff --git a/src/world/Manager/PlayerMgr.cpp b/src/world/Manager/PlayerMgr.cpp index 8b964728..51394b89 100644 --- a/src/world/Manager/PlayerMgr.cpp +++ b/src/world/Manager/PlayerMgr.cpp @@ -274,8 +274,6 @@ void PlayerMgr::onCompanionUpdate( Entity::Player& player, uint8_t companionId ) void PlayerMgr::onMountUpdate( Entity::Player& player, uint32_t mountId ) { - Common::Service< World::Manager::PlayerMgr >::ref().onMountUpdate( player, mountId ); - if( mountId != 0 ) { player.sendToInRangeSet( makeActorControl( player.getId(), ActorControlType::SetStatus, @@ -366,6 +364,17 @@ void PlayerMgr::onLogin( Entity::Player& player ) } } +void PlayerMgr::onLogout( Entity::Player &player ) +{ + auto& partyMgr = Common::Service< World::Manager::PartyMgr >::ref(); + auto& fcMgr = Common::Service< World::Manager::FreeCompanyMgr >::ref(); + // send updates to mgrs + if( player.getPartyId() != 0 ) + partyMgr.onMemberDisconnect( player ); + + fcMgr.onFcLogout( player.getCharacterId() ); +} + void PlayerMgr::onDeath( Entity::Player& player ) { auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref(); diff --git a/src/world/Manager/PlayerMgr.h b/src/world/Manager/PlayerMgr.h index 79f71cc9..5df23905 100644 --- a/src/world/Manager/PlayerMgr.h +++ b/src/world/Manager/PlayerMgr.h @@ -57,6 +57,7 @@ class PlayerMgr void onHateListChanged( Sapphire::Entity::Player& player ); void onLogin( Sapphire::Entity::Player& player ); + void onLogout( Sapphire::Entity::Player& player ); void onDeath( Sapphire::Entity::Player& player ); diff --git a/src/world/Session.cpp b/src/world/Session.cpp index 202a235c..6f9ef99a 100644 --- a/src/world/Session.cpp +++ b/src/world/Session.cpp @@ -1,5 +1,4 @@ #include -#include #include #include @@ -78,6 +77,9 @@ void Sapphire::World::Session::close() // remove the session from the player if( m_pPlayer ) { + auto& playerMgr = Common::Service< World::Manager::PlayerMgr >::ref(); + playerMgr.onLogout( *m_pPlayer ); + m_pPlayer->unload(); } } @@ -116,7 +118,7 @@ void Sapphire::World::Session::startReplay( const std::string& path ) { if( !fs::exists( path ) ) { - PlayerMgr::sendDebug( *getPlayer(), "Couldn't find folder." ); + PlayerMgr::sendDebug( *getPlayer(), "Couldn't find folder {}.", path ); return; } @@ -129,11 +131,11 @@ void Sapphire::World::Session::startReplay( const std::string& path ) { // Get the filename of the current element auto fileName = it->path().filename().string(); - auto unixTime = std::stoull( fileName.substr( 0, 14 ).c_str() ); + auto unixTime = std::stoull( fileName.substr( 0, 14 ) ); if( unixTime > 1000000000 ) { - loadedSets.push_back( std::tuple< uint64_t, std::string >( unixTime, it->path().string() ) ); + loadedSets.emplace_back( unixTime, it->path().string() ); } } @@ -147,8 +149,7 @@ void Sapphire::World::Session::startReplay( const std::string& path ) for( auto set : loadedSets ) { - m_replayCache.push_back( std::tuple< uint64_t, std::string >( - Common::Util::getTimeMs() + ( std::get< 0 >( set ) - startTime ), std::get< 1 >( set ) ) ); + m_replayCache.emplace_back( Common::Util::getTimeMs() + ( std::get< 0 >( set ) - startTime ), std::get< 1 >( set ) ); Logger::info( "Registering {0} for {1}", std::get< 1 >( set ), std::get< 0 >( set ) - startTime ); } @@ -177,7 +178,7 @@ void Sapphire::World::Session::processReplay() at++; } - if( m_replayCache.size() == 0 ) + if( m_replayCache.empty() ) m_isReplaying = false; }