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 <experimental/filesystem>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -6,67 +6,76 @@
|
|||
#include <spdlog/sinks/daily_file_sink.h>
|
||||
|
||||
// #include <iostream>
|
||||
#include <experimental/filesystem> // or #include <filesystem>
|
||||
|
||||
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<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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Add table
Reference in a new issue