diff --git a/src/common/Config/ConfigMgr.cpp b/src/common/Config/ConfigMgr.cpp index 91f8ff42..1fdc9af0 100644 --- a/src/common/Config/ConfigMgr.cpp +++ b/src/common/Config/ConfigMgr.cpp @@ -3,6 +3,8 @@ #include #include +namespace fs = std::experimental::filesystem; + /** * Loads an ini file and parses it * @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 ) { // 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( - std::experimental::filesystem::path( configDir / configName ).string() ) ); + if( !fs::exists( configFile ) ) + { + copyDefaultConfig( configName ); + } + + m_pInih = std::unique_ptr< INIReader >( new INIReader( configFile.string() ) ); if( m_pInih->ParseError() < 0 ) return false; @@ -24,16 +30,16 @@ bool Core::ConfigMgr::loadConfig( 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; - if( !std::experimental::filesystem::exists( configPath.string() + m_configDefaultSuffix ) ) + if( !fs::exists( configPath.string() + m_configDefaultSuffix ) ) { // no default file :( return false; } - std::experimental::filesystem::copy_file( configPath.string() + m_configDefaultSuffix, configPath ); + fs::copy_file( configPath.string() + m_configDefaultSuffix, configPath ); return true; } diff --git a/src/common/Logging/Logger.cpp b/src/common/Logging/Logger.cpp index 96225ebd..22534330 100644 --- a/src/common/Logging/Logger.cpp +++ b/src/common/Logging/Logger.cpp @@ -6,67 +6,76 @@ #include // #include +#include // or #include + +namespace fs = std::experimental::filesystem; namespace Core { + Logger::Logger() + { -Logger::Logger() -{ - -} - -Logger::~Logger() -{ - -} - -void Logger::setLogPath( const std::string& logPath ) -{ - m_logFile = logPath; -} - -void Logger::init() -{ - spdlog::init_thread_pool( 8192, 1 ); - - 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 ); - - std::vector sinks { stdout_sink, daily_sink }; - - auto logger = std::make_shared< spdlog::async_logger >( "logger", sinks.begin(), sinks.end(), - spdlog::thread_pool(), spdlog::async_overflow_policy::block ); - - - spdlog::register_logger( logger ); - 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 - // 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::flush_on( spdlog::level::critical ); -} - -void Logger::error( const std::string& text ) -{ - spdlog::get( "logger" )->error( text ); -} - -void Logger::info( const std::string& text ) -{ - spdlog::get( "logger" )->info( text ); -} - -void Logger::debug( const std::string& text ) -{ - spdlog::get( "logger" )->debug( text ); -} - -void Logger::fatal( const std::string& text ) -{ - spdlog::get( "logger" )->critical( text ); -} - + } + + Logger::~Logger() + { + + } + + void Logger::setLogPath( const std::string& logPath ) + { + auto pos = logPath.find_last_of( '/' ); + + if( pos != std::string::npos ) + { + std::string realPath = logPath.substr( 0, pos ); + fs::create_directories( realPath ); + } + + m_logFile = logPath; + } + + void Logger::init() + { + spdlog::init_thread_pool( 8192, 1 ); + + 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 ); + + std::vector< spdlog::sink_ptr > sinks { stdout_sink, daily_sink }; + + auto logger = std::make_shared< spdlog::async_logger >( "logger", sinks.begin(), sinks.end(), + spdlog::thread_pool(), spdlog::async_overflow_policy::block ); + + + spdlog::register_logger( logger ); + 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 + // 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::flush_on( spdlog::level::critical ); + } + + void Logger::error( const std::string& text ) + { + spdlog::get( "logger" )->error( text ); + } + + void Logger::info( const std::string& text ) + { + spdlog::get( "logger" )->info( text ); + } + + void Logger::debug( const std::string& text ) + { + spdlog::get( "logger" )->debug( text ); + } + + void Logger::fatal( const std::string& text ) + { + spdlog::get( "logger" )->critical( text ); + } } diff --git a/src/servers/sapphire_api/SapphireAPI.cpp b/src/servers/sapphire_api/SapphireAPI.cpp index 33602b13..1f981514 100644 --- a/src/servers/sapphire_api/SapphireAPI.cpp +++ b/src/servers/sapphire_api/SapphireAPI.cpp @@ -133,13 +133,16 @@ Core::Network::SapphireAPI::createCharacter( const int& accountId, const std::st 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() ) - tmpVector2.push_back( v.get< int >() ); + if( !v.empty() && !v.is_array() ) + tmpVector2.push_back( std::stoi( std::string( v ) ) ); } // leaving this in for now for reference diff --git a/src/servers/sapphire_api/main.cpp b/src/servers/sapphire_api/main.cpp index 5d627b64..90edbd05 100644 --- a/src/servers/sapphire_api/main.cpp +++ b/src/servers/sapphire_api/main.cpp @@ -488,9 +488,7 @@ void checkSession( shared_ptr< HttpServer::Response > response, shared_ptr< Http else { std::string json_string = nlohmann::json( { - { "result", result }, - { "result2", "penis" }, - { "result3", "wtf" } + { "result", result } } ).dump() ; *response << buildHttpResponse( 200, json_string, JSON ); diff --git a/src/servers/sapphire_lobby/RestConnector.cpp b/src/servers/sapphire_lobby/RestConnector.cpp index d17fe938..96ac9c6f 100644 --- a/src/servers/sapphire_lobby/RestConnector.cpp +++ b/src/servers/sapphire_lobby/RestConnector.cpp @@ -143,7 +143,7 @@ uint32_t Core::Network::RestConnector::getNextCharId() if( content.find( "invalid" ) == std::string::npos ) { - return json["result"].get< uint32_t >(); + return std::stoi( std::string( json["result"] ) ); } else { @@ -182,7 +182,7 @@ uint64_t Core::Network::RestConnector::getNextContentId() if( content.find( "invalid" ) == std::string::npos ) { - return json["result"].get< uint64_t >(); + return std::stoll( std::string( json["result"] ) ); } else { @@ -313,7 +313,7 @@ int Core::Network::RestConnector::createCharacter( char* sId, std::string name, } if( content.find( "invalid" ) == std::string::npos ) - return json["result"].get< int >(); + return std::stoi( json["result"].get< std::string >() ); return -1; } else diff --git a/src/servers/sapphire_zone/Session.cpp b/src/servers/sapphire_zone/Session.cpp index 66e0b06b..3d5070de 100644 --- a/src/servers/sapphire_zone/Session.cpp +++ b/src/servers/sapphire_zone/Session.cpp @@ -77,8 +77,12 @@ void Core::Session::close() // remove the session from the player if( m_pPlayer ) + { + // do one last update to db + m_pPlayer->updateSql(); // reset the zone, so the zone handler knows to remove the actor m_pPlayer->setCurrentZone( nullptr ); + } } uint32_t Core::Session::getId() const diff --git a/src/servers/sapphire_zone/mainGameServer.cpp b/src/servers/sapphire_zone/mainGameServer.cpp index b45e71b0..f9a07c4a 100644 --- a/src/servers/sapphire_zone/mainGameServer.cpp +++ b/src/servers/sapphire_zone/mainGameServer.cpp @@ -29,7 +29,7 @@ bool setupFramework() auto pDebugCom = std::make_shared< DebugCommandHandler >(); auto pConfig = std::make_shared< ConfigMgr >(); - pLogger->setLogPath( "log/SapphireZone_" ); + pLogger->setLogPath( "log/SapphireZone" ); pLogger->init(); g_fw.set< ServerZone >( pServer );