1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 14:57:44 +00:00

Merge remote-tracking branch 'origin/develop' into housing

This commit is contained in:
mordred 2018-11-09 11:10:34 +01:00
commit e1f58a9875
7 changed files with 94 additions and 74 deletions

View file

@ -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;
} }

View file

@ -6,11 +6,13 @@
#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()
{ {
@ -23,6 +25,14 @@ Logger::~Logger()
void Logger::setLogPath( const std::string& logPath ) 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; m_logFile = logPath;
} }
@ -68,5 +78,4 @@ void Logger::fatal( const std::string& text )
spdlog::get( "logger" )->critical( text ); spdlog::get( "logger" )->critical( text );
} }
} }

View file

@ -132,14 +132,17 @@ Core::Network::SapphireAPI::createCharacter( const int& accountId, const std::st
std::vector< int32_t > tmpVector2; std::vector< int32_t > tmpVector2;
for( auto& v : json["content"] ) for( auto& v : json["content"] )
{
if( v.is_array() )
{ {
for( auto& vs : v ) for( auto& vs : v )
{ {
tmpVector.push_back( vs.get< int >() ); 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

View file

@ -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 );

View file

@ -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

View file

@ -77,9 +77,13 @@ 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
{ {

View file

@ -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 );