mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-26 06:27:45 +00:00
start of new service locator impl
This commit is contained in:
parent
8f71d01a69
commit
3a2272594e
22 changed files with 223 additions and 73 deletions
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include <Util/CrashHandler.h>
|
||||
|
||||
Sapphire::Common::Util::CrashHandler crashHandler;
|
||||
[[maybe_unused]] Sapphire::Common::Util::CrashHandler crashHandler;
|
||||
|
||||
Sapphire::Db::DbWorkerPool< Sapphire::Db::ZoneDbConnection > g_charaDb;
|
||||
Sapphire::Data::ExdDataGenerated g_exdDataGen;
|
||||
|
|
114
src/common/Service.h
Normal file
114
src/common/Service.h
Normal file
|
@ -0,0 +1,114 @@
|
|||
#ifndef SAPPHIRE_SERVICE_H
|
||||
#define SAPPHIRE_SERVICE_H
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
// stolen from: https://github.com/skypjack/entt/blob/master/src/entt/locator/locator.hpp
|
||||
|
||||
namespace Sapphire::Common
|
||||
{
|
||||
/**
|
||||
* @brief Service locator, nothing more.
|
||||
*
|
||||
* A service locator can be used to do what it promises: locate services.<br/>
|
||||
* Usually service locators are tightly bound to the services they expose and
|
||||
* thus it's hard to define a general purpose class to do that. This template
|
||||
* based implementation tries to fill the gap and to get rid of the burden of
|
||||
* defining a different specific locator for each application.
|
||||
*
|
||||
* @tparam SvcType Type of service managed by the locator.
|
||||
*/
|
||||
template< typename SvcType >
|
||||
struct Service
|
||||
{
|
||||
/*! @brief Type of service offered. */
|
||||
using ServiceType = SvcType;
|
||||
|
||||
/*! @brief Default constructor, deleted on purpose. */
|
||||
Service() = delete;
|
||||
|
||||
/*! @brief Default destructor, deleted on purpose. */
|
||||
~Service() = delete;
|
||||
|
||||
/**
|
||||
* @brief Tests if a valid service implementation is set.
|
||||
* @return True if the service is set, false otherwise.
|
||||
*/
|
||||
static bool empty() noexcept
|
||||
{
|
||||
return !static_cast< bool >( service );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a weak pointer to a service implementation, if any.
|
||||
*
|
||||
* Clients of a service shouldn't retain references to it. The recommended
|
||||
* way is to retrieve the service implementation currently set each and
|
||||
* every time the need of using it arises. Otherwise users can incur in
|
||||
* unexpected behaviors.
|
||||
*
|
||||
* @return A reference to the service implementation currently set, if any.
|
||||
*/
|
||||
static std::weak_ptr< SvcType > get() noexcept
|
||||
{
|
||||
return service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a weak reference to a service implementation, if any.
|
||||
*
|
||||
* Clients of a service shouldn't retain references to it. The recommended
|
||||
* way is to retrieve the service implementation currently set each and
|
||||
* every time the need of using it arises. Otherwise users can incur in
|
||||
* unexpected behaviors.
|
||||
*
|
||||
* @warning
|
||||
* In case no service implementation has been set, a call to this function
|
||||
* results in undefined behavior.
|
||||
*
|
||||
* @return A reference to the service implementation currently set, if any.
|
||||
*/
|
||||
static SvcType& ref() noexcept
|
||||
{
|
||||
return *service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets or replaces a service.
|
||||
* @tparam Impl Type of the new service to use.
|
||||
* @tparam Args Types of arguments to use to construct the service.
|
||||
* @param args Parameters to use to construct the service.
|
||||
*/
|
||||
template< typename Impl = SvcType, typename... Args >
|
||||
static void set( Args&& ... args )
|
||||
{
|
||||
service = std::make_shared< Impl >( std::forward< Args >( args )... );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets or replaces a service.
|
||||
* @param ptr Service to use to replace the current one.
|
||||
*/
|
||||
static void set( std::shared_ptr< SvcType > ptr )
|
||||
{
|
||||
assert( static_cast< bool >( ptr ) );
|
||||
service = std::move( ptr );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resets a service.
|
||||
*
|
||||
* The service is no longer valid after a reset.
|
||||
*/
|
||||
static void reset()
|
||||
{
|
||||
service.reset();
|
||||
}
|
||||
|
||||
private:
|
||||
inline static std::shared_ptr< SvcType > service = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //SAPPHIRE_SERVICE_H
|
|
@ -8,7 +8,7 @@
|
|||
#include <common/Util/CrashHandler.h>
|
||||
#include <common/Config/ConfigMgr.h>
|
||||
|
||||
Sapphire::Common::Util::CrashHandler crashHandler;
|
||||
[[maybe_unused]] Sapphire::Common::Util::CrashHandler crashHandler;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <Util/CrashHandler.h>
|
||||
|
||||
Sapphire::Common::Util::CrashHandler crashHandler;
|
||||
[[maybe_unused]] Sapphire::Common::Util::CrashHandler crashHandler;
|
||||
|
||||
Sapphire::Lobby::ServerLobby g_serverLobby( "lobby.ini" );
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
#include <filesystem>
|
||||
|
||||
Sapphire::Common::Util::CrashHandler crashHandler;
|
||||
[[maybe_unused]] Sapphire::Common::Util::CrashHandler crashHandler;
|
||||
Sapphire::Data::ExdDataGenerated g_exdData;
|
||||
|
||||
using namespace Sapphire;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include <filesystem>
|
||||
|
||||
Sapphire::Common::Util::CrashHandler crashHandler;
|
||||
[[maybe_unused]] Sapphire::Common::Util::CrashHandler crashHandler;
|
||||
|
||||
Sapphire::Data::ExdDataGenerated g_exdData;
|
||||
xiv::dat::GameData* gameData = nullptr;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#include <filesystem>
|
||||
|
||||
Sapphire::Common::Util::CrashHandler crashHandler;
|
||||
[[maybe_unused]] Sapphire::Common::Util::CrashHandler crashHandler;
|
||||
|
||||
Sapphire::Data::ExdDataGenerated g_exdData;
|
||||
xiv::dat::GameData* gameData = nullptr;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <Network/CommonActorControl.h>
|
||||
#include <Network/PacketWrappers/EffectPacket.h>
|
||||
#include <cmath>
|
||||
#include <Service.h>
|
||||
|
||||
#include "Session.h"
|
||||
#include "Player.h"
|
||||
|
@ -114,8 +115,8 @@ Sapphire::Entity::Player::~Player()
|
|||
|
||||
void Sapphire::Entity::Player::injectPacket( const std::string& path )
|
||||
{
|
||||
auto pServerZone = m_pFw->get< World::ServerMgr >();
|
||||
auto session = pServerZone->getSession( getId() );
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
auto session = serverMgr.getSession( getId() );
|
||||
if( session )
|
||||
session->getZoneConnection()->injectPacket( path, *this );
|
||||
}
|
||||
|
@ -1257,8 +1258,8 @@ const uint8_t* Sapphire::Entity::Player::getGcRankArray() const
|
|||
|
||||
void Sapphire::Entity::Player::queuePacket( Network::Packets::FFXIVPacketBasePtr pPacket )
|
||||
{
|
||||
auto pServerZone = m_pFw->get< World::ServerMgr >();
|
||||
auto pSession = pServerZone->getSession( m_id );
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
auto pSession = serverMgr.getSession( m_id );
|
||||
|
||||
if( !pSession )
|
||||
return;
|
||||
|
@ -1272,8 +1273,8 @@ void Sapphire::Entity::Player::queuePacket( Network::Packets::FFXIVPacketBasePtr
|
|||
|
||||
void Sapphire::Entity::Player::queueChatPacket( Network::Packets::FFXIVPacketBasePtr pPacket )
|
||||
{
|
||||
auto pServerZone = m_pFw->get< World::ServerMgr >();
|
||||
auto pSession = pServerZone->getSession( m_id );
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
auto pSession = serverMgr.getSession( m_id );
|
||||
|
||||
if( !pSession )
|
||||
return;
|
||||
|
@ -1689,8 +1690,8 @@ void Sapphire::Entity::Player::sendZonePackets()
|
|||
if( isLogin() )
|
||||
{
|
||||
//Update player map in servermgr - in case player name has been changed
|
||||
auto pServerMgr = m_pFw->get< World::ServerMgr >();
|
||||
pServerMgr->updatePlayerName( getId(), getName() );
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
serverMgr.updatePlayerName( getId(), getName() );
|
||||
}
|
||||
|
||||
getCurrentTerritory()->onBeforePlayerZoneIn( *this );
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <Common.h>
|
||||
#include <Logging/Logger.h>
|
||||
#include <Network/PacketContainer.h>
|
||||
#include <Service.h>
|
||||
|
||||
#include "Network/GameConnection.h"
|
||||
#include "Network/PacketWrappers/ActorControlPacket.h"
|
||||
|
@ -341,8 +342,9 @@ void Sapphire::Entity::Player::eventItemActionStart( uint32_t eventId,
|
|||
|
||||
void Sapphire::Entity::Player::onLogin()
|
||||
{
|
||||
auto pServerMgr = m_pFw->get< Sapphire::World::ServerMgr >();
|
||||
auto motd = pServerMgr->getConfig().motd;
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
auto motd = serverMgr.getConfig().motd;
|
||||
|
||||
std::istringstream ss( motd );
|
||||
std::string msg;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <Database/DatabaseDef.h>
|
||||
#include <cmath>
|
||||
#include <Network/PacketWrappers/EffectPacket.h>
|
||||
#include <Service.h>
|
||||
|
||||
#include "DebugCommand/DebugCommand.h"
|
||||
#include "DebugCommandMgr.h"
|
||||
|
@ -372,6 +373,8 @@ void Sapphire::World::Manager::DebugCommandMgr::set( char* data, Entity::Player&
|
|||
void Sapphire::World::Manager::DebugCommandMgr::add( char* data, Entity::Player& player,
|
||||
std::shared_ptr< DebugCommand > command )
|
||||
{
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
std::string subCommand;
|
||||
std::string params = "";
|
||||
|
||||
|
@ -418,9 +421,7 @@ void Sapphire::World::Manager::DebugCommandMgr::add( char* data, Entity::Player&
|
|||
}
|
||||
else if( subCommand == "bnpc" )
|
||||
{
|
||||
auto serverZone = framework()->get< World::ServerMgr >();
|
||||
|
||||
auto bNpcTemplate = serverZone->getBNpcTemplate( params );
|
||||
auto bNpcTemplate = serverMgr.getBNpcTemplate( params );
|
||||
|
||||
if( !bNpcTemplate )
|
||||
{
|
||||
|
@ -577,8 +578,9 @@ void
|
|||
Sapphire::World::Manager::DebugCommandMgr::injectPacket( char* data, Entity::Player& player,
|
||||
std::shared_ptr< DebugCommand > command )
|
||||
{
|
||||
auto pServerZone = framework()->get< World::ServerMgr >();
|
||||
auto pSession = pServerZone->getSession( player.getId() );
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
auto pSession = serverMgr.getSession( player.getId() );
|
||||
if( pSession )
|
||||
pSession->getZoneConnection()->injectPacket( data + 7, player );
|
||||
}
|
||||
|
@ -586,8 +588,9 @@ Sapphire::World::Manager::DebugCommandMgr::injectPacket( char* data, Entity::Pla
|
|||
void Sapphire::World::Manager::DebugCommandMgr::injectChatPacket( char* data, Entity::Player& player,
|
||||
std::shared_ptr< DebugCommand > command )
|
||||
{
|
||||
auto pServerZone = framework()->get< World::ServerMgr >();
|
||||
auto pSession = pServerZone->getSession( player.getId() );
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
auto pSession = serverMgr.getSession( player.getId() );
|
||||
if( pSession )
|
||||
pSession->getChatConnection()->injectPacket( data + 8, player );
|
||||
}
|
||||
|
@ -595,7 +598,8 @@ void Sapphire::World::Manager::DebugCommandMgr::injectChatPacket( char* data, En
|
|||
void Sapphire::World::Manager::DebugCommandMgr::replay( char* data, Entity::Player& player,
|
||||
std::shared_ptr< DebugCommand > command )
|
||||
{
|
||||
auto pServerZone = framework()->get< World::ServerMgr >();
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
std::string subCommand;
|
||||
std::string params = "";
|
||||
|
||||
|
@ -620,19 +624,19 @@ void Sapphire::World::Manager::DebugCommandMgr::replay( char* data, Entity::Play
|
|||
|
||||
if( subCommand == "start" )
|
||||
{
|
||||
auto pSession = pServerZone->getSession( player.getId() );
|
||||
auto pSession = serverMgr.getSession( player.getId() );
|
||||
if( pSession )
|
||||
pSession->startReplay( params );
|
||||
}
|
||||
else if( subCommand == "stop" )
|
||||
{
|
||||
auto pSession = pServerZone->getSession( player.getId() );
|
||||
auto pSession = serverMgr.getSession( player.getId() );
|
||||
if( pSession )
|
||||
pSession->stopReplay();
|
||||
}
|
||||
else if( subCommand == "info" )
|
||||
{
|
||||
auto pSession = pServerZone->getSession( player.getId() );
|
||||
auto pSession = serverMgr.getSession( player.getId() );
|
||||
if( pSession )
|
||||
pSession->sendReplayInfo();
|
||||
}
|
||||
|
@ -695,10 +699,11 @@ void
|
|||
Sapphire::World::Manager::DebugCommandMgr::serverInfo( char* data, Entity::Player& player,
|
||||
std::shared_ptr< DebugCommand > command )
|
||||
{
|
||||
auto pServerZone = framework()->get< World::ServerMgr >();
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
player.sendDebug( "SapphireZone {0} \nRev: {1}", Version::VERSION, Version::GIT_HASH );
|
||||
player.sendDebug( "Compiled: " __DATE__ " " __TIME__ );
|
||||
player.sendDebug( "Sessions: {0}", pServerZone->getSessionCount() );
|
||||
player.sendDebug( "Sessions: {0}", serverMgr.getSessionCount() );
|
||||
}
|
||||
|
||||
void Sapphire::World::Manager::DebugCommandMgr::script( char* data, Entity::Player& player,
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <unordered_map>
|
||||
#include <cstring>
|
||||
#include <Service.h>
|
||||
|
||||
#include "Actor/Player.h"
|
||||
#include "Actor/EventObject.h"
|
||||
|
@ -310,6 +311,8 @@ Sapphire::LandPtr Sapphire::World::Manager::HousingMgr::getLandByOwnerId( uint32
|
|||
|
||||
void Sapphire::World::Manager::HousingMgr::sendLandSignOwned( Entity::Player& player, const Common::LandIdent ident )
|
||||
{
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
player.setActiveLand( static_cast< uint8_t >( ident.landId ), static_cast< uint8_t >( ident.wardNum ) );
|
||||
|
||||
auto landSetId = toLandSetId( static_cast< uint16_t >( ident.territoryTypeId ), static_cast< uint8_t >( ident.wardNum ) );
|
||||
|
@ -336,7 +339,8 @@ void Sapphire::World::Manager::HousingMgr::sendLandSignOwned( Entity::Player& pl
|
|||
}
|
||||
|
||||
uint32_t playerId = static_cast< uint32_t >( land->getOwnerId() );
|
||||
std::string playerName = framework()->get< World::ServerMgr >()->getPlayerNameFromDb( playerId );
|
||||
|
||||
std::string playerName = serverMgr.getPlayerNameFromDb( playerId );
|
||||
|
||||
memcpy( &landInfoSignPacket->data().ownerName, playerName.c_str(), playerName.size() );
|
||||
|
||||
|
@ -463,6 +467,8 @@ bool Sapphire::World::Manager::HousingMgr::relinquishLand( Entity::Player& playe
|
|||
|
||||
void Sapphire::World::Manager::HousingMgr::sendWardLandInfo( Entity::Player& player, uint8_t wardId, uint16_t territoryTypeId )
|
||||
{
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
auto landSetId = toLandSetId( territoryTypeId, wardId );
|
||||
auto hZone = getHousingZoneByLandSetId( landSetId );
|
||||
|
||||
|
@ -509,7 +515,7 @@ void Sapphire::World::Manager::HousingMgr::sendWardLandInfo( Entity::Player& pla
|
|||
entry.infoFlags |= Common::WardlandFlags::IsEstateOwned;
|
||||
|
||||
auto owner = land->getOwnerId();
|
||||
auto playerName = framework()->get< World::ServerMgr >()->getPlayerNameFromDb( static_cast< uint32_t >( owner ) );
|
||||
auto playerName = serverMgr.getPlayerNameFromDb( static_cast< uint32_t >( owner ) );
|
||||
memcpy( &entry.estateOwnerName, playerName.c_str(), playerName.size() );
|
||||
|
||||
break;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "ServerMgr.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <Service.h>
|
||||
|
||||
#include "Actor/Player.h"
|
||||
|
||||
|
@ -72,7 +73,8 @@ bool Sapphire::World::Manager::TerritoryMgr::init()
|
|||
return false;
|
||||
}
|
||||
|
||||
auto& cfg = framework()->get< World::ServerMgr >()->getConfig();
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
auto& cfg = serverMgr.getConfig();
|
||||
|
||||
m_inRangeDistance = cfg.network.inRangeDistance;
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <DetourCommon.h>
|
||||
#include <recastnavigation/Recast/Include/Recast.h>
|
||||
#include <filesystem>
|
||||
#include <Service.h>
|
||||
|
||||
Sapphire::World::Navi::NaviProvider::NaviProvider( const std::string& internalName, FrameworkPtr pFw ) :
|
||||
m_naviMesh( nullptr ),
|
||||
|
@ -32,7 +33,8 @@ Sapphire::World::Navi::NaviProvider::NaviProvider( const std::string& internalNa
|
|||
|
||||
bool Sapphire::World::Navi::NaviProvider::init()
|
||||
{
|
||||
auto& cfg = m_pFw->get< Sapphire::World::ServerMgr >()->getConfig();
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
auto& cfg = serverMgr.getConfig();
|
||||
|
||||
auto meshesFolder = std::filesystem::path( cfg.navigation.meshPath );
|
||||
auto meshFolder = meshesFolder / std::filesystem::path( m_internalName );
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <Network/Acceptor.h>
|
||||
#include <Network/PacketContainer.h>
|
||||
#include <Network/GamePacketParser.h>
|
||||
#include <Service.h>
|
||||
|
||||
#include "Territory/Territory.h"
|
||||
|
||||
|
@ -380,7 +381,7 @@ void Sapphire::Network::GameConnection::injectPacket( const std::string& packetp
|
|||
void Sapphire::Network::GameConnection::handlePackets( const Sapphire::Network::Packets::FFXIVARR_PACKET_HEADER& ipcHeader,
|
||||
const std::vector< Sapphire::Network::Packets::FFXIVARR_PACKET_RAW >& packetData )
|
||||
{
|
||||
auto pServerZone = m_pFw->get< World::ServerMgr >();
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
// if a session is set, update the last time it recieved a game packet
|
||||
if( m_pSession )
|
||||
|
@ -397,18 +398,18 @@ void Sapphire::Network::GameConnection::handlePackets( const Sapphire::Network::
|
|||
auto pCon = std::static_pointer_cast< GameConnection, Connection >( shared_from_this() );
|
||||
|
||||
// try to retrieve the session for this id
|
||||
auto session = pServerZone->getSession( playerId );
|
||||
auto session = serverMgr.getSession( playerId );
|
||||
|
||||
if( !session )
|
||||
{
|
||||
Logger::info( "[{0}] Session not registered, creating", id );
|
||||
// return;
|
||||
if( !pServerZone->createSession( playerId ) )
|
||||
if( !serverMgr.createSession( playerId ) )
|
||||
{
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
session = pServerZone->getSession( playerId );
|
||||
session = serverMgr.getSession( playerId );
|
||||
}
|
||||
//TODO: Catch more things in lobby and send real errors
|
||||
else if( !session->isValid() || ( session->getPlayer() && session->getPlayer()->getLastPing() != 0 ) )
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "Forwards.h"
|
||||
#include "Framework.h"
|
||||
#include <Network/PacketDef/Lobby/ServerLobbyDef.h>
|
||||
#include <Service.h>
|
||||
|
||||
using namespace Sapphire::Common;
|
||||
using namespace Sapphire::Network::Packets;
|
||||
|
@ -45,7 +46,8 @@ void examineHandler( Sapphire::FrameworkPtr pFw, Sapphire::Entity::Player& playe
|
|||
{
|
||||
using namespace Sapphire;
|
||||
|
||||
auto pSession = pFw->get< World::ServerMgr >()->getSession( targetId );
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
auto pSession = serverMgr.getSession( targetId );
|
||||
if( pSession )
|
||||
{
|
||||
auto pTarget = pSession->getPlayer();
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <Exd/ExdDataGenerated.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <Service.h>
|
||||
|
||||
#include "Network/GameConnection.h"
|
||||
|
||||
|
@ -594,7 +595,7 @@ void Sapphire::Network::GameConnection::gm2Handler( FrameworkPtr pFw,
|
|||
if( player.getGmRank() <= 0 )
|
||||
return;
|
||||
|
||||
auto pServerZone = pFw->get< World::ServerMgr >();
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
const auto packet = ZoneChannelPacket< Client::FFXIVIpcGmCommand2 >( inPacket );
|
||||
|
||||
|
@ -608,7 +609,7 @@ void Sapphire::Network::GameConnection::gm2Handler( FrameworkPtr pFw,
|
|||
Logger::debug( "{0} used GM2 commandId: {1}, params: {2}, {3}, {4}, {5}, target: {6}",
|
||||
player.getName(), commandId, param1, param2, param3, param4, target );
|
||||
|
||||
auto targetSession = pServerZone->getSession( target );
|
||||
auto targetSession = serverMgr.getSession( target );
|
||||
Sapphire::Entity::CharaPtr targetActor;
|
||||
|
||||
if( targetSession != nullptr )
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <unordered_map>
|
||||
#include <Network/PacketDef/Zone/ClientZoneDef.h>
|
||||
#include <Logging/Logger.h>
|
||||
#include <Service.h>
|
||||
|
||||
#include "Network/GameConnection.h"
|
||||
|
||||
|
@ -120,7 +121,8 @@ void Sapphire::Network::GameConnection::reqExamineSearchCommentHandler( Framewor
|
|||
{
|
||||
|
||||
auto targetId = *reinterpret_cast< const uint32_t* >( &inPacket.data[ 0x10 ] );
|
||||
auto pSession = pFw->get< World::ServerMgr >()->getSession( targetId );
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
auto pSession = serverMgr.getSession( targetId );
|
||||
|
||||
Logger::debug( "reqExamineSearchCommentHandler: {0}", targetId );
|
||||
|
||||
|
@ -148,7 +150,9 @@ void Sapphire::Network::GameConnection::reqExamineFcInfo( FrameworkPtr pFw,
|
|||
{
|
||||
|
||||
auto targetId = *reinterpret_cast< const uint32_t* >( &inPacket.data[ 0x18 ] );
|
||||
auto pSession = pFw->get< World::ServerMgr >()->getSession( targetId );
|
||||
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
auto pSession = serverMgr.getSession( targetId );
|
||||
|
||||
Logger::debug( "reqExamineFcInfo: {0}", targetId );
|
||||
|
||||
|
@ -566,9 +570,9 @@ void Sapphire::Network::GameConnection::tellHandler( FrameworkPtr pFw,
|
|||
{
|
||||
const auto packet = ZoneChannelPacket< Client::FFXIVIpcTellHandler >( inPacket );
|
||||
|
||||
auto pZoneServer = pFw->get< World::ServerMgr >();
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
auto pSession = pZoneServer->getSession( packet.data().targetPCName );
|
||||
auto pSession = serverMgr.getSession( packet.data().targetPCName );
|
||||
|
||||
if( !pSession )
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "NativeScriptMgr.h"
|
||||
|
||||
#include <Crypt/md5.h>
|
||||
#include <Service.h>
|
||||
#include "ServerMgr.h"
|
||||
|
||||
#include "Framework.h"
|
||||
|
@ -124,8 +125,9 @@ namespace Sapphire::Scripting
|
|||
NativeScriptMgr::NativeScriptMgr( FrameworkPtr pFw ) :
|
||||
World::Manager::BaseManager( pFw )
|
||||
{
|
||||
auto pServerMgr = framework()->get< Sapphire::World::ServerMgr >();
|
||||
m_loader.setCachePath( pServerMgr->getConfig().scripts.cachePath );
|
||||
auto& serverMgr = Common::Service< Sapphire::World::ServerMgr >::ref();
|
||||
|
||||
m_loader.setCachePath( serverMgr.getConfig().scripts.cachePath );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <Exd/ExdDataGenerated.h>
|
||||
|
||||
#include <watchdog/Watchdog.h>
|
||||
#include <Service.h>
|
||||
|
||||
#include "Territory/Territory.h"
|
||||
#include "Territory/InstanceContent.h"
|
||||
|
@ -49,9 +50,9 @@ void Sapphire::Scripting::ScriptMgr::update()
|
|||
bool Sapphire::Scripting::ScriptMgr::init()
|
||||
{
|
||||
std::set< std::string > files;
|
||||
auto pServerMgr = framework()->get< World::ServerMgr >();
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
auto status = loadDir( pServerMgr->getConfig().scripts.path, files, m_nativeScriptMgr->getModuleExtension() );
|
||||
auto status = loadDir( serverMgr.getConfig().scripts.path, files, m_nativeScriptMgr->getModuleExtension() );
|
||||
|
||||
if( !status )
|
||||
{
|
||||
|
@ -81,12 +82,12 @@ bool Sapphire::Scripting::ScriptMgr::init()
|
|||
|
||||
void Sapphire::Scripting::ScriptMgr::watchDirectories()
|
||||
{
|
||||
auto pServerMgr = framework()->get< World::ServerMgr >();
|
||||
auto shouldWatch = pServerMgr->getConfig().scripts.hotSwap;
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
auto shouldWatch = serverMgr.getConfig().scripts.hotSwap;
|
||||
if( !shouldWatch )
|
||||
return;
|
||||
|
||||
Watchdog::watchMany( pServerMgr->getConfig().scripts.path + "*" +
|
||||
Watchdog::watchMany( serverMgr.getConfig().scripts.path + "*" +
|
||||
m_nativeScriptMgr->getModuleExtension(),
|
||||
[ this ]( const std::vector< ci::fs::path >& paths )
|
||||
{
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <Database/ZoneDbConnection.h>
|
||||
#include <Database/DbWorkerPool.h>
|
||||
#include <Service.h>
|
||||
#include "Manager/LinkshellMgr.h"
|
||||
#include "Manager/TerritoryMgr.h"
|
||||
#include "Manager/HousingMgr.h"
|
||||
|
@ -66,20 +67,20 @@ size_t Sapphire::World::ServerMgr::getSessionCount() const
|
|||
|
||||
bool Sapphire::World::ServerMgr::loadSettings( int32_t argc, char* argv[] )
|
||||
{
|
||||
auto pConfig = framework()->get< Common::ConfigMgr >();
|
||||
auto& configMgr = Common::Service< Common::ConfigMgr >::ref();
|
||||
|
||||
Logger::info( "Loading config {0}", m_configName );
|
||||
|
||||
bool failedLoad = false;
|
||||
|
||||
// load global cfg first
|
||||
if( !pConfig->loadGlobalConfig( m_config.global ) )
|
||||
if( !configMgr.loadGlobalConfig( m_config.global ) )
|
||||
{
|
||||
Logger::fatal( "Error loading config global.ini, copying default..." );
|
||||
failedLoad = true;
|
||||
}
|
||||
|
||||
if( !pConfig->loadConfig( m_configName ) )
|
||||
if( !configMgr.loadConfig( m_configName ) )
|
||||
{
|
||||
Logger::fatal( "Error loading config {0}", m_configName );
|
||||
failedLoad = true;
|
||||
|
@ -93,20 +94,20 @@ bool Sapphire::World::ServerMgr::loadSettings( int32_t argc, char* argv[] )
|
|||
}
|
||||
|
||||
// load world specific config
|
||||
m_config.scripts.hotSwap = pConfig->getValue( "Scripts", "HotSwap", true );
|
||||
m_config.scripts.path = pConfig->getValue< std::string >( "Scripts", "Path", "./compiledscripts/" );
|
||||
m_config.scripts.cachePath = pConfig->getValue< std::string >( "Scripts", "CachePath", "./cache/" );
|
||||
m_config.scripts.hotSwap = configMgr.getValue( "Scripts", "HotSwap", true );
|
||||
m_config.scripts.path = configMgr.getValue< std::string >( "Scripts", "Path", "./compiledscripts/" );
|
||||
m_config.scripts.cachePath = configMgr.getValue< std::string >( "Scripts", "CachePath", "./cache/" );
|
||||
|
||||
m_config.navigation.meshPath = pConfig->getValue< std::string >( "Navigation", "MeshPath", "navi" );
|
||||
m_config.navigation.meshPath = configMgr.getValue< std::string >( "Navigation", "MeshPath", "navi" );
|
||||
|
||||
m_config.network.disconnectTimeout = pConfig->getValue< uint16_t >( "Network", "DisconnectTimeout", 20 );
|
||||
m_config.network.listenIp = pConfig->getValue< std::string >( "Network", "ListenIp", "0.0.0.0" );
|
||||
m_config.network.listenPort = pConfig->getValue< uint16_t >( "Network", "ListenPort", 54992 );
|
||||
m_config.network.inRangeDistance = pConfig->getValue< float >( "Network", "InRangeDistance", 80.f );
|
||||
m_config.network.disconnectTimeout = configMgr.getValue< uint16_t >( "Network", "DisconnectTimeout", 20 );
|
||||
m_config.network.listenIp = configMgr.getValue< std::string >( "Network", "ListenIp", "0.0.0.0" );
|
||||
m_config.network.listenPort = configMgr.getValue< uint16_t >( "Network", "ListenPort", 54992 );
|
||||
m_config.network.inRangeDistance = configMgr.getValue< float >( "Network", "InRangeDistance", 80.f );
|
||||
|
||||
m_config.motd = pConfig->getValue< std::string >( "General", "MotD", "" );
|
||||
m_config.motd = configMgr.getValue< std::string >( "General", "MotD", "" );
|
||||
|
||||
m_config.housing.defaultEstateName = pConfig->getValue< std::string >( "Housing", "DefaultEstateName", "Estate #{}" );
|
||||
m_config.housing.defaultEstateName = configMgr.getValue< std::string >( "Housing", "DefaultEstateName", "Estate #{}" );
|
||||
|
||||
m_port = m_config.network.listenPort;
|
||||
m_ip = m_config.network.listenIp;
|
||||
|
@ -124,7 +125,7 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] )
|
|||
printBanner();
|
||||
|
||||
auto pConfig = std::make_shared< Common::ConfigMgr >();
|
||||
framework()->set< Common::ConfigMgr >( pConfig );
|
||||
Common::Service< Common::ConfigMgr >::set( pConfig );
|
||||
if( !loadSettings( argc, argv ) )
|
||||
{
|
||||
Logger::fatal( "Unable to load settings!" );
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <Network/CommonActorControl.h>
|
||||
#include <Database/DatabaseDef.h>
|
||||
#include <Network/PacketWrappers/ActorControlSelfPacket.h>
|
||||
#include <Service.h>
|
||||
|
||||
#include "Territory.h"
|
||||
#include "InstanceContent.h"
|
||||
|
@ -251,7 +252,6 @@ void Sapphire::Territory::pushActor( Entity::ActorPtr pActor )
|
|||
agentId = m_pNaviProvider->addAgent( *pPlayer );
|
||||
pPlayer->setAgentId( agentId );
|
||||
|
||||
auto pServerZone = m_pFw->get< World::ServerMgr >();
|
||||
m_playerMap[ pPlayer->getId() ] = pPlayer;
|
||||
updateCellActivity( cx, cy, 2 );
|
||||
}
|
||||
|
@ -319,7 +319,8 @@ void Sapphire::Territory::queuePacketForRange( Entity::Player& sourcePlayer, uin
|
|||
if( pTeriMgr->isPrivateTerritory( getTerritoryTypeId() ) )
|
||||
return;
|
||||
|
||||
auto pServerZone = m_pFw->get< World::ServerMgr >();
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
for( auto entry : m_playerMap )
|
||||
{
|
||||
auto player = entry.second;
|
||||
|
@ -329,7 +330,7 @@ void Sapphire::Territory::queuePacketForRange( Entity::Player& sourcePlayer, uin
|
|||
if( ( distance < range ) && sourcePlayer.getId() != player->getId() )
|
||||
{
|
||||
|
||||
auto pSession = pServerZone->getSession( player->getId() );
|
||||
auto pSession = serverMgr.getSession( player->getId() );
|
||||
//pPacketEntry->setValAt< uint32_t >( 0x08, player->getId() );
|
||||
if( pSession )
|
||||
pSession->getZoneConnection()->queueOutPacket( pPacketEntry );
|
||||
|
@ -345,14 +346,15 @@ void Sapphire::Territory::queuePacketForZone( Entity::Player& sourcePlayer,
|
|||
if( pTeriMgr->isPrivateTerritory( getTerritoryTypeId() ) )
|
||||
return;
|
||||
|
||||
auto pServerZone = m_pFw->get< World::ServerMgr >();
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
for( auto entry : m_playerMap )
|
||||
{
|
||||
auto player = entry.second;
|
||||
if( ( sourcePlayer.getId() != player->getId() ) ||
|
||||
( ( sourcePlayer.getId() == player->getId() ) && forSelf ) )
|
||||
{
|
||||
auto pSession = pServerZone->getSession( player->getId() );
|
||||
auto pSession = serverMgr.getSession( player->getId() );
|
||||
if( pSession )
|
||||
pSession->getZoneConnection()->queueOutPacket( pPacketEntry );
|
||||
}
|
||||
|
@ -874,9 +876,9 @@ void Sapphire::Territory::updateSpawnPoints()
|
|||
{
|
||||
if( !point->getLinkedBNpc() && ( Util::getTimeSeconds() - point->getTimeOfDeath() ) > 60 )
|
||||
{
|
||||
auto serverZone = m_pFw->get< World::ServerMgr >();
|
||||
auto& serverMgr = Common::Service< World::ServerMgr >::ref();
|
||||
|
||||
auto bNpcTemplate = serverZone->getBNpcTemplate( group.getTemplateId() );
|
||||
auto bNpcTemplate = serverMgr.getBNpcTemplate( group.getTemplateId() );
|
||||
|
||||
if( !bNpcTemplate )
|
||||
{
|
||||
|
|
|
@ -4,17 +4,21 @@
|
|||
#include <Framework.h>
|
||||
|
||||
#include <Util/CrashHandler.h>
|
||||
#include <Service.h>
|
||||
|
||||
using namespace Sapphire;
|
||||
using namespace Sapphire::World;
|
||||
|
||||
[[maybe_unused]]
|
||||
Common::Util::CrashHandler crashHandler;
|
||||
|
||||
int main( int32_t argc, char* argv[] )
|
||||
{
|
||||
auto pFramework = make_Framework();
|
||||
auto pServer = std::make_shared< ServerMgr >( "world.ini", pFramework );
|
||||
pFramework->set< ServerMgr >( pServer );
|
||||
|
||||
Common::Service< ServerMgr >::set( pServer );
|
||||
|
||||
pServer->run( argc, argv );
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue