/// <summary> /// The entry point of the program, where the program control starts and ends. /// </summary> /// <param name='args'> /// The command-line arguments. /// </param> private static void Main(string[] args) { try { Configuration.System.UpTime = DateTime.Now; Core.KernelThread = Thread.CurrentThread; Core.KernelThread.Name = "Kernel"; Configuration.System.Version += " [libirc v. " + libirc.Defs.Version.ToString() + "]"; Thread logger = new Thread(Logging.Exec) { Name = "Logger" }; Core.ThreadManager.RegisterThread(logger); ParseArgs(args); Syslog.WriteNow(Configuration.System.Version); Syslog.WriteNow("Loading..."); logger.Start(); Console.CancelKeyPress += SigInt; messages.LoadLD(); if (Configuration.Load() != 0) { Syslog.WriteNow("Error while loading the config file, exiting", true); Environment.Exit(-2); } Terminal.Init(); Core.Help.CreateHelp(); Core.WriterThread = new Thread(StorageWriter.Exec); Core.ThreadManager.RegisterThread(Core.WriterThread); Core.WriterThread.Name = "Writer"; Core.WriterThread.Start(); if (WMIBMySQL.IsAvailable) { Syslog.Log("Initializing MySQL"); Core.MysqlDB = new WMIBMySQL(); } else { Syslog.Log("Mysql is not configured, not using"); } if (PostgreSQL.IsAvailable) { Syslog.Log("Opening connection to PostgreDB"); Core.PostgreDB = new PostgreSQL(); Core.PostgreDB.Connect(); } else { Syslog.Log("Postgres is not configured, not using"); } // let's use postgre as default if (Core.PostgreDB != null) { Syslog.Log("Using Postgres as a default SQL provider"); Core.DB = Core.PostgreDB; } else if (Core.MysqlDB != null) { Syslog.Log("Using MySQL as a default SQL"); Core.DB = Core.MysqlDB; } // register all commands Commands.InitAdminCommands(); Syslog.Log("Loading modules"); ExtensionHandler.SearchMods(); Security.Init(); Security.Global(); Syslog.Log("Connecting"); IRC.Connect(); #if __MonoCS__ UnixSignal[] signals = { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGTERM), new UnixSignal(Signum.SIGQUIT), new UnixSignal(Signum.SIGHUP) }; #endif while (Core.IsRunning) { #if __MonoCS__ int index = UnixSignal.WaitAny(signals, -1); Signum signal = signals [index].Signum; switch (signal) { case Signum.SIGINT: SigInt(null, null); goto exit; case Signum.SIGTERM: Syslog.WriteNow("SIGTERM - Shutting down", true); Core.Kill(); goto exit; } #endif Thread.Sleep(200); } #if __MonoCS__ exit: #endif // memory cleanup if (Core.DB != null) { ((WMIBMySQL)Core.DB).Dispose(); } } catch (Exception fatal) { Syslog.WriteNow("bot crashed, bellow is debugging information", Syslog.Type.Error); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Description: " + fatal.Message); Console.WriteLine("Stack trace: " + fatal.StackTrace); Environment.Exit(-2); } }
/// <summary> /// Connect the instance /// </summary> private void Connect() { irc.Connect(); }