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

move all the old config calls to the new config object

This commit is contained in:
NotAdam 2019-01-07 00:03:48 +11:00
parent 3349ccce42
commit 092b343114
7 changed files with 60 additions and 69 deletions

View file

@ -77,6 +77,8 @@ bool loadSettings( int32_t argc, char* argv[] )
return false;
}
auto pConfig = m_pConfig->getConfig();
std::vector< std::string > args( argv + 1, argv + argc );
for( size_t i = 0; i + 1 < args.size(); i += 2 )
{
@ -140,7 +142,7 @@ bool loadSettings( int32_t argc, char* argv[] )
}
Logger::info( "Setting up generated EXD data" );
auto dataPath = m_pConfig->getValue< std::string >( "GlobalParameters", "DataPath", "" );
auto dataPath = m_pConfig->getConfig()->globalParameters.dataPath;
if( !g_exdDataGen.init( dataPath ) )
{
Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in config.ini" );
@ -151,21 +153,20 @@ bool loadSettings( int32_t argc, char* argv[] )
Sapphire::Db::DbLoader loader;
Sapphire::Db::ConnectionInfo info;
info.password = m_pConfig->getValue< std::string >( "Database", "Password", "" );
info.host = m_pConfig->getValue< std::string >( "Database", "Host", "127.0.0.1" );
info.database = m_pConfig->getValue< std::string >( "Database", "Database", "sapphire" );
info.port = m_pConfig->getValue< uint16_t >( "Database", "Port", 3306 );
info.user = m_pConfig->getValue< std::string >( "Database", "Username", "root" );
info.syncThreads = m_pConfig->getValue< uint8_t >( "Database", "SyncThreads", 2 );
info.asyncThreads = m_pConfig->getValue< uint8_t >( "Database", "AsyncThreads", 2 );
info.password = pConfig->database.password;
info.host = pConfig->database.host;
info.database = pConfig->database.database;
info.port = pConfig->database.port;
info.user = pConfig->database.username;
info.syncThreads = pConfig->database.syncThreads;
info.asyncThreads = pConfig->database.asyncThreads;
loader.addDb( g_charaDb, info );
if( !loader.initDbs() )
return false;
server.config.port = static_cast< uint16_t >( std::stoul(
m_pConfig->getValue< std::string >( "RestNetwork", "ListenPort", "80" ) ) );
server.config.address = m_pConfig->getValue< std::string >( "RestNetwork", "ListenIp", "0.0.0.0" );
server.config.port = pConfig->restNetwork.listenPort;
server.config.address = pConfig->restNetwork.listenIP;
Logger::info( "Database: Connected to {0}:{1}", info.host, info.port );
@ -267,9 +268,9 @@ void createAccount( shared_ptr< HttpServer::Response > response, shared_ptr< Htt
// todo: construct proper json object here
std::string json_string = "{\"sId\":\"" + sId +
"\", \"lobbyHost\":\"" +
m_pConfig->getValue< std::string >( "GlobalNetwork", "LobbyHost" ) +
m_pConfig->getConfig()->globalNetwork.lobbyHost +
"\", \"frontierHost\":\"" +
m_pConfig->getValue< std::string >( "GlobalNetwork", "RestHost" ) + "\"}";
m_pConfig->getConfig()->globalNetwork.restHost + "\"}";
*response << buildHttpResponse( 200, json_string, JSON );
}
else
@ -300,9 +301,9 @@ void login( shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer:
// todo: build proper json object and stringify it
std::string json_string = "{\"sId\":\"" + sId +
"\", \"lobbyHost\":\"" +
m_pConfig->getValue< std::string >( "GlobalNetwork", "LobbyHost" ) +
m_pConfig->getConfig()->globalNetwork.lobbyHost +
"\", \"frontierHost\":\"" +
m_pConfig->getValue< std::string >( "GlobalNetwork", "RestHost" ) + "\"}";
m_pConfig->getConfig()->globalNetwork.restHost + "\"}";
*response << buildHttpResponse( 200, json_string, JSON );
}
else
@ -332,7 +333,7 @@ void deleteCharacter( shared_ptr< HttpServer::Response > response, shared_ptr< H
int32_t accountId = g_sapphireAPI.checkSession( sId );
if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret )
if( m_pConfig->getConfig()->globalParameters.serverSecret != secret )
{
std::string json_string = "{\"result\":\"invalid_secret\"}";
*response << buildHttpResponse( 403, json_string, JSON );
@ -372,15 +373,15 @@ void createCharacter( shared_ptr< HttpServer::Response > response, shared_ptr< H
if( result != -1 )
{
if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret )
if( m_pConfig->getConfig()->globalParameters.serverSecret != secret )
{
std::string json_string = "{\"result\":\"invalid_secret\"}";
*response << buildHttpResponse( 403, json_string, JSON );
}
else
{
int32_t charId = g_sapphireAPI.createCharacter( result, name, finalJson, m_pConfig->getValue< uint8_t >(
"CharacterCreation", "DefaultGMRank", 255 ) );
int32_t charId = g_sapphireAPI.createCharacter( result, name, finalJson,
m_pConfig->getConfig()->characterCreation.defaultGMRank );
std::string json_string = "{\"result\":\"" + std::to_string( charId ) + "\"}";
*response << buildHttpResponse( 200, json_string, JSON );
@ -413,7 +414,7 @@ void insertSession( shared_ptr< HttpServer::Response > response, shared_ptr< Htt
std::string secret = json["secret"];
// reloadConfig();
if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret )
if( m_pConfig->getConfig()->globalParameters.serverSecret != secret )
{
std::string json_string = "{\"result\":\"invalid_secret\"}";
*response << buildHttpResponse( 403, json_string, JSON );
@ -445,7 +446,7 @@ void checkNameTaken( shared_ptr< HttpServer::Response > response, shared_ptr< Ht
// reloadConfig();
if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret )
if( m_pConfig->getConfig()->globalParameters.serverSecret != secret )
{
std::string json_string = "{\"result\":\"invalid_secret\"}";
*response << buildHttpResponse( 403, json_string, JSON );
@ -482,7 +483,7 @@ void checkSession( shared_ptr< HttpServer::Response > response, shared_ptr< Http
if( result != -1 )
{
if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret )
if( m_pConfig->getConfig()->globalParameters.serverSecret != secret )
{
std::string json_string = "{\"result\":\"invalid_secret\"}";
*response << buildHttpResponse( 403, json_string, JSON );
@ -521,7 +522,7 @@ void getNextCharId( shared_ptr< HttpServer::Response > response, shared_ptr< Htt
// reloadConfig();
if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret )
if( m_pConfig->getConfig()->globalParameters.serverSecret != secret )
{
std::string json_string = "{\"result\":\"invalid_secret\"}";
*response << buildHttpResponse( 403, json_string, JSON );
@ -552,7 +553,7 @@ void getNextContentId( shared_ptr< HttpServer::Response > response, shared_ptr<
// reloadConfig();
if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret )
if( m_pConfig->getConfig()->globalParameters.serverSecret != secret )
{
std::string json_string = "{\"result\":\"invalid_secret\"}";
*response << buildHttpResponse( 403, json_string, JSON );
@ -587,7 +588,7 @@ void getCharacterList( shared_ptr< HttpServer::Response > response, shared_ptr<
if( result != -1 )
{
if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret )
if( m_pConfig->getConfig()->globalParameters.serverSecret != secret )
{
std::string json_string = "{\"result\":\"invalid_secret\"}";
*response << buildHttpResponse( 403, json_string, JSON );
@ -767,8 +768,8 @@ int main( int argc, char* argv[] )
server.start();
} );
Logger::info( "API server running on {0}:{1}", m_pConfig->getValue< std::string >( "RestNetwork", "ListenIp", "0.0.0.0" ),
m_pConfig->getValue< std::string >( "RestNetwork", "ListenPort", "80" ) );
auto& cfg = m_pConfig->getConfig()->restNetwork;
Logger::info( "API server running on {0}:{1}", cfg.listenIP, cfg.listenPort );
//Wait for server to start so that the client can connect
this_thread::sleep_for( chrono::seconds( 1 ) );

View file

@ -128,11 +128,10 @@ void Sapphire::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet
serverListPacket->data().seq = 1;
serverListPacket->data().offset = 0;
serverListPacket->data().numServers = 1;
serverListPacket->data().server[ 0 ].id = g_serverLobby.getConfig()->getValue< uint16_t >( "Lobby", "WorldID", 1 );
serverListPacket->data().server[ 0 ].id = g_serverLobby.getConfig()->getConfig()->lobby.worldID;
serverListPacket->data().server[ 0 ].index = 0;
serverListPacket->data().final = 1;
strcpy( serverListPacket->data().server[ 0 ].name,
g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() );
strcpy( serverListPacket->data().server[ 0 ].name, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() );
pRP.addPacket( serverListPacket );
auto retainerListPacket = makeLobbyPacket< FFXIVIpcRetainerList >( tmpId );
@ -162,15 +161,13 @@ void Sapphire::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet
auto& charEntry = charList[ charIndex ];
details.uniqueId = std::get< 1 >( charEntry );
details.contentId = std::get< 2 >( charEntry );
details.serverId = g_serverLobby.getConfig()->getValue< uint16_t >( "Lobby", "WorldID", 1 );
details.serverId1 = g_serverLobby.getConfig()->getValue< uint16_t >( "Lobby", "WorldID", 1 );
details.serverId = g_serverLobby.getConfig()->getConfig()->lobby.worldID;
details.serverId1 = g_serverLobby.getConfig()->getConfig()->lobby.worldID;
details.index = charIndex;
strcpy( details.charDetailJson, std::get< 3 >( charEntry ).c_str() );
strcpy( details.nameChara, std::get< 0 >( charEntry ).c_str() );
strcpy( details.nameServer,
g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() );
strcpy( details.nameServer1,
g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() );
strcpy( details.nameServer, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() );
strcpy( details.nameServer1, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() );
charListPacket->data().charaDetails[ j ] = details;
@ -236,9 +233,8 @@ void Sapphire::Network::GameConnection::enterWorld( FFXIVARR_PACKET_RAW& packet,
auto enterWorldPacket = makeLobbyPacket< FFXIVIpcEnterWorld >( tmpId );
enterWorldPacket->data().contentId = lookupId;
enterWorldPacket->data().seq = sequence;
strcpy( enterWorldPacket->data().host,
g_serverLobby.getConfig()->getValue< std::string >( "GlobalNetwork", "ZoneHost" ).c_str() );
enterWorldPacket->data().port = g_serverLobby.getConfig()->getValue< uint16_t >( "GlobalNetwork", "ZonePort" );
strcpy( enterWorldPacket->data().host, g_serverLobby.getConfig()->getConfig()->globalNetwork.zoneHost.c_str() );
enterWorldPacket->data().port = g_serverLobby.getConfig()->getConfig()->globalNetwork.zonePort;
enterWorldPacket->data().charId = logInCharId;
memcpy( enterWorldPacket->data().sid, m_pSession->getSessionId(), 66 );
pRP.addPacket( enterWorldPacket );
@ -249,7 +245,7 @@ bool Sapphire::Network::GameConnection::sendServiceAccountList( FFXIVARR_PACKET_
{
LobbySessionPtr pSession = g_serverLobby.getSession( ( char* ) &packet.data[ 0 ] + 0x20 );
if( g_serverLobby.getConfig()->getValue< bool >( "Lobby", "AllowNoSessionConnect" ) && pSession == nullptr )
if( g_serverLobby.getConfig()->getConfig()->lobby.allowNoSessionConnect && pSession == nullptr )
{
auto session = make_LobbySession();
session->setAccountID( 0 );
@ -316,8 +312,7 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW&
auto charCreatePacket = makeLobbyPacket< FFXIVIpcCharCreate >( tmpId );
charCreatePacket->data().content_id = newContentId;
strcpy( charCreatePacket->data().name, name.c_str() );
strcpy( charCreatePacket->data().world,
g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() );
strcpy( charCreatePacket->data().world, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() );
charCreatePacket->data().type = 1;
charCreatePacket->data().seq = sequence;
charCreatePacket->data().unknown = 1;
@ -340,10 +335,8 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW&
auto charCreatePacket = makeLobbyPacket< FFXIVIpcCharCreate >( tmpId );
charCreatePacket->data().content_id = newContentId;
strcpy( charCreatePacket->data().name, name.c_str() );
strcpy( charCreatePacket->data().world,
g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() );
strcpy( charCreatePacket->data().world2,
g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() );
strcpy( charCreatePacket->data().world, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() );
strcpy( charCreatePacket->data().world2, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() );
charCreatePacket->data().type = 2;
charCreatePacket->data().seq = sequence;
charCreatePacket->data().unknown = 1;
@ -371,8 +364,7 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW&
//charCreatePacket->data().content_id = deletePlayer.getContentId();
charCreatePacket->data().content_id = 0;
strcpy( charCreatePacket->data().name, name.c_str() );
strcpy( charCreatePacket->data().world,
g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() );
strcpy( charCreatePacket->data().world, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() );
charCreatePacket->data().type = 4;
charCreatePacket->data().seq = sequence;
charCreatePacket->data().unknown = 1;

View file

@ -67,9 +67,7 @@ namespace Sapphire
Network::HivePtr hive( new Network::Hive() );
Network::addServerToHive< Network::GameConnection >( m_ip, m_port, hive, pFw );
Logger::info(
"Lobby server running on " + m_pConfig->getValue< std::string >( "LobbyNetwork", "ListenIp", "0.0.0.0" ) + ":" +
m_pConfig->getValue< std::string >( "LobbyNetwork", "ListenPort", "80" ) );
Logger::info( "Lobby server running on {0}:{1}", m_ip, m_port );
std::vector< std::thread > threadGroup;
@ -108,19 +106,19 @@ namespace Sapphire
if( arg == "ip" )
{
// todo: ip addr in config
m_pConfig->setValue< std::string >( "LobbyNetwork.ListenIp", val );
m_pConfig->getConfig()->lobbyNetwork.listenIp = val;
}
else if( arg == "p" || arg == "port" )
{
m_pConfig->setValue< std::string >( "LobbyNetwork.LobbyPort", val );
m_pConfig->getConfig()->lobbyNetwork.listenPort = std::stoi( val );
}
else if( arg == "worldip" || arg == "worldip" )
{
m_pConfig->setValue< std::string >( "GlobalNetwork.ZoneHost", val );
m_pConfig->getConfig()->globalNetwork.zoneHost = val;
}
else if( arg == "worldport" )
{
m_pConfig->setValue< std::string >( "GlobalNetwork.ZonePort", val );
m_pConfig->getConfig()->globalNetwork.zonePort = std::stoi( val );
}
}
catch( ... )
@ -130,12 +128,13 @@ namespace Sapphire
}
}
m_port = m_pConfig->getValue< uint16_t >( "LobbyNetwork", "ListenPort", 54994 );
m_ip = m_pConfig->getValue< std::string >( "LobbyNetwork", "ListenIp", "0.0.0.0" );
m_port = m_pConfig->getConfig()->lobbyNetwork.listenPort;
m_ip = m_pConfig->getConfig()->lobbyNetwork.listenIp;
g_restConnector.restHost = m_pConfig->getValue< std::string >( "GlobalNetwork", "RestHost" ) + ":" +
m_pConfig->getValue< std::string >( "GlobalNetwork", "RestPort" );
g_restConnector.serverSecret = m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" );
g_restConnector.restHost = m_pConfig->getConfig()->globalNetwork.restHost + ":" +
std::to_string( m_pConfig->getConfig()->globalNetwork.restPort );
g_restConnector.serverSecret = m_pConfig->getConfig()->globalParameters.serverSecret;
return true;
}

View file

@ -327,7 +327,7 @@ void Sapphire::Entity::Player::eventItemActionStart( uint32_t eventId,
void Sapphire::Entity::Player::onLogin()
{
auto pConfig = m_pFw->get< ConfigMgr >();
auto motd = pConfig->getValue< std::string >( "General", "MotD", "" );
auto motd = pConfig->getConfig()->general.motd;
std::istringstream ss( motd );
std::string msg;

View file

@ -125,7 +125,7 @@ namespace Sapphire::Scripting
World::Manager::BaseManager( pFw )
{
auto pConfig = framework()->get< ConfigMgr >();
m_loader.setCachePath( pConfig->getValue< std::string >( "Scripts", "CachePath", "./cache/" ) );
m_loader.setCachePath( pConfig->getConfig()->scripts.cachePath );
}

View file

@ -50,8 +50,7 @@ bool Sapphire::Scripting::ScriptMgr::init()
std::set< std::string > files;
auto pConfig = framework()->get< ConfigMgr >();
auto status = loadDir( pConfig->getValue< std::string >( "Scripts", "Path", "./compiledscripts/" ),
files, m_nativeScriptMgr->getModuleExtension() );
auto status = loadDir( pConfig->getConfig()->scripts.path, files, m_nativeScriptMgr->getModuleExtension() );
if( !status )
{
@ -82,11 +81,11 @@ bool Sapphire::Scripting::ScriptMgr::init()
void Sapphire::Scripting::ScriptMgr::watchDirectories()
{
auto pConfig = framework()->get< ConfigMgr >();
auto shouldWatch = pConfig->getValue< bool >( "Scripts", "HotSwap", true );
auto shouldWatch = pConfig->getConfig()->scripts.hotSwap;
if( !shouldWatch )
return;
Watchdog::watchMany( pConfig->getValue< std::string >( "Scripts", "Path", "./compiledscripts/" ) + "*" +
Watchdog::watchMany( pConfig->getConfig()->scripts.path + "*" +
m_nativeScriptMgr->getModuleExtension(),
[ this ]( const std::vector< ci::fs::path >& paths )
{

View file

@ -74,8 +74,8 @@ bool Sapphire::World::ServerMgr::loadSettings( int32_t argc, char* argv[] )
return false;
}
m_port = pConfig->getValue< uint16_t >( "ZoneNetwork", "ListenPort", 54992 );
m_ip = pConfig->getValue< std::string >( "ZoneNetwork", "ListenIp", "0.0.0.0" );
m_port = pConfig->getConfig()->zoneNetwork.listenPort;
m_ip = pConfig->getConfig()->zoneNetwork.listenIp;
return true;
}
@ -99,7 +99,7 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] )
Logger::info( "Setting up generated EXD data" );
auto pExdData = std::make_shared< Data::ExdDataGenerated >();
auto dataPath = pConfig->getValue< std::string >( "GlobalParameters", "DataPath", "" );
auto dataPath = pConfig->getConfig()->globalParameters.dataPath;
if( !pExdData->init( dataPath ) )
{
Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in config.ini" );