[11751] Implement option for set ahbot config file in mangosd command line

"-a configfilename" or "--ahbot configfilename" can be used for this

This possibility can be useful if normal mangosd.conf path also set by -c
option for example.
This commit is contained in:
VladimirMangos 2011-07-24 08:23:10 +04:00
parent b26a969e0d
commit f07a3232d4
4 changed files with 19 additions and 8 deletions

View file

@ -211,19 +211,22 @@ INSTANTIATE_SINGLETON_1( AuctionBotConfig );
//== AuctionBotConfig functions ============================ //== AuctionBotConfig functions ============================
AuctionBotConfig::AuctionBotConfig() : m_configFileName(_AUCTIONHOUSEBOT_CONFIG)
{
}
bool AuctionBotConfig::Initialize() bool AuctionBotConfig::Initialize()
{ {
char const* cfg_file = _AUCTIONHOUSEBOT_CONFIG; if (!m_AhBotCfg.SetSource(m_configFileName.c_str()))
if (!m_AhBotCfg.SetSource(cfg_file))
{ {
sLog.outString("AHBOT is Disabled. Unable to open configuration file(%s). ", _AUCTIONHOUSEBOT_CONFIG); sLog.outString("AHBOT is Disabled. Unable to open configuration file(%s). ", m_configFileName.c_str());
setConfig(CONFIG_UINT32_AHBOT_ALLIANCE_ITEM_AMOUNT_RATIO, 0); setConfig(CONFIG_UINT32_AHBOT_ALLIANCE_ITEM_AMOUNT_RATIO, 0);
setConfig(CONFIG_UINT32_AHBOT_HORDE_ITEM_AMOUNT_RATIO, 0); setConfig(CONFIG_UINT32_AHBOT_HORDE_ITEM_AMOUNT_RATIO, 0);
setConfig(CONFIG_UINT32_AHBOT_NEUTRAL_ITEM_AMOUNT_RATIO, 0); setConfig(CONFIG_UINT32_AHBOT_NEUTRAL_ITEM_AMOUNT_RATIO, 0);
return false; return false;
} }
else else
sLog.outString("AHBot using configuration file %s",_AUCTIONHOUSEBOT_CONFIG); sLog.outString("AHBot using configuration file %s", m_configFileName.c_str());
GetConfigFromFile(); GetConfigFromFile();

View file

@ -107,8 +107,9 @@ enum AuctionBotConfigBoolValues
class AuctionBotConfig class AuctionBotConfig
{ {
public: public:
AuctionBotConfig() {} AuctionBotConfig();
void SetConfigFileName(char const* filename) { m_configFileName = filename; }
bool Initialize(); bool Initialize();
const char* GetAHBotIncludes() const { return m_AHBotIncludes.c_str(); } const char* GetAHBotIncludes() const { return m_AHBotIncludes.c_str(); }
const char* GetAHBotExcludes() const { return m_AHBotExcludes.c_str(); } const char* GetAHBotExcludes() const { return m_AHBotExcludes.c_str(); }
@ -131,6 +132,7 @@ class AuctionBotConfig
static char const* GetHouseTypeName(AuctionHouseType houseType); static char const* GetHouseTypeName(AuctionHouseType houseType);
private: private:
std::string m_configFileName;
std::string m_AHBotIncludes; std::string m_AHBotIncludes;
std::string m_AHBotExcludes; std::string m_AHBotExcludes;
Config m_AhBotCfg; Config m_AhBotCfg;

View file

@ -27,6 +27,7 @@
#include "Log.h" #include "Log.h"
#include "Master.h" #include "Master.h"
#include "SystemConfig.h" #include "SystemConfig.h"
#include "AuctionHouseBot/AuctionHouseBot.h"
#include "revision.h" #include "revision.h"
#include "revision_nr.h" #include "revision_nr.h"
#include <openssl/opensslv.h> #include <openssl/opensslv.h>
@ -62,6 +63,7 @@ void usage(const char *prog)
sLog.outString("Usage: \n %s [<options>]\n" sLog.outString("Usage: \n %s [<options>]\n"
" -v, --version print version and exist\n\r" " -v, --version print version and exist\n\r"
" -c config_file use config_file as configuration file\n\r" " -c config_file use config_file as configuration file\n\r"
" -a, --ahbot config_file use config_file as ahbot configuration file\n\r"
#ifdef WIN32 #ifdef WIN32
" Running as service functions:\n\r" " Running as service functions:\n\r"
" -s run run as service\n\r" " -s run run as service\n\r"
@ -82,10 +84,11 @@ extern int main(int argc, char **argv)
char const* cfg_file = _MANGOSD_CONFIG; char const* cfg_file = _MANGOSD_CONFIG;
char const *options = ":c:s:"; char const *options = ":a:c:s:";
ACE_Get_Opt cmd_opts(argc, argv, options); ACE_Get_Opt cmd_opts(argc, argv, options);
cmd_opts.long_option("version", 'v'); cmd_opts.long_option("version", 'v', ACE_Get_Opt::NO_ARG);
cmd_opts.long_option("ahbot", 'a', ACE_Get_Opt::ARG_REQUIRED);
char serviceDaemonMode = '\0'; char serviceDaemonMode = '\0';
@ -94,6 +97,9 @@ extern int main(int argc, char **argv)
{ {
switch (option) switch (option)
{ {
case 'a':
sAuctionBotConfig.SetConfigFileName(cmd_opts.opt_arg());
break;
case 'c': case 'c':
cfg_file = cmd_opts.opt_arg(); cfg_file = cmd_opts.opt_arg();
break; break;

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "11750" #define REVISION_NR "11751"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__