static void Main(string[] args)
{
Thread.CurrentThread.Name = "Main";
Thread.GetDomain().UnhandledException += new UnhandledExceptionEventHandler(Application_UnhandledException);
string mainConfigFN = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
+ Path.DirectorySeparatorChar + "CTFBot.ini";
logger.Info("Loading main configuration from "+mainConfigFN);
using (StreamReader sr = new StreamReader(mainConfigFN))
{
String line;
while ((line = sr.ReadLine()) != null)
{
if (!line.StartsWith("#") && (line != "")) //ignore comments
{
string[] parts = line.Split(new char[1] { '=' }, 2);
mainConfig.Add(parts[0], parts[1]);
}
}
}
botNick = (string)mainConfig["botnick"];
sourceServerName = (string)mainConfig["sourceIrcserver"];
sourceChannel = (string)mainConfig["sourceChannel"];
sourceAccount = (string)mainConfig["sourceAccount"];
targetServerName = (string)mainConfig["targetIrcserver"];
targetFeedChannel = (string)mainConfig["targetFeedChannel"];
targetCVNChannel = (string)mainConfig["targetCVNChannel"];
targetControlChannel = (string)mainConfig["targetControlChannel"];
targetHomeChannel = (string)mainConfig["targetHomeChannel"];
// ClueNet only monitors en.wikipedia and there are no plans for monitoring more
// and/or to split up in tracable sources. This only affects the links generated
// and the Autoblacklist-message
targetWikiproject = "en.wikipedia";
targetBlacklistDuration = (string)mainConfig["targetBlacklistDuration"];
botCmd = new Regex("^" + botNick + @" (\s*(?<command>\S*))(\s(?<params>.*))?$", RegexOptions.IgnoreCase);
logger.Info("Loading messages");
readMessages((string)mainConfig["messages"]);
if ((!msgs.ContainsKey("00000")) || ((String)msgs["00000"] != "0.02"))
{
logger.Fatal("Message file version mismatch or read messages failed");
Exit();
}
logger.Info("Setting up main IRC client");
//Set up freenode IRC client
irc.Encoding = System.Text.Encoding.UTF8;
irc.SendDelay = 300;
//irc.AutoReconnect = true;
//irc.AutoRejoin = true;
irc.ActiveChannelSyncing = true;
irc.OnChannelMessage += new IrcEventHandler(irc_OnChannelMessage);
irc.OnChannelNotice += new IrcEventHandler(irc_OnChannelNotice);
irc.OnConnected += new EventHandler(irc_OnConnected);
irc.OnError += new Meebey.SmartIrc4net.ErrorEventHandler(irc_OnError);
irc.OnConnectionError += new EventHandler(irc_OnConnectionError);
irc.OnPong += new PongEventHandler(irc_OnPong);
//irc.PingTimeout = 10;
try
{
irc.Connect(targetServerName, 6667);
}
catch (ConnectionException e)
{
logger.Fatal("Could not connect: " + e.Message);
Exit();
}
// Now initialize flood protection code
new Thread(new ThreadStart(msgthread)).Start();
try
{
irc.Login(botNick, (string)mainConfig["description"] + " " + version, 4, botNick, (string)mainConfig["botpass"]);
if (targetFeedChannel != "None")
{
logger.Info("Joining feed channel: " + targetFeedChannel);
irc.RfcJoin(targetFeedChannel);
}
if (targetCVNChannel != "None")
{
logger.Info("Joining cvn channel: " + targetCVNChannel);
irc.RfcJoin(targetCVNChannel);
}
if (targetControlChannel != "None")
{
logger.Info("Joining control channel: " + targetControlChannel);
irc.RfcJoin(targetControlChannel);
}
if (targetHomeChannel != "None")
{
logger.Info("Joining home channel: " + targetHomeChannel);
irc.RfcJoin(targetHomeChannel);
}
//Now connect the SourceReader to channels
new Thread(new ThreadStart(sourceirc.initiateConnection)).Start();
// here we tell the IRC API to go into a receive mode, all events
// will be triggered by _this_ thread (main thread in this case)
// Listen() blocks by default, you can also use ListenOnce() if you
// need that does one IRC operation and then returns, so you need then
// an own loop
irc.Listen();
// when Listen() returns our IRC session is over, to be sure we call
// disconnect manually
irc.Disconnect();
}
catch (ConnectionException)
{
// this exception is handled because Disconnect() can throw a not
// connected exception
Exit();
}
catch (Exception e)
{
// this should not happen by just in case we handle it nicely
logger.Fatal("Error occurred in Main IRC try clause! Message: " + e.Message);
logger.Fatal("Exception: " + e.StackTrace);
Exit();
}
}