mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-27 06:47:45 +00:00
Merge remote-tracking branch 'origin/develop' into housing
This commit is contained in:
commit
e1f58a9875
7 changed files with 94 additions and 74 deletions
|
@ -3,6 +3,8 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <experimental/filesystem>
|
#include <experimental/filesystem>
|
||||||
|
|
||||||
|
namespace fs = std::experimental::filesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an ini file and parses it
|
* Loads an ini file and parses it
|
||||||
* @param configName the name of ini file relative to m_configFolderRoot to load alongside global.ini
|
* @param configName the name of ini file relative to m_configFolderRoot to load alongside global.ini
|
||||||
|
@ -11,10 +13,14 @@
|
||||||
bool Core::ConfigMgr::loadConfig( const std::string& configName )
|
bool Core::ConfigMgr::loadConfig( const std::string& configName )
|
||||||
{
|
{
|
||||||
// get global config
|
// get global config
|
||||||
auto configDir = std::experimental::filesystem::path( m_configFolderRoot );
|
auto configFile = fs::path( fs::path( m_configFolderRoot ) / configName );
|
||||||
|
|
||||||
m_pInih = std::unique_ptr< INIReader >( new INIReader(
|
if( !fs::exists( configFile ) )
|
||||||
std::experimental::filesystem::path( configDir / configName ).string() ) );
|
{
|
||||||
|
copyDefaultConfig( configName );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pInih = std::unique_ptr< INIReader >( new INIReader( configFile.string() ) );
|
||||||
|
|
||||||
if( m_pInih->ParseError() < 0 )
|
if( m_pInih->ParseError() < 0 )
|
||||||
return false;
|
return false;
|
||||||
|
@ -24,16 +30,16 @@ bool Core::ConfigMgr::loadConfig( const std::string& configName )
|
||||||
|
|
||||||
bool Core::ConfigMgr::copyDefaultConfig( const std::string& configName )
|
bool Core::ConfigMgr::copyDefaultConfig( const std::string& configName )
|
||||||
{
|
{
|
||||||
std::experimental::filesystem::path configPath( m_configFolderRoot );
|
fs::path configPath( m_configFolderRoot );
|
||||||
configPath /= configName;
|
configPath /= configName;
|
||||||
|
|
||||||
if( !std::experimental::filesystem::exists( configPath.string() + m_configDefaultSuffix ) )
|
if( !fs::exists( configPath.string() + m_configDefaultSuffix ) )
|
||||||
{
|
{
|
||||||
// no default file :(
|
// no default file :(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::experimental::filesystem::copy_file( configPath.string() + m_configDefaultSuffix, configPath );
|
fs::copy_file( configPath.string() + m_configDefaultSuffix, configPath );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,67 +6,76 @@
|
||||||
#include <spdlog/sinks/daily_file_sink.h>
|
#include <spdlog/sinks/daily_file_sink.h>
|
||||||
|
|
||||||
// #include <iostream>
|
// #include <iostream>
|
||||||
|
#include <experimental/filesystem> // or #include <filesystem>
|
||||||
|
|
||||||
|
namespace fs = std::experimental::filesystem;
|
||||||
|
|
||||||
namespace Core
|
namespace Core
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Logger::Logger()
|
||||||
|
{
|
||||||
|
|
||||||
Logger::Logger()
|
}
|
||||||
{
|
|
||||||
|
Logger::~Logger()
|
||||||
}
|
{
|
||||||
|
|
||||||
Logger::~Logger()
|
}
|
||||||
{
|
|
||||||
|
void Logger::setLogPath( const std::string& logPath )
|
||||||
}
|
{
|
||||||
|
auto pos = logPath.find_last_of( '/' );
|
||||||
void Logger::setLogPath( const std::string& logPath )
|
|
||||||
{
|
if( pos != std::string::npos )
|
||||||
m_logFile = logPath;
|
{
|
||||||
}
|
std::string realPath = logPath.substr( 0, pos );
|
||||||
|
fs::create_directories( realPath );
|
||||||
void Logger::init()
|
}
|
||||||
{
|
|
||||||
spdlog::init_thread_pool( 8192, 1 );
|
m_logFile = logPath;
|
||||||
|
}
|
||||||
auto stdout_sink = std::make_shared< spdlog::sinks::stdout_color_sink_mt >();
|
|
||||||
auto daily_sink = std::make_shared< spdlog::sinks::daily_file_sink_mt >( m_logFile + ".log", 0, 0 );
|
void Logger::init()
|
||||||
|
{
|
||||||
std::vector<spdlog::sink_ptr> sinks { stdout_sink, daily_sink };
|
spdlog::init_thread_pool( 8192, 1 );
|
||||||
|
|
||||||
auto logger = std::make_shared< spdlog::async_logger >( "logger", sinks.begin(), sinks.end(),
|
auto stdout_sink = std::make_shared< spdlog::sinks::stdout_color_sink_mt >();
|
||||||
spdlog::thread_pool(), spdlog::async_overflow_policy::block );
|
auto daily_sink = std::make_shared< spdlog::sinks::daily_file_sink_mt >( m_logFile + ".log", 0, 0 );
|
||||||
|
|
||||||
|
std::vector< spdlog::sink_ptr > sinks { stdout_sink, daily_sink };
|
||||||
spdlog::register_logger( logger );
|
|
||||||
spdlog::set_pattern( "[%H:%M:%S.%e] [%^%l%$] %v" );
|
auto logger = std::make_shared< spdlog::async_logger >( "logger", sinks.begin(), sinks.end(),
|
||||||
spdlog::set_level( spdlog::level::debug );
|
spdlog::thread_pool(), spdlog::async_overflow_policy::block );
|
||||||
// always flush the log on criticial messages, otherwise it's done by libc
|
|
||||||
// see: https://github.com/gabime/spdlog/wiki/7.-Flush-policy
|
|
||||||
// nb: if the server crashes, log data can be missing from the file unless something logs critical just before it does
|
spdlog::register_logger( logger );
|
||||||
spdlog::flush_on( spdlog::level::critical );
|
spdlog::set_pattern( "[%H:%M:%S.%e] [%^%l%$] %v" );
|
||||||
}
|
spdlog::set_level( spdlog::level::debug );
|
||||||
|
// always flush the log on criticial messages, otherwise it's done by libc
|
||||||
void Logger::error( const std::string& text )
|
// see: https://github.com/gabime/spdlog/wiki/7.-Flush-policy
|
||||||
{
|
// nb: if the server crashes, log data can be missing from the file unless something logs critical just before it does
|
||||||
spdlog::get( "logger" )->error( text );
|
spdlog::flush_on( spdlog::level::critical );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::info( const std::string& text )
|
void Logger::error( const std::string& text )
|
||||||
{
|
{
|
||||||
spdlog::get( "logger" )->info( text );
|
spdlog::get( "logger" )->error( text );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::debug( const std::string& text )
|
void Logger::info( const std::string& text )
|
||||||
{
|
{
|
||||||
spdlog::get( "logger" )->debug( text );
|
spdlog::get( "logger" )->info( text );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::fatal( const std::string& text )
|
void Logger::debug( const std::string& text )
|
||||||
{
|
{
|
||||||
spdlog::get( "logger" )->critical( text );
|
spdlog::get( "logger" )->debug( text );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Logger::fatal( const std::string& text )
|
||||||
|
{
|
||||||
|
spdlog::get( "logger" )->critical( text );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,13 +133,16 @@ Core::Network::SapphireAPI::createCharacter( const int& accountId, const std::st
|
||||||
|
|
||||||
for( auto& v : json["content"] )
|
for( auto& v : json["content"] )
|
||||||
{
|
{
|
||||||
for( auto& vs : v )
|
if( v.is_array() )
|
||||||
{
|
{
|
||||||
tmpVector.push_back( vs.get< int >() );
|
for( auto& vs : v )
|
||||||
|
{
|
||||||
|
tmpVector.push_back( std::stoi( std::string( vs ) ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !v.empty() )
|
if( !v.empty() && !v.is_array() )
|
||||||
tmpVector2.push_back( v.get< int >() );
|
tmpVector2.push_back( std::stoi( std::string( v ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// leaving this in for now for reference
|
// leaving this in for now for reference
|
||||||
|
|
|
@ -488,9 +488,7 @@ void checkSession( shared_ptr< HttpServer::Response > response, shared_ptr< Http
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::string json_string = nlohmann::json( {
|
std::string json_string = nlohmann::json( {
|
||||||
{ "result", result },
|
{ "result", result }
|
||||||
{ "result2", "penis" },
|
|
||||||
{ "result3", "wtf" }
|
|
||||||
} ).dump()
|
} ).dump()
|
||||||
;
|
;
|
||||||
*response << buildHttpResponse( 200, json_string, JSON );
|
*response << buildHttpResponse( 200, json_string, JSON );
|
||||||
|
|
|
@ -143,7 +143,7 @@ uint32_t Core::Network::RestConnector::getNextCharId()
|
||||||
|
|
||||||
if( content.find( "invalid" ) == std::string::npos )
|
if( content.find( "invalid" ) == std::string::npos )
|
||||||
{
|
{
|
||||||
return json["result"].get< uint32_t >();
|
return std::stoi( std::string( json["result"] ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -182,7 +182,7 @@ uint64_t Core::Network::RestConnector::getNextContentId()
|
||||||
|
|
||||||
if( content.find( "invalid" ) == std::string::npos )
|
if( content.find( "invalid" ) == std::string::npos )
|
||||||
{
|
{
|
||||||
return json["result"].get< uint64_t >();
|
return std::stoll( std::string( json["result"] ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -313,7 +313,7 @@ int Core::Network::RestConnector::createCharacter( char* sId, std::string name,
|
||||||
}
|
}
|
||||||
|
|
||||||
if( content.find( "invalid" ) == std::string::npos )
|
if( content.find( "invalid" ) == std::string::npos )
|
||||||
return json["result"].get< int >();
|
return std::stoi( json["result"].get< std::string >() );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -77,8 +77,12 @@ void Core::Session::close()
|
||||||
|
|
||||||
// remove the session from the player
|
// remove the session from the player
|
||||||
if( m_pPlayer )
|
if( m_pPlayer )
|
||||||
|
{
|
||||||
|
// do one last update to db
|
||||||
|
m_pPlayer->updateSql();
|
||||||
// reset the zone, so the zone handler knows to remove the actor
|
// reset the zone, so the zone handler knows to remove the actor
|
||||||
m_pPlayer->setCurrentZone( nullptr );
|
m_pPlayer->setCurrentZone( nullptr );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Core::Session::getId() const
|
uint32_t Core::Session::getId() const
|
||||||
|
|
|
@ -29,7 +29,7 @@ bool setupFramework()
|
||||||
auto pDebugCom = std::make_shared< DebugCommandHandler >();
|
auto pDebugCom = std::make_shared< DebugCommandHandler >();
|
||||||
auto pConfig = std::make_shared< ConfigMgr >();
|
auto pConfig = std::make_shared< ConfigMgr >();
|
||||||
|
|
||||||
pLogger->setLogPath( "log/SapphireZone_" );
|
pLogger->setLogPath( "log/SapphireZone" );
|
||||||
pLogger->init();
|
pLogger->init();
|
||||||
|
|
||||||
g_fw.set< ServerZone >( pServer );
|
g_fw.set< ServerZone >( pServer );
|
||||||
|
|
Loading…
Add table
Reference in a new issue