mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-25 22:17:45 +00:00
Cleanup of event system.
This commit is contained in:
parent
3cd60e0633
commit
ee6bf76124
8 changed files with 56 additions and 50 deletions
|
@ -15,6 +15,19 @@ namespace Sapphire::Common::EventSystem
|
|||
virtual ~LoginEvent() = default;
|
||||
|
||||
|
||||
uint64_t characterId;
|
||||
};
|
||||
|
||||
class LogoutEvent : public Event
|
||||
{
|
||||
public:
|
||||
static constexpr DescriptorType descriptor = "LogoutEvent";
|
||||
virtual DescriptorType type() const { return descriptor; }
|
||||
|
||||
LogoutEvent( uint64_t charId ) : characterId( charId ) {};
|
||||
virtual ~LogoutEvent() = default;
|
||||
|
||||
|
||||
uint64_t characterId;
|
||||
};
|
||||
|
||||
|
|
|
@ -29,16 +29,6 @@ using namespace Sapphire::Network::Packets;
|
|||
using namespace Sapphire::Network::Packets::WorldPackets::Server;
|
||||
using namespace Sapphire::World::Manager;
|
||||
|
||||
void FreeCompanyMgr::handleEvent( const Common::EventSystem::Event& e )
|
||||
{
|
||||
if( e.type() == Common::EventSystem::LoginEvent::descriptor )
|
||||
{
|
||||
const Common::EventSystem::LoginEvent& loginEvent = static_cast< const Common::EventSystem::LoginEvent& >( e );
|
||||
onFcLogin( loginEvent.characterId );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool FreeCompanyMgr::loadFreeCompanies()
|
||||
{
|
||||
auto& chatChannelMgr = Common::Service< Manager::ChatChannelMgr >::ref();
|
||||
|
@ -249,10 +239,13 @@ void FreeCompanyMgr::sendFcStatus( Entity::Player& player )
|
|||
server.queueForPlayer( player.getCharacterId(), fcResultPacket );
|
||||
}
|
||||
|
||||
void FreeCompanyMgr::onFcLogin( uint64_t characterId )
|
||||
void FreeCompanyMgr::onFcLogin( const Common::EventSystem::Event& e )
|
||||
{
|
||||
Logger::debug( "{}", __FUNCTION__ );
|
||||
const auto& loginEvent = static_cast< const Common::EventSystem::LoginEvent& >( e );
|
||||
|
||||
auto& server = Common::Service< World::WorldServer >::ref();
|
||||
auto player = server.getPlayer( characterId );
|
||||
auto player = server.getPlayer( loginEvent.characterId );
|
||||
if( !player )
|
||||
return;
|
||||
|
||||
|
@ -273,13 +266,14 @@ void FreeCompanyMgr::onFcLogin( uint64_t characterId )
|
|||
0, FreeCompanyResultPacket::UpdateStatus::Member,
|
||||
fc->getName(), player->getName() );
|
||||
|
||||
server.queueForFreeCompany( fc->getId(), fcResultOthers, { characterId } );
|
||||
server.queueForFreeCompany( fc->getId(), fcResultOthers, { loginEvent.characterId } );
|
||||
}
|
||||
|
||||
void FreeCompanyMgr::onFcLogout( uint64_t characterId )
|
||||
void FreeCompanyMgr::onFcLogout( const Common::EventSystem::Event& e )
|
||||
{
|
||||
const auto& logoutEvent = static_cast< const Common::EventSystem::LogoutEvent& >( e );
|
||||
auto& server = Common::Service< World::WorldServer >::ref();
|
||||
auto player = server.getPlayer( characterId );
|
||||
auto player = server.getPlayer( logoutEvent.characterId );
|
||||
if( !player )
|
||||
return;
|
||||
|
||||
|
@ -293,7 +287,7 @@ void FreeCompanyMgr::onFcLogout( uint64_t characterId )
|
|||
0, FreeCompanyResultPacket::UpdateStatus::Member,
|
||||
fc->getName(), player->getName() );
|
||||
|
||||
server.queueForFreeCompany( fc->getId(), fcResultOthers, { characterId } );
|
||||
server.queueForFreeCompany( fc->getId(), fcResultOthers, { logoutEvent.characterId } );
|
||||
}
|
||||
|
||||
void FreeCompanyMgr::onSignPetition( Entity::Player& source, Entity::Player& target )
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
#include "ForwardsZone.h"
|
||||
#include "FreeCompany/FreeCompany.h"
|
||||
#include <Event/Observer.h>
|
||||
#include <Event/EventDefinitions/EventDefinitions.h>
|
||||
|
||||
namespace Sapphire::World::Manager
|
||||
{
|
||||
|
||||
class FreeCompanyMgr : public Common::EventSystem::EventObserver
|
||||
class FreeCompanyMgr
|
||||
{
|
||||
private:
|
||||
std::unordered_map< uint64_t, FreeCompanyPtr > m_fcIdMap;
|
||||
|
@ -26,8 +27,6 @@ namespace Sapphire::World::Manager
|
|||
|
||||
FreeCompanyMgr() = default;
|
||||
|
||||
void handleEvent( const Common::EventSystem::Event& e );
|
||||
|
||||
// initialize all fcs from db to memory
|
||||
bool loadFreeCompanies();
|
||||
void writeFreeCompany( uint64_t fcId );
|
||||
|
@ -69,8 +68,11 @@ namespace Sapphire::World::Manager
|
|||
// void leaveLinkshell( uint64_t lsId, uint64_t characterId );
|
||||
// void joinLinkshell( uint64_t lsId, uint64_t characterId );
|
||||
|
||||
void onFcLogin( uint64_t characterId );
|
||||
void onFcLogout( uint64_t characterId );
|
||||
/// Events
|
||||
void onFcLogin( const Common::EventSystem::Event& e );
|
||||
void onFcLogout( const Common::EventSystem::Event& e );
|
||||
///
|
||||
|
||||
void onSignPetition( Entity::Player& source, Entity::Player& target );
|
||||
|
||||
};
|
||||
|
|
|
@ -49,17 +49,6 @@ using namespace Sapphire::Network::Packets;
|
|||
using namespace Sapphire::Network::Packets::WorldPackets::Server;
|
||||
using namespace Sapphire::Network::ActorControl;
|
||||
|
||||
void PlayerMgr::handleEvent( const Common::EventSystem::Event& e )
|
||||
{
|
||||
if( e.type() == Common::EventSystem::LoginEvent::descriptor )
|
||||
{
|
||||
const Common::EventSystem::LoginEvent& loginEvent = static_cast< const Common::EventSystem::LoginEvent& >( e );
|
||||
auto player = server().getPlayer( loginEvent.characterId );
|
||||
onLogin( *player );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PlayerMgr::onOnlineStatusChanged( Entity::Player& player, bool updateProfile )
|
||||
{
|
||||
auto statusPacket = makeZonePacket< FFXIVIpcSetOnlineStatus >( player.getId() );
|
||||
|
@ -349,8 +338,11 @@ void PlayerMgr::onClassChanged( Entity::Player& player )
|
|||
onPlayerHpMpTpChanged( player );
|
||||
}
|
||||
|
||||
void PlayerMgr::onLogin( Entity::Player& player )
|
||||
void PlayerMgr::onLogin( const Common::EventSystem::Event& e )
|
||||
{
|
||||
Logger::debug( "{}", __FUNCTION__ );
|
||||
const auto& loginEvent = dynamic_cast< const Common::EventSystem::LoginEvent& >( e );
|
||||
auto player = *server().getPlayer( loginEvent.characterId );
|
||||
auto motd = server().getConfig().motd;
|
||||
|
||||
std::istringstream ss( motd );
|
||||
|
@ -361,15 +353,15 @@ void PlayerMgr::onLogin( Entity::Player& player )
|
|||
}
|
||||
}
|
||||
|
||||
void PlayerMgr::onLogout( Entity::Player &player )
|
||||
void PlayerMgr::onLogout( const Common::EventSystem::Event& e )
|
||||
{
|
||||
const auto& logoutEvent = dynamic_cast< const Common::EventSystem::LogoutEvent& >( e );
|
||||
auto player = *server().getPlayer( logoutEvent.characterId );
|
||||
|
||||
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 )
|
||||
|
|
|
@ -3,17 +3,15 @@
|
|||
#include "ForwardsZone.h"
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
#include "MgrUtil.h"
|
||||
#include <Event/Observer.h>
|
||||
#include <Event/Event.h>
|
||||
|
||||
namespace Sapphire::World::Manager
|
||||
{
|
||||
class PlayerMgr : public Common::EventSystem::EventObserver
|
||||
class PlayerMgr
|
||||
{
|
||||
public:
|
||||
PlayerMgr() = default;
|
||||
|
||||
void handleEvent( const Common::EventSystem::Event& e );
|
||||
|
||||
void onOnlineStatusChanged( Sapphire::Entity::Player& player, bool updateProfile = true );
|
||||
|
||||
void onEquipDisplayFlagsChanged( Sapphire::Entity::Player& player );
|
||||
|
@ -42,8 +40,11 @@ namespace Sapphire::World::Manager
|
|||
|
||||
void onHateListChanged( Sapphire::Entity::Player& player );
|
||||
|
||||
void onLogin( Sapphire::Entity::Player& player );
|
||||
void onLogout( Sapphire::Entity::Player& player );
|
||||
/// Events
|
||||
void onLogin( const Common::EventSystem::Event& e );
|
||||
void onLogout( const Common::EventSystem::Event& e );
|
||||
///
|
||||
|
||||
void onDeath( Sapphire::Entity::Player& player );
|
||||
void onMoveZone( Sapphire::Entity::Player& player );
|
||||
|
||||
|
|
|
@ -353,7 +353,6 @@ void Sapphire::Network::GameConnection::loginHandler( const Packets::FFXIVARR_PA
|
|||
player.setIsLogin( true );
|
||||
player.setConnected( true );
|
||||
teriMgr.joinWorld( player );
|
||||
fcMgr.onFcLogin( player.getCharacterId() );
|
||||
}
|
||||
|
||||
void Sapphire::Network::GameConnection::syncHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player )
|
||||
|
|
|
@ -77,9 +77,6 @@ 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -312,8 +312,15 @@ void WorldServer::run( int32_t argc, char* argv[] )
|
|||
Common::Service< ContentFinder >::set( contentFinder );
|
||||
Common::Service< Manager::TaskMgr >::set( taskMgr );
|
||||
|
||||
dispatcher->subscribe( Common::EventSystem::LoginEvent::descriptor, std::bind( &Manager::PlayerMgr::handleEvent, pPlayerMgr, std::placeholders::_1 ) );
|
||||
dispatcher->subscribe( Common::EventSystem::LoginEvent::descriptor, std::bind( &Manager::FreeCompanyMgr::handleEvent, pFcMgr, std::placeholders::_1 ) );
|
||||
using namespace Common;
|
||||
using namespace Manager;
|
||||
using namespace std::placeholders;
|
||||
|
||||
dispatcher->subscribe( EventSystem::LoginEvent::descriptor, std::bind( &PlayerMgr::onLogin, pPlayerMgr, _1 ) );
|
||||
dispatcher->subscribe( EventSystem::LoginEvent::descriptor, std::bind( &FreeCompanyMgr::onFcLogin, pFcMgr, _1 ) );
|
||||
|
||||
dispatcher->subscribe( EventSystem::LogoutEvent::descriptor, std::bind( &PlayerMgr::onLogout, pPlayerMgr, _1 ) );
|
||||
dispatcher->subscribe( EventSystem::LogoutEvent::descriptor, std::bind( &FreeCompanyMgr::onFcLogout, pFcMgr, _1 ) );
|
||||
|
||||
|
||||
Logger::info( "World server running on {0}:{1}", m_ip, m_port );
|
||||
|
@ -411,6 +418,8 @@ void WorldServer::updateSessions( uint32_t currTime )
|
|||
player.removeOnlineStatus( Common::OnlineStatus::Online );
|
||||
player.addOnlineStatus( Common::OnlineStatus::Offline );
|
||||
|
||||
auto dispatcher = Common::Service< Common::EventSystem::EventDispatcher >::ref();
|
||||
dispatcher.emit( Common::EventSystem::LogoutEvent( player.getCharacterId() ) );
|
||||
Logger::info( "[{0}] Session removal", session->getId() );
|
||||
session->close();
|
||||
sessionRemovalQueue.push( session->getId() );
|
||||
|
@ -545,7 +554,6 @@ Sapphire::Entity::PlayerPtr WorldServer::getPlayer( uint32_t entityId )
|
|||
|
||||
Sapphire::Entity::PlayerPtr WorldServer::getPlayer( uint64_t characterId )
|
||||
{
|
||||
//std::lock_guard<std::mutex> lock( m_sessionMutex );
|
||||
auto it = m_playerMapByCharacterId.find( characterId );
|
||||
|
||||
if( it != m_playerMapByCharacterId.end() )
|
||||
|
|
Loading…
Add table
Reference in a new issue