/** * @return bool (false means an error occurred ) * @param inipath Doc at RoamingServer::ReadConfig */ bool MapServer::ReadConfig(const std::string &inipath) { StringsBasedCfg config; ACE_Ini_ImpExp config_importer(config); ACE_Configuration_Section_Key root; std::string map_templates_dir; if(m_endpoint) { //TODO: perform shutdown, and load config ? ACE_DEBUG((LM_WARNING,ACE_TEXT("(%P|%t) MapServer already initialized and running\n") )); return true; } if (config.open () == -1) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) MapServer: %p\n"), ACE_TEXT ("config")),false); if (config_importer.import_config (inipath.c_str()) == -1) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) MapServer: Unable to open config file : %s\n"), inipath.c_str()),false); if(-1==config.open_section(config.root_section(),"MapServer",1,root)) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) MapServer: Config file %s is missing [MapServer] section\n"), inipath.c_str()),false); if(!RoamingServer::ReadConfig(inipath)) return false; config.get_addr(root,ACE_TEXT("listen_addr"),m_listen_point,ACE_INET_Addr(7002,"0.0.0.0")); config.get_addr(root,ACE_TEXT("location_addr"),m_location,ACE_INET_Addr(7002,"127.0.0.1")); config.get_addr(root,ACE_TEXT("location_addr"),m_location,ACE_INET_Addr(7002,"127.0.0.1")); config.get_string_value(root,ACE_TEXT("maps"),map_templates_dir,"."); m_online = false; return m_manager.load_templates(map_templates_dir); }
bool GameServer::ReadConfig(const std::string &inipath) { if(m_endpoint) { ACE_DEBUG((LM_WARNING,ACE_TEXT("(%P|%t) Game server already initialized and running\n") )); return true; } StringsBasedCfg config; if (config.open () == -1) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("config")),false); } ACE_Ini_ImpExp config_importer (config); ACE_Configuration_Section_Key root; if (config_importer.import_config (inipath.c_str()) == -1) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) GameServer: Unable to open config file : %s\n"), inipath.c_str()),false); if(-1==config.open_section(config.root_section(),"GameServer",1,root)) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p GameServer: Config file %s is missing [GameServer] section\n"), inipath.c_str()),false); config.get_addr(root,ACE_TEXT("listen_addr"),m_listen_point,ACE_INET_Addr(7002,"0.0.0.0")); config.get_addr(root,ACE_TEXT("location_addr"),m_location,ACE_INET_Addr(7002,"127.0.0.1")); config.get_string_value(root,ACE_TEXT("server_name"),m_serverName,"unnamed"); config.get_integer_value_with_default(root,ACE_TEXT("max_players"),m_max_players,600); m_current_players = 0; m_id = 1; m_unk1=m_unk2=0; m_online = false; //m_db = new GameServerDb(""); return true; }
bool ConfigMgr::LoadData(char const* file) { ACE_Ini_ImpExp config_importer(*_config.get()); if (config_importer.import_config(file) == 0) return true; return false; }
bool Config::Reload() { delete mConf; mConf = new ACE_Configuration_Heap; if (mConf->open() == 0) { ACE_Ini_ImpExp config_importer(*mConf); if (config_importer.import_config(mFilename.c_str()) == 0) return true; } delete mConf; mConf = NULL; return false; }
bool Load(const char* file) { GuardType guard(m_configLock); if (file) _filename = file; _config.reset(new ACE_Configuration_Heap); if (_config->open() == 0) { ACE_Ini_ImpExp config_importer(*_config.get()); if (config_importer.import_config(_filename.c_str()) == 0) return true; } _config.reset(); return false; }
int KSGateway::start_scheduler_algorithm() { std::string config_path = KSGOSUtil::JoinPath(_configuration._basedir,KSG_CONFIG_FILENAME); ACE_Configuration_Heap config; if(config.open() == -1) { ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); } ACE_Ini_ImpExp config_importer(config); if(config_importer.import_config(config_path.c_str()) == -1) { ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); } ACE_Configuration_Section_Key section; if(config.open_section(config.root_section(),ACE_TEXT(KSG_COMMON_SECT) ,0,section) == -1) { ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); } ACE_TString v; if(config.open_section(config.root_section(),ACE_TEXT(KSG_SCHEDULER_SECT) ,0,section) == -1) ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); if(config.get_string_value(section,KSG_SCHD_ALG,v) == -1) { ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); } std::string algs = v.c_str(); std::list<std::string> idstr; std::back_insert_iterator<std::list<std::string> > iter(idstr); // 从配置中读取需要启动的任务号 xutil::StringUtil::SpliteString(algs,",",iter); int count = 0; for(std::list<std::string>::iterator i = idstr.begin();i != idstr.end();++i,++count) { if(init_scheduler_algorithm(*i)) return -1; } ACE_DEBUG((LM_TRACE,"启动[%d]个调度算法",count)); return 0; }
/** * @return int * @param configpath This is a platform specific path to a config file containing * general RoamingServer vars. */ bool RoamingServer::ReadConfig(const std::string &inipath) { StringsBasedCfg config; ACE_Ini_ImpExp config_importer(config); ACE_Configuration_Section_Key root; if (config.open () == -1) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("config")),false); } if (config_importer.import_config (inipath.c_str()) == -1) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) RoamingServer: Unable to open config file : %s\n"), inipath.c_str()),false); if(-1==config.open_section(config.root_section(),"RoamingServer",1,root)) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) RoamingServer: Config file %s is missing [RoamingServer] section\n"), inipath.c_str()),false); config.get_addr(root,ACE_TEXT("location_addr"),m_authaddr,ACE_INET_Addr(2106,"127.0.0.1")); config.get_string_value(root,ACE_TEXT("auth_pass"),m_passw,""); return true; }
int KSGateway::get_scheduler_alg_thr_count(const std::string &alg_name) { int count = 0; std::string config_path = KSGOSUtil::JoinPath(_configuration._basedir,KSG_CONFIG_FILENAME); ACE_Configuration_Heap config; if(config.open() == -1) { ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); } ACE_Ini_ImpExp config_importer(config); if(config_importer.import_config(config_path.c_str()) == -1) { ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); } ACE_Configuration_Section_Key section; if(config.open_section(config.root_section(),ACE_TEXT(KSG_COMMON_SECT) ,0,section) == -1) { ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); } ACE_TString v; if(config.open_section(config.root_section(),ACE_TEXT(KSG_SCHEDULER_SECT) ,0,section) == -1) ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); std::string key_name = alg_name; key_name += "_thr_count"; if(config.get_string_value(section,key_name.c_str(),v) == -1) { count = 5; } else { count = ACE_OS::atoi(v.c_str()); count = (count <= 0) ? 5 : count; } return count; }
/*! * @brief Read server configuration * @param inipath is a path to our configuration file. * @return bool, if it's false, this function failed somehow. */ bool AuthServer::ReadConfig(const std::string &inipath) { if(m_running) ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("(%P|%t) AuthServer: Already initialized and running\n") ),false); StringsBasedCfg config; if (config.open () == -1) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("config")),false); } ACE_Ini_ImpExp config_importer (config); ACE_Configuration_Section_Key root; if (config_importer.import_config (inipath.c_str()) == -1) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) AuthServer: Unable to open config file : %s\n"), inipath.c_str()),false); if(-1==config.open_section(config.root_section(),"AuthServer",1,root)) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p AuthServer: Config file %s is missing [AuthServer] section\n"), inipath.c_str()),false); config.get_addr(root,ACE_TEXT ("listen_addr"),m_location,ACE_INET_Addr(2106,"127.0.0.1")); return true; }
//--------------------------------------------------------------------------------------------- int HA_ccifs::init ( int argc , ACE_TCHAR *argv[] ) { ACE_Trace _( ACE_TEXT( "%D HA_ccifs::init" ) , __LINE__ ); //command line //------------------------------------------------------------------------------- static const ACE_TCHAR options[] = ACE_TEXT (":f:"); ACE_Get_Opt cmd_opts (argc, argv, options, 0); if (cmd_opts.long_option (ACE_TEXT ( "config" ), 'f', ACE_Get_Opt::ARG_REQUIRED) == -1) { return -1; } int option; ACE_TCHAR config_file[MAXPATHLEN]; ACE_OS::strcpy ( config_file, ACE_TEXT ( conf_path.c_str() ) ); while ( ( option = cmd_opts ()) != EOF) switch ( option ) { case 'f' : ACE_OS::strncpy (config_file , cmd_opts.opt_arg () , MAXPATHLEN ); break; case ':': ACE_ERROR_RETURN ( ( LM_ERROR , ACE_TEXT ( "-%c requires an argument\n" ) , cmd_opts.opt_opt ()) , -1 ); default: ACE_ERROR_RETURN ( ( LM_ERROR , ACE_TEXT ( "parse error.\n" ) ) , - 1); } //configuration file //------------------------------------------------------------------------------- ACE_Configuration_Heap config; config.open (); ACE_Registry_ImpExp config_importer (config); if ( config_importer.import_config (config_file) == -1 ) { ACE_ERROR_RETURN ( ( LM_ERROR , ACE_TEXT ("%p\n") , config_file ) , -1 ); } ACE_Configuration_Section_Key dispatcher_section; if (config.open_section (config.root_section (), ACE_TEXT ("HA_ccifs"), 0, dispatcher_section) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ( "can't open HA_ccifs section" ) ) , -1 ); //fifo u_int dispatcher_port; if (config.get_integer_value ( dispatcher_section, ACE_TEXT ( "fifo" ) , dispatcher_port ) == -1 ) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("HA_ccifs fifo") ACE_TEXT (" does not exist\n") ) , -1 ); //ccifs ACE_TString ccifs; if (config.get_string_value ( dispatcher_section, ACE_TEXT ( "ccifs_tmpfs_mount" ) , ccifs ) == -1 ) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("HA_ccifs ccifs_mount") ACE_TEXT (" does not exist\n") ) , -1 ); if( ACE_Thread_Manager::instance()->spawn( ACE_THR_FUNC (ccifs_func) , (void*) this , THR_NEW_LWP , &m_thread_id ) ) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) ..spawned ccifs notify thread..\n"))); } else { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) ..spawning ccifs notify failed..\n"))); } return 0; }
// Listing 1 code/ch19 int HA_Status::init (int argc, ACE_TCHAR *argv[]) { static const ACE_TCHAR options[] = ACE_TEXT (":f:"); ACE_Get_Opt cmd_opts (argc, argv, options, 0); if (cmd_opts.long_option (ACE_TEXT ("config"), 'f', ACE_Get_Opt::ARG_REQUIRED) == -1) return -1; int option; ACE_TCHAR config_file[MAXPATHLEN]; ACE_OS::strcpy (config_file, ACE_TEXT ("HAStatus.conf")); while ((option = cmd_opts ()) != EOF) switch (option) { case 'f': ACE_OS::strncpy (config_file, cmd_opts.opt_arg (), MAXPATHLEN); break; case ':': ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("-%c requires an argument\n"), cmd_opts.opt_opt ()), -1); default: ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Parse error.\n")), -1); } ACE_Configuration_Heap config; config.open (); ACE_Registry_ImpExp config_importer (config); if (config_importer.import_config (config_file) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), config_file), -1); ACE_Configuration_Section_Key status_section; if (config.open_section (config.root_section (), ACE_TEXT ("HAStatus"), 0, status_section) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("Can't open HAStatus section")), -1); u_int status_port; if (config.get_integer_value (status_section, ACE_TEXT ("ListenPort"), status_port) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("HAStatus ListenPort ") ACE_TEXT ("does not exist\n")), -1); this->listen_addr_.set (static_cast<u_short> (status_port)); if (this->acceptor_.open (this->listen_addr_) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("HAStatus %p\n"), ACE_TEXT ("accept")), -1); return 0; }
int KSGConfig::loadConfig(const std::string& file_name) { ACE_Configuration_Heap config; if(config.open() == -1) { ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); } ACE_Ini_ImpExp config_importer(config); if(config_importer.import_config(file_name.c_str()) == -1) { ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); } ACE_Configuration_Section_Key section; if(config.open_section(config.root_section(),ACE_TEXT(KSG_COMMON_SECT) ,0,section) == -1) { ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); } ACE_TString v; if(config.get_string_value(section,ACE_TEXT(KSG_MAJOR_VER),v) == -1) { ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); } _majorVer = ACE_OS::atoi(v.c_str()); if(config.get_string_value(section,KSG_MINOR_VER,v) == -1) { ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); } _minorVer = ACE_OS::atoi(v.c_str()); if(config.open_section(config.root_section(),ACE_TEXT(KSG_SERVER_SECT) ,0,section) == -1 ) ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); if(config.get_string_value(section,KSG_SVR_IP,v) == -1) { ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); } _drtpSvrIP = v.c_str(); if(config.get_string_value(section,KSG_SVR_PORT,v) == -1) ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); _drtpSvrPort = ACE_OS::atoi(v.c_str()); if(config.get_string_value(section,KSG_SVR_BRANCE_NO,v) == -1) ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); _drtpNo = ACE_OS::atoi(v.c_str()); if(config.get_string_value(section,KSG_SVR_MAINFUNC,v) == -1) ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); _drtpMainFunc = ACE_OS::atoi(v.c_str()); if(config.get_string_value(section,KSG_SVR_POOL_CONN,v) == -1) _drtpPoolMaxCnt = 5; else _drtpPoolMaxCnt = ACE_OS::atoi(v.c_str()); if(_drtpPoolMaxCnt < 0) _drtpPoolMaxCnt = 5; if(_drtpPoolMaxCnt > 30) _drtpPoolMaxCnt = 30; if(config.get_string_value(section,KSG_SVR_BCC,v) == -1) _start_bcc = 0; else _start_bcc = ACE_OS::atoi(v.c_str()); /// 是否加载卡状态 if(config.get_string_value(section,KSG_SVR_LOAD_CARD_STATE,v) == -1) _loadCardState = 0; else _loadCardState = ACE_OS::atoi(v.c_str()); if(config.open_section(config.root_section(),ACE_TEXT(KSG_GATEWAY_SECT) ,0,section) == -1) ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); if(config.get_string_value(section,KSG_GW_IP,v) == -1) ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); _localIP = v.c_str(); if(config.open_section(config.root_section(),ACE_TEXT(KSG_SCHEDULER_SECT) ,0,section) == -1) ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1); _runTaskIds = ""; if(config.get_string_value(section,KSG_SCHD_IDS,v) != -1) { _runTaskIds = v.c_str(); } _listenerIds = ""; if(config.get_string_value(section,KSG_LISTENER_IDS,v) != -1) { _listenerIds = v.c_str(); } if(config.get_string_value(section,"conn_interval",v)==-1) _conn_interval = 100; else _conn_interval = ACE_OS::atoi(v.c_str()); if(config.get_string_value(section,"reactor_thr_count",v)==-1) _reactor_thr_count = 10; else _reactor_thr_count = ACE_OS::atoi(v.c_str()); if(config.open_section(config.root_section(),ACE_TEXT(KSG_LOG_SECT) ,0,section) == -1) ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取日志配置失败")),-1); if(config.get_string_value(section,KSG_LOG_LEVEL,v)!=-1) { _logLevel = v.c_str(); } if(config.get_string_value(section,KSG_LOG_APPENDER,v)!=-1) { _logOutput = v.c_str(); } if(config.get_string_value(section,KSG_LOG_FILE,v)!=-1) { _logFilePath = v.c_str(); } if(config.get_string_value(section,KSG_LOG_FILEMAX,v) != -1) { _log_max_file_size = ACE_OS::atoi(v.c_str()); if(_log_max_file_size == 0) _log_max_file_size = 1024; _log_max_file_size *= 1024; if(_log_max_file_size <= 0) _log_max_file_size = 1024 * 1024; } if(config.get_string_value(section,KSG_LOG_MAX_COUNT,v) !=-1) { _log_max_backup = ACE_OS::atoi(v.c_str()); if(_log_max_backup == 0) _log_max_backup = 1; } return 0; }
bool _AdminServer::ReadConfig(const std::string &inipath) { if(m_running) ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("(%P|%t) AdminServer: Already initialized and running\n") ),false); StringsBasedCfg config; if (config.open () == -1) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("config")),false); } ACE_Ini_ImpExp config_importer (config); if (config_importer.import_config (inipath.c_str()) == -1) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) AdminServer: Unable to open config file : %s\n"), inipath.c_str()),false); ACE_Configuration_Section_Key root; ACE_Configuration_Section_Key account_db_config; ACE_Configuration_Section_Key character_db_config; if(-1==config.open_section(config.root_section(),"AdminServer",1,root)) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) AdminServer: Config file %s is missing [AdminServer] section\n"), inipath.c_str()),false); if(-1==config.open_section(root,"AccountDatabase",1,account_db_config)) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) AdminServer: Config file %s is missing [AccountDatabase] section\n"), inipath.c_str()),false); std::string dbhost,dbname,dbuser,dbpass,dbport,dbdriver; config.get_string_value(account_db_config,ACE_TEXT("db_driver"),dbdriver,"sqlite"); config.get_string_value(account_db_config,ACE_TEXT("db_host"),dbhost,"127.0.0.1"); config.get_string_value(account_db_config,ACE_TEXT("db_port"),dbport,"5432"); config.get_string_value(account_db_config,ACE_TEXT("db_name"),dbname,"segs"); config.get_string_value(account_db_config,ACE_TEXT("db_user"),dbuser,"none"); config.get_string_value(account_db_config,ACE_TEXT("db_pass"),dbpass,"none"); Database *db1; if(dbdriver=="pgsql") { #ifdef HAVE_POSTGRES db1 = new PSqlDatabase; #else ACE_DEBUG((LM_INFO,"PostgreSQL support was not selected during compilation.\n")); db1 = new SqliteDatabase; #endif } else { db1 = new SqliteDatabase; } db1->setConnectionConfiguration(dbhost.c_str(),dbport.c_str(),dbname.c_str(),dbuser.c_str(),dbpass.c_str()); m_db->setDb(db1); if(-1==config.open_section(root,"CharacterDatabase",1,character_db_config)) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) AdminServer: Config file %s is missing [CharacterDatabase] section\n"), inipath.c_str()),false); config.get_string_value(character_db_config,ACE_TEXT("db_driver"),dbdriver,"sqlite"); config.get_string_value(character_db_config,ACE_TEXT("db_host"),dbhost,"127.0.0.1"); config.get_string_value(character_db_config,ACE_TEXT("db_port"),dbport,"5432"); config.get_string_value(character_db_config,ACE_TEXT("db_name"),dbname,"segs_game"); config.get_string_value(character_db_config,ACE_TEXT("db_user"),dbuser,"none"); config.get_string_value(character_db_config,ACE_TEXT("db_pass"),dbpass,"none"); Database *db2; if(dbdriver=="pgsql") { #ifdef HAVE_POSTGRES db2 = new PSqlDatabase; #else ACE_DEBUG((LM_INFO,"PostgreSQL support was not selected during compilation.\n")); db2 = new SqliteDatabase; #endif } else { db2 = new SqliteDatabase; } db2->setConnectionConfiguration(dbhost.c_str(),dbport.c_str(),dbname.c_str(),dbuser.c_str(),dbpass.c_str()); m_char_db->setDb(db2); return true; }