2018-06-10 16:28:03 +00:00
|
|
|
#include "ConfigMgr.h"
|
2018-10-24 23:02:30 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <experimental/filesystem>
|
2018-06-10 16:28:03 +00:00
|
|
|
|
2018-11-06 18:35:02 +11:00
|
|
|
namespace fs = std::experimental::filesystem;
|
|
|
|
|
2018-06-10 16:28:03 +00:00
|
|
|
/**
|
|
|
|
* Loads an ini file and parses it
|
|
|
|
* @param configName the name of ini file relative to m_configFolderRoot to load alongside global.ini
|
|
|
|
* @return true if loading was successful
|
|
|
|
*/
|
2018-11-29 16:55:48 +01:00
|
|
|
bool Sapphire::ConfigMgr::loadConfig( const std::string& configName )
|
2018-06-10 16:28:03 +00:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
// get global config
|
2018-11-06 18:35:02 +11:00
|
|
|
auto configFile = fs::path( fs::path( m_configFolderRoot ) / configName );
|
|
|
|
|
|
|
|
if( !fs::exists( configFile ) )
|
|
|
|
{
|
2018-12-18 21:40:44 +11:00
|
|
|
copyDefaultConfig( configName );
|
|
|
|
return false;
|
2018-11-06 18:35:02 +11:00
|
|
|
}
|
2018-06-10 16:28:03 +00:00
|
|
|
|
2018-11-06 18:35:02 +11:00
|
|
|
m_pInih = std::unique_ptr< INIReader >( new INIReader( configFile.string() ) );
|
2018-10-24 23:02:30 +02:00
|
|
|
|
|
|
|
if( m_pInih->ParseError() < 0 )
|
|
|
|
return false;
|
2018-06-10 16:28:03 +00:00
|
|
|
|
2019-01-06 23:39:30 +11:00
|
|
|
initConfigData();
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return true;
|
2018-06-10 16:28:03 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 22:11:52 +11:00
|
|
|
bool Sapphire::ConfigMgr::loadGlobalConfig( Common::Config::GlobalConfig& config, const string& configName )
|
|
|
|
{
|
|
|
|
auto configFile = fs::path( fs::path( m_configFolderRoot ) / configName );
|
|
|
|
|
|
|
|
if( !fs::exists( configFile ) )
|
|
|
|
{
|
|
|
|
copyDefaultConfig( configName );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pInih = std::make_unique< INIReader >( configFile.string() );
|
|
|
|
if( m_pInih->ParseError() < 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// database
|
|
|
|
config.database.host = getValue< std::string >( "Database", "Host", "127.0.0.1" );
|
|
|
|
config.database.port = getValue< uint16_t >( "Database", "Port", 3306 );
|
|
|
|
config.database.database = getValue< std::string >( "Database", "Database", "sapphire" );
|
|
|
|
config.database.username = getValue< std::string >( "Database", "Username", "sapphire" );
|
|
|
|
config.database.password = getValue< std::string >( "Database", "Password", "" );
|
|
|
|
config.database.syncThreads = getValue< uint8_t >( "Database", "SyncThreads", 2 );
|
|
|
|
config.database.asyncThreads = getValue< uint8_t >( "Database", "AsyncThreads", 2 );
|
|
|
|
|
|
|
|
// params
|
|
|
|
config.parameters.dataPath = getValue< std::string >( "Parameters", "DataPath", "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack" );
|
|
|
|
config.parameters.serverSecret = getValue< std::string >( "Parameters", "ServerSecret", "default" );
|
|
|
|
config.parameters.worldID = getValue< uint16_t >( "Parameters", "WorldID", 67 );
|
|
|
|
|
|
|
|
// network
|
|
|
|
config.network.zoneHost = getValue< std::string >( "Network", "ZoneHost", "127.0.0.1" );
|
|
|
|
config.network.zonePort = getValue< uint16_t >( "Network", "ZonePort", 54992 );
|
|
|
|
config.network.lobbyHost = getValue< std::string >( "Network", "LobbyHost", "127.0.0.1" );
|
|
|
|
config.network.lobbyPort = getValue< uint16_t >( "Network", "LobbyPort", 54994 );
|
|
|
|
config.network.restHost = getValue< std::string >( "Network", "RestHost", "127.0.0.1" );
|
|
|
|
config.network.restPort = getValue< uint16_t >( "Network", "RestPort", 80 );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
bool Sapphire::ConfigMgr::copyDefaultConfig( const std::string& configName )
|
2018-06-10 16:28:03 +00:00
|
|
|
{
|
2018-11-06 18:35:02 +11:00
|
|
|
fs::path configPath( m_configFolderRoot );
|
2018-08-29 21:40:59 +02:00
|
|
|
configPath /= configName;
|
2018-06-10 16:28:03 +00:00
|
|
|
|
2018-11-06 18:35:02 +11:00
|
|
|
if( !fs::exists( configPath.string() + m_configDefaultSuffix ) )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
|
|
|
// no default file :(
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-10 16:28:03 +00:00
|
|
|
|
2018-11-06 18:35:02 +11:00
|
|
|
fs::copy_file( configPath.string() + m_configDefaultSuffix, configPath );
|
2018-06-10 16:28:03 +00:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return true;
|
2018-10-24 23:02:30 +02:00
|
|
|
}
|
2019-01-06 23:39:30 +11:00
|
|
|
|
|
|
|
void Sapphire::ConfigMgr::initConfigData()
|
|
|
|
{
|
|
|
|
m_pConfig = std::make_shared< Common::Configuration >();
|
|
|
|
|
|
|
|
// lobby
|
|
|
|
m_pConfig->lobby.worldID = getValue< uint16_t >( "Lobby", "WorldID", 67 );
|
|
|
|
m_pConfig->lobby.allowNoSessionConnect = getValue< bool >( "Lobby", "AllowNoSessionConnect", false );
|
|
|
|
m_pConfig->lobby.worldName = getValue< std::string >( "Lobby", "WorldName", "Sapphire" );
|
|
|
|
|
|
|
|
// lobby network
|
|
|
|
m_pConfig->lobbyNetwork.listenIp = getValue< std::string >( "LobbyNetwork", "ListenIp", "0.0.0.0" );
|
|
|
|
m_pConfig->lobbyNetwork.listenPort = getValue< uint16_t >( "LobbyNetwork", "ListenPort", 54994 );
|
|
|
|
|
|
|
|
// character creation
|
|
|
|
m_pConfig->characterCreation.defaultGMRank = getValue< uint8_t >( "CharacterCreation", "DefaultGMRank", 255 );
|
|
|
|
|
|
|
|
// rest network
|
|
|
|
m_pConfig->restNetwork.listenIP = getValue< std::string >( "RestNetwork", "ListenIp", "0.0.0.0" );
|
|
|
|
m_pConfig->restNetwork.listenPort = getValue< uint16_t >( "RestNetwork", "ListenPort", 80 );
|
|
|
|
|
|
|
|
// scripts
|
|
|
|
m_pConfig->scripts.hotSwap = getValue( "Scripts", "HotSwap", true );
|
|
|
|
m_pConfig->scripts.path = getValue< std::string >( "Scripts", "Path", "./compiledscripts/" );
|
|
|
|
m_pConfig->scripts.cachePath = getValue< std::string >( "Scripts", "CachePath", "./cache/" );
|
|
|
|
|
|
|
|
// network
|
|
|
|
m_pConfig->network.disconnectTimeout = getValue< uint16_t >( "Network", "DisconnectTimeout", 20 );
|
|
|
|
|
|
|
|
// zone network
|
|
|
|
m_pConfig->zoneNetwork.listenIp = getValue< std::string >( "ZoneNetwork", "ListenIp", "0.0.0.0" );
|
|
|
|
m_pConfig->zoneNetwork.listenPort = getValue< uint16_t >( "ZoneNetwork", "ListenPort", 54992 );
|
|
|
|
|
|
|
|
// general
|
|
|
|
m_pConfig->general.motd = getValue< std::string >( "General", "MotD", "" );
|
|
|
|
|
|
|
|
// housing
|
|
|
|
m_pConfig->housing.defaultEstateName = getValue< std::string >( "Housing", "DefaultEstateName", "Estate #{}" );
|
|
|
|
}
|
|
|
|
|
|
|
|
Sapphire::ConfigMgr::ConfigurationPtr Sapphire::ConfigMgr::getConfig()
|
|
|
|
{
|
|
|
|
return m_pConfig;
|
|
|
|
}
|