Skip to content

Commit

Permalink
Allow setting config-file by commandline args
Browse files Browse the repository at this point in the history
  • Loading branch information
clint.banzhaf authored and clint.banzhaf committed Dec 13, 2017
1 parent 10fbd00 commit c1db6cc
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 127 deletions.
17 changes: 1 addition & 16 deletions Meridian59.Bot.IRC/IRCBotConfig.cs
Expand Up @@ -71,28 +71,13 @@ public class IRCBotConfig : BotConfig
/// Constructor
/// </summary>
public IRCBotConfig()
: base() { }

/// <summary>
///
/// </summary>
protected override void InitPreConfig()
: base()
{
base.InitPreConfig();

AdminCommands = new List<string>();
AllowedUsers = new List<string>();
RelayBots = new List<RelayConfig>();
}

/// <summary>
///
/// </summary>
protected override void InitPastConfig()
{
base.InitPastConfig();
}

/// <summary>
///
/// </summary>
Expand Down
15 changes: 13 additions & 2 deletions Meridian59.Bot.IRC/Program.cs
Expand Up @@ -28,13 +28,23 @@ class Program
{
static void Main(string[] args)
{
string configFile = Config.CONFIGFILE;
string configFileAlt = Config.CONFIGFILE_ALT;

// try parse config parameter
string cmdConfig = Config.GetFilenameFromCmdArgs(args);

// overwrite with user specified config
if (cmdConfig != null)
configFile = configFileAlt = cmdConfig;

// run as console app
if (Environment.UserInteractive)
{
IRCBotClient ircBot = new IRCBotClient();

// start it
ircBot.Start(true);
ircBot.Start(true, configFile, configFileAlt);
}

// run as windows service
Expand All @@ -46,7 +56,8 @@ static void Main(string[] args)

// create bot-service wrapper
ServiceBase serviceWrap =
new BotServiceWrapper<GameTick, ResourceManager, DataController, IRCBotConfig, IRCBotClient>();
new BotServiceWrapper<GameTick, ResourceManager, DataController, IRCBotConfig, IRCBotClient>(
configFile, configFileAlt);

// run service
ServiceBase.Run(serviceWrap);
Expand Down
15 changes: 13 additions & 2 deletions Meridian59.Bot.Shop/Program.cs
Expand Up @@ -28,13 +28,23 @@ class Program
{
static void Main(string[] args)
{
string configFile = ShopBotConfig.CONFIGFILE_SHOPBOT;
string configFileAlt = ShopBotConfig.CONFIGFILE_SHOPBOT_ALT;

// try parse config parameter
string cmdConfig = Config.GetFilenameFromCmdArgs(args);

// overwrite with user specified config
if (cmdConfig != null)
configFile = configFileAlt = cmdConfig;

// run as console app
if (Environment.UserInteractive)
{
ShopBotClient shopBot = new ShopBotClient();

// start it
shopBot.Start(true);
shopBot.Start(true, configFile, configFileAlt);
}

// run as windows service
Expand All @@ -46,7 +56,8 @@ static void Main(string[] args)

// create bot-service wrapper
ServiceBase serviceWrap =
new BotServiceWrapper<GameTick, ResourceManager, DataController, ShopBotConfig, ShopBotClient>();
new BotServiceWrapper<GameTick, ResourceManager, DataController, ShopBotConfig, ShopBotClient>(
configFile, configFileAlt);

// run service
ServiceBase.Run(serviceWrap);
Expand Down
19 changes: 1 addition & 18 deletions Meridian59.Bot.Shop/ShopBotConfig.cs
Expand Up @@ -52,8 +52,6 @@ public class ShopBotConfig : BotConfig
#endregion

#region Properties
public override string ConfigFile { get { return CONFIGFILE_SHOPBOT; } }
public override string ConfigFileAlt { get { return CONFIGFILE_SHOPBOT_ALT; } }
public uint IntervalBroadcast { get; protected set; }
public uint IntervalSay { get; protected set; }
public bool TellOnEnter { get; protected set; }
Expand All @@ -67,27 +65,12 @@ public class ShopBotConfig : BotConfig
/// Constructor
/// </summary>
public ShopBotConfig()
: base() { }

/// <summary>
///
/// </summary>
protected override void InitPreConfig()
: base()
{
base.InitPreConfig();

OfferList = new List<ShopItem>();
BuyList = new List<ShopItem>();
}

/// <summary>
///
/// </summary>
protected override void InitPastConfig()
{
base.InitPastConfig();
}

/// <summary>
/// Looks up an entry from the buylist.
/// </summary>
Expand Down
15 changes: 13 additions & 2 deletions Meridian59.Bot.Spell/Program.cs
Expand Up @@ -28,13 +28,23 @@ class Program
{
static void Main(string[] args)
{
string configFile = SpellBotConfig.CONFIGFILE_SPELLBOT;
string configFileAlt = SpellBotConfig.CONFIGFILE_SPELLBOT_ALT;

// try parse config parameter
string cmdConfig = Config.GetFilenameFromCmdArgs(args);

// overwrite with user specified config
if (cmdConfig != null)
configFile = configFileAlt = cmdConfig;

// run as console app
if (Environment.UserInteractive)
{
SpellBotClient spellBot = new SpellBotClient();

// start it
spellBot.Start(true);
spellBot.Start(true, configFile, configFileAlt);
}

// run as windows service
Expand All @@ -46,7 +56,8 @@ static void Main(string[] args)

// create bot-service wrapper
ServiceBase serviceWrap =
new BotServiceWrapper<GameTick, ResourceManager, DataController, SpellBotConfig, SpellBotClient>();
new BotServiceWrapper<GameTick, ResourceManager, DataController, SpellBotConfig, SpellBotClient>(
configFile, configFileAlt);

// run service
ServiceBase.Run(serviceWrap);
Expand Down
21 changes: 2 additions & 19 deletions Meridian59.Bot.Spell/SpellBotConfig.cs
Expand Up @@ -70,8 +70,6 @@ public class SpellBotConfig : BotConfig
protected int currentTask = 0;

#region Properties
public override string ConfigFile { get { return CONFIGFILE_SPELLBOT; } }
public override string ConfigFileAlt { get { return CONFIGFILE_SPELLBOT_ALT; } }
public Template ActiveTemplate { get; protected set; }
public List<Template> Templates { get; protected set; }
#endregion
Expand All @@ -80,24 +78,9 @@ public class SpellBotConfig : BotConfig
/// Constructor
/// </summary>
public SpellBotConfig()
: base() { }

/// <summary>
///
/// </summary>
protected override void InitPreConfig()
{
base.InitPreConfig();

Templates = new List<Template>();
}

/// <summary>
///
/// </summary>
protected override void InitPastConfig()
: base()
{
base.InitPastConfig();
Templates = new List<Template>();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Meridian59.Ogre.Client/Application.cpp
Expand Up @@ -88,7 +88,7 @@ int __stdcall WinMain(
::System::Threading::Thread::CurrentThread->Priority = ::System::Threading::ThreadPriority::Highest;

// init client and start (locks thread)
OgreClient::Singleton->Start(true);
OgreClient::Singleton->Start(true, Config::CONFIGFILE, Config::CONFIGFILE_ALT);

#if _DEBUG
//FreeConsole();
Expand Down
37 changes: 11 additions & 26 deletions Meridian59.Ogre.Client/OgreClientConfig.cpp
Expand Up @@ -22,18 +22,8 @@ namespace Meridian59 { namespace Ogre
{
OgreClientConfig::OgreClientConfig() : Config()
{
// be warned:
// base constructor will already start reading, use InitPreConfig() instead
};

void OgreClientConfig::InitPreConfig()
{
Config::InitPreConfig();

// default ui layout

UILayoutAvatar = new ::CEGUI::URect(
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(0.0f, 2.0f), ::CEGUI::UDim(0.0f, 25.0f)),
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(0.0f, 2.0f), ::CEGUI::UDim(0.0f, 25.0f)),
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 250.0f), ::CEGUI::UDim(0.0f, 141.0f)));

UILayoutTarget = new ::CEGUI::URect(
Expand All @@ -46,56 +36,51 @@ namespace Meridian59 { namespace Ogre

UILayoutMainButtonsLeft = new ::CEGUI::URect(
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(0.5f, -174.0f), ::CEGUI::UDim(1.0f, -32.0f)),
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 175.0f), ::CEGUI::UDim(0.0f, 30.0f)));
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 175.0f), ::CEGUI::UDim(0.0f, 30.0f)));

UILayoutMainButtonsRight = new ::CEGUI::URect(
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(0.5f, 0.0f), ::CEGUI::UDim(1.0f, -32.0f)),
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 175.0f), ::CEGUI::UDim(0.0f, 30.0f)));

UILayoutActionButtons = new ::CEGUI::URect(
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(0.5f, -174.0f), ::CEGUI::UDim(1.0f, -150.0f)),
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 349.0f), ::CEGUI::UDim(0.0f, 117.0f)));
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 349.0f), ::CEGUI::UDim(0.0f, 117.0f)));

UILayoutChat = new ::CEGUI::URect(
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(0.0f, 2.0f), ::CEGUI::UDim(1.0f, -186.0f)),
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(0.0f, 2.0f), ::CEGUI::UDim(1.0f, -186.0f)),
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 463.0f), ::CEGUI::UDim(0.0f, 184.0f)));

UILayoutInventory = new ::CEGUI::URect(
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(1.0f, -286.0f), ::CEGUI::UDim(1.0f, -186.0f)),
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 284.0f), ::CEGUI::UDim(0.0f, 184.0f)));
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 284.0f), ::CEGUI::UDim(0.0f, 184.0f)));

UILayoutMinimap = new ::CEGUI::URect(
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(1.0f, -258.0f), ::CEGUI::UDim(0.0f, 25.0f)),
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 256.0f), ::CEGUI::UDim(0.0f, 256.0f)));
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 256.0f), ::CEGUI::UDim(0.0f, 256.0f)));

UILayoutOnlinePlayers = new ::CEGUI::URect(
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(0.5f, -96.0f), ::CEGUI::UDim(0.3f, -24.0f)),
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 192.0f), ::CEGUI::UDim(0.0f, 192.0f)));
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 192.0f), ::CEGUI::UDim(0.0f, 192.0f)));

UILayoutSpells = new ::CEGUI::URect(
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(0.5f, -96.0f), ::CEGUI::UDim(0.3f, 0.0f)),
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 192.0f), ::CEGUI::UDim(0.0f, 192.0f)));
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 192.0f), ::CEGUI::UDim(0.0f, 192.0f)));

UILayoutSkills = new ::CEGUI::URect(
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(0.5f, -96.0f), ::CEGUI::UDim(0.3f, 24.0f)),
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 192.0f), ::CEGUI::UDim(0.0f, 192.0f)));
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 192.0f), ::CEGUI::UDim(0.0f, 192.0f)));

UILayoutActions = new ::CEGUI::URect(
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(0.5f, -96.0f), ::CEGUI::UDim(0.3f, 48.0f)),
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 192.0f), ::CEGUI::UDim(0.0f, 192.0f)));
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 192.0f), ::CEGUI::UDim(0.0f, 192.0f)));

UILayoutRoomObjects = new ::CEGUI::URect(
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(0.5f, -96.0f), ::CEGUI::UDim(0.3f, 72.0f)),
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 192.0f), ::CEGUI::UDim(0.0f, 192.0f)));

UILayoutAttributes = new ::CEGUI::URect(
::CEGUI::Vector2<::CEGUI::UDim>(::CEGUI::UDim(0.5f, -144.0f), ::CEGUI::UDim(0.3f, 96.0f)),
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 288.0f), ::CEGUI::UDim(0.0f, 192.0f)));
};

void OgreClientConfig::InitPastConfig()
{
Config::InitPastConfig();
::CEGUI::Size <::CEGUI::UDim>(::CEGUI::UDim(0.0f, 288.0f), ::CEGUI::UDim(0.0f, 192.0f)));
};

void OgreClientConfig::ReadUILayout(::CEGUI::URect* Layout, XmlNode^ Node, bool DoSize)
Expand Down
2 changes: 0 additions & 2 deletions Meridian59.Ogre.Client/OgreClientConfig.h
Expand Up @@ -302,8 +302,6 @@ namespace Meridian59 { namespace Ogre

OgreClientConfig();

virtual void InitPreConfig() override;
virtual void InitPastConfig() override;
virtual void ReadXml(::System::Xml::XmlDocument^ Document) override;
virtual void WriteXml(::System::Xml::XmlWriter^ Writer) override;

Expand Down
2 changes: 1 addition & 1 deletion Meridian59/Bot/BotClient.cs
Expand Up @@ -663,7 +663,7 @@ protected virtual void ProcessKeyPress(ConsoleKeyInfo Key)
Log("SYS", LOG_RELOADCONFIG);

// reload
Config.Load();
Config.Load(Config.ConfigFile, Config.ConfigFileAlt);
break;
}
}
Expand Down
14 changes: 0 additions & 14 deletions Meridian59/Bot/BotConfig.cs
Expand Up @@ -52,24 +52,10 @@ public abstract class BotConfig : Config
/// Constructor
/// </summary>
public BotConfig() : base()
{
}

/// <summary>
/// Override with init code called before configload in parentconstructor
/// </summary>
protected override void InitPreConfig()
{
Admins = new List<string>();
}

/// <summary>
/// Override with init code called after configload
/// </summary>
protected override void InitPastConfig()
{
}

/// <summary>
/// Says whether a name is on the admin list
/// </summary>
Expand Down
21 changes: 20 additions & 1 deletion Meridian59/Bot/BotServiceWrapper.cs
Expand Up @@ -56,6 +56,25 @@ public class BotServiceWrapper<T, R, D, K, X> : ServiceBase
/// </summary>
protected X client;

/// <summary>
/// Stores config file to use
/// </summary>
protected readonly string configFile;

/// <summary>
/// Stores alternative config file to use
/// </summary>
protected readonly string configFileAlt;

/// <summary>
/// Constructor
/// </summary>
public BotServiceWrapper(string ConfigFile = Config.CONFIGFILE, string ConfigFileAlt = Config.CONFIGFILE_ALT)
{
this.configFile = ConfigFile;
this.configFileAlt = ConfigFileAlt;
}

/// <summary>
/// Executed when service starts.
/// Do not lock here!
Expand Down Expand Up @@ -109,7 +128,7 @@ protected void ThreadProc()
client.IsService = true;

// start it (locks with a while loop)
client.Start();
client.Start(true, configFile, configFileAlt);

// sleep 30s before restart after "normal exit"
Thread.Sleep(30000);
Expand Down

0 comments on commit c1db6cc

Please sign in to comment.