1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-25 05:57:45 +00:00

Merge pull request #505 from NotAdam/develop

add customisable log level to config
This commit is contained in:
Mordred 2019-01-25 14:52:25 +01:00 committed by GitHub
commit 9b518e84e4
13 changed files with 62 additions and 21 deletions

View file

@ -12,6 +12,8 @@ ServerSecret = default
DataPath = C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack DataPath = C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack
WorldID = 67 WorldID = 67
DefaultGMRank = 255 DefaultGMRank = 255
LogLevel = 1
LogFilter = 0
[Network] [Network]
; Values definining how Users and other servers will access - these have to be set to your public IP when running a public server ; Values definining how Users and other servers will access - these have to be set to your public IP when running a public server

View file

@ -713,6 +713,8 @@ int main( int argc, char* argv[] )
if( !loadSettings( argc, argv ) ) if( !loadSettings( argc, argv ) )
throw std::exception(); throw std::exception();
Logger::setLogLevel( m_config.global.general.logLevel );
server.resource[ "^/ZoneName/([0-9]+)$" ][ "GET" ] = &getZoneName; server.resource[ "^/ZoneName/([0-9]+)$" ][ "GET" ] = &getZoneName;
server.resource[ "^/sapphire-api/lobby/createAccount" ][ "POST" ] = &createAccount; server.resource[ "^/sapphire-api/lobby/createAccount" ][ "POST" ] = &createAccount;
server.resource[ "^/sapphire-api/lobby/login" ][ "POST" ] = &login; server.resource[ "^/sapphire-api/lobby/login" ][ "POST" ] = &login;

View file

@ -16,6 +16,8 @@ namespace Sapphire::Common::Config
uint16_t worldID; uint16_t worldID;
uint8_t defaultGMRank; uint8_t defaultGMRank;
uint8_t logLevel;
uint32_t logFilter;
} general; } general;
struct Network struct Network

View file

@ -57,6 +57,8 @@ bool Sapphire::ConfigMgr::loadGlobalConfig( Common::Config::GlobalConfig& config
config.general.serverSecret = getValue< std::string >( "General", "ServerSecret", "default" ); config.general.serverSecret = getValue< std::string >( "General", "ServerSecret", "default" );
config.general.worldID = getValue< uint16_t >( "General", "WorldID", 67 ); config.general.worldID = getValue< uint16_t >( "General", "WorldID", 67 );
config.general.defaultGMRank = getValue< uint8_t >( "General", "DefaultGMRank", 255 ); config.general.defaultGMRank = getValue< uint8_t >( "General", "DefaultGMRank", 255 );
config.general.logLevel = getValue< uint8_t >( "General", "LogLevel", 1 );
config.general.logFilter = getValue< uint32_t >( "General", "LogFilter", 0 );
// network // network
config.network.zoneHost = getValue< std::string >( "Network", "ZoneHost", "127.0.0.1" ); config.network.zoneHost = getValue< std::string >( "Network", "ZoneHost", "127.0.0.1" );

View file

@ -53,6 +53,11 @@ namespace Sapphire
spdlog::flush_on( spdlog::level::critical ); spdlog::flush_on( spdlog::level::critical );
} }
void Logger::setLogLevel( uint8_t logLevel )
{
spdlog::set_level( static_cast< spdlog::level::level_enum >( logLevel ) );
}
void Logger::error( const std::string& text ) void Logger::error( const std::string& text )
{ {
spdlog::get( "logger" )->error( text ); spdlog::get( "logger" )->error( text );

View file

@ -19,6 +19,7 @@ namespace Sapphire
public: public:
static void init( const std::string& logPath ); static void init( const std::string& logPath );
static void setLogLevel( uint8_t logLevel );
// todo: this is a minor increase in build time because of fmtlib, but much less than including spdlog directly // todo: this is a minor increase in build time because of fmtlib, but much less than including spdlog directly

View file

@ -63,6 +63,8 @@ namespace Sapphire
return; return;
} }
Logger::setLogLevel( m_config.global.general.logLevel );
auto pFw = std::make_shared< Framework >(); auto pFw = std::make_shared< Framework >();
Network::HivePtr hive( new Network::Hive() ); Network::HivePtr hive( new Network::Hive() );
Network::addServerToHive< Network::GameConnection >( m_ip, m_port, hive, pFw ); Network::addServerToHive< Network::GameConnection >( m_ip, m_port, hive, pFw );

View file

@ -10,10 +10,11 @@ Sapphire::World::Manager::NaviMgr::NaviMgr( FrameworkPtr pFw ) :
bool Sapphire::World::Manager::NaviMgr::setupTerritory( const std::string& bgPath ) bool Sapphire::World::Manager::NaviMgr::setupTerritory( const std::string& bgPath )
{ {
std::string bg; std::string bg = getBgName( bgPath );
auto findPos = bgPath.find_last_of( "/" );
if( findPos != std::string::npos ) // check if a provider exists already
bg = bgPath.substr( findPos + 1 ); if( m_naviProviderTerritoryMap.find( bg ) != m_naviProviderTerritoryMap.end() )
return true;
auto provider = Navi::make_NaviProvider( bg, m_pFw ); auto provider = Navi::make_NaviProvider( bg, m_pFw );
@ -28,13 +29,19 @@ bool Sapphire::World::Manager::NaviMgr::setupTerritory( const std::string& bgPat
Sapphire::World::Navi::NaviProviderPtr Sapphire::World::Manager::NaviMgr::getNaviProvider( const std::string& bgPath ) Sapphire::World::Navi::NaviProviderPtr Sapphire::World::Manager::NaviMgr::getNaviProvider( const std::string& bgPath )
{ {
std::string bg; std::string bg = getBgName( bgPath );
auto findPos = bgPath.find_last_of( "/" );
if( findPos != std::string::npos )
bg = bgPath.substr( findPos + 1 );
if( m_naviProviderTerritoryMap.find( bg ) != m_naviProviderTerritoryMap.end() ) if( m_naviProviderTerritoryMap.find( bg ) != m_naviProviderTerritoryMap.end() )
return m_naviProviderTerritoryMap[ bg ]; return m_naviProviderTerritoryMap[ bg ];
return nullptr; return nullptr;
} }
std::string Sapphire::World::Manager::NaviMgr::getBgName( const std::string& bgPath )
{
auto findPos = bgPath.find_last_of( "/" );
if( findPos != std::string::npos )
return bgPath.substr( findPos + 1 );
return "";
}

View file

@ -22,6 +22,8 @@ namespace Sapphire::World::Manager
private: private:
FrameworkPtr m_pFw; FrameworkPtr m_pFw;
std::string getBgName( const std::string& bgPath );
std::unordered_map< std::string, Navi::NaviProviderPtr > m_naviProviderTerritoryMap; std::unordered_map< std::string, Navi::NaviProviderPtr > m_naviProviderTerritoryMap;
}; };

View file

@ -36,7 +36,8 @@ bool Sapphire::World::Navi::NaviProvider::init()
{ {
auto baseMesh = meshFolder / std::experimental::filesystem::path( m_internalName + ".nav" ); auto baseMesh = meshFolder / std::experimental::filesystem::path( m_internalName + ".nav" );
loadMesh( baseMesh.string() ); if( !loadMesh( baseMesh.string() ) )
return false;
initQuery(); initQuery();
@ -376,11 +377,14 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 >
return resultCoords; return resultCoords;
} }
void Sapphire::World::Navi::NaviProvider::loadMesh( const std::string& path ) bool Sapphire::World::Navi::NaviProvider::loadMesh( const std::string& path )
{ {
FILE* fp = fopen( path.c_str(), "rb" ); FILE* fp = fopen( path.c_str(), "rb" );
if( !fp ) if( !fp )
throw std::runtime_error( "Could open navimesh file" ); {
Logger::error( "Couldn't open navimesh file: {0}", path );
return false;
}
// Read header. // Read header.
NavMeshSetHeader header; NavMeshSetHeader header;
@ -389,19 +393,22 @@ void Sapphire::World::Navi::NaviProvider::loadMesh( const std::string& path )
if( readLen != 1 ) if( readLen != 1 )
{ {
fclose( fp ); fclose( fp );
throw std::runtime_error( "Could not read NavMeshSetHeader" ); Logger::error( "Couldn't read NavMeshSetHeader for {0}", path );
return false;
} }
if( header.magic != NAVMESHSET_MAGIC ) if( header.magic != NAVMESHSET_MAGIC )
{ {
fclose( fp ); fclose( fp );
throw std::runtime_error( "Not a NavMeshSet" ); Logger::error( "'{0}' has an incorrect NavMeshSet header.", path );
return false;
} }
if( header.version != NAVMESHSET_VERSION ) if( header.version != NAVMESHSET_VERSION )
{ {
fclose( fp ); fclose( fp );
throw std::runtime_error( "Invalid NavMeshSet version" ); Logger::error( "'{0}' has an incorrect NavMeshSet version. Expected '{1}', got '{2}'", path, NAVMESHSET_VERSION, header.version );
return false;
} }
if( !m_naviMesh ) if( !m_naviMesh )
@ -410,14 +417,16 @@ void Sapphire::World::Navi::NaviProvider::loadMesh( const std::string& path )
if( !m_naviMesh ) if( !m_naviMesh )
{ {
fclose( fp ); fclose( fp );
throw std::runtime_error( "Could not allocate dtNavMesh" ); Logger::error( "Couldn't allocate dtNavMesh" );
return false;
} }
dtStatus status = m_naviMesh->init( &header.params ); dtStatus status = m_naviMesh->init( &header.params );
if( dtStatusFailed( status ) ) if( dtStatusFailed( status ) )
{ {
fclose( fp ); fclose( fp );
throw std::runtime_error( "Could not initialize dtNavMesh" ); Logger::error( "Couldn't initialise dtNavMesh" );
return false;
} }
} }
@ -429,13 +438,14 @@ void Sapphire::World::Navi::NaviProvider::loadMesh( const std::string& path )
if( readLen != 1 ) if( readLen != 1 )
{ {
fclose( fp ); fclose( fp );
throw std::runtime_error( "Could not read NavMeshTileHeader" ); Logger::error( "Couldn't read NavMeshTileHeader from '{0}'", path );
return false;
} }
if( !tileHeader.tileRef || !tileHeader.dataSize ) if( !tileHeader.tileRef || !tileHeader.dataSize )
break; break;
uint8_t* data = reinterpret_cast< uint8_t* >( dtAlloc( tileHeader.dataSize, DT_ALLOC_PERM ) ); auto data = reinterpret_cast< uint8_t* >( dtAlloc( tileHeader.dataSize, DT_ALLOC_PERM ) );
if( !data ) if( !data )
break; break;
memset( data, 0, tileHeader.dataSize ); memset( data, 0, tileHeader.dataSize );
@ -444,11 +454,15 @@ void Sapphire::World::Navi::NaviProvider::loadMesh( const std::string& path )
{ {
dtFree( data ); dtFree( data );
fclose( fp ); fclose( fp );
throw std::runtime_error( "Could not read tile data" );
Logger::error( "Couldn't read tile data from '{0}'", path );
return false;
} }
m_naviMesh->addTile( data, tileHeader.dataSize, DT_TILE_FREE_DATA, tileHeader.tileRef, 0 ); m_naviMesh->addTile( data, tileHeader.dataSize, DT_TILE_FREE_DATA, tileHeader.tileRef, 0 );
} }
fclose( fp ); fclose( fp );
return true;
} }

View file

@ -34,7 +34,7 @@ namespace Sapphire::World::Navi
explicit NaviProvider( const std::string& internalName, FrameworkPtr pFw ); explicit NaviProvider( const std::string& internalName, FrameworkPtr pFw );
bool init(); bool init();
void loadMesh( const std::string& path ); bool loadMesh( const std::string& path );
void initQuery(); void initQuery();
void toDetourPos( const Common::FFXIVARR_POSITION3& position, float* out ); void toDetourPos( const Common::FFXIVARR_POSITION3& position, float* out );

View file

@ -53,7 +53,7 @@ bool Sapphire::Scripting::ScriptMgr::init()
if( !status ) if( !status )
{ {
Logger::error( "ScriptMgr: failed to load scripts, the server will not function correctly without scripts loaded." ); Logger::error( "ScriptMgr: failed to load modules, the server will not function correctly without scripts loaded." );
return false; return false;
} }

View file

@ -129,6 +129,8 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] )
return; return;
} }
Logger::setLogLevel( m_config.global.general.logLevel );
Logger::info( "Setting up generated EXD data" ); Logger::info( "Setting up generated EXD data" );
auto pExdData = std::make_shared< Data::ExdDataGenerated >(); auto pExdData = std::make_shared< Data::ExdDataGenerated >();
auto dataPath = m_config.global.general.dataPath; auto dataPath = m_config.global.general.dataPath;