/* * Some ideal values when dealing with SQL: * All table names begin with the plugin's name, underscore, then its purpose. (e.g. memo_messages) * * Channels names are defined by RFC 1459 to be "of length up to 200 characters". * * Nicks don't appear to have standards. * RFC 2812 defines it as 9 characters max, but the UnrealIRCD server I'm on uses a 30 character limit. * * TODO: Learn PGSQL database limitations and best practices. Describe here. * * Old constraints: * channel varchar(200) -- Channel name, including leading '#' * nick varchar(50) -- User's nickname */ internal static NpgsqlConnection OpenPGSqlConnection(IniConfiguration conf) { string connectstring = "Host=" + conf["database.server"] + ";Username="******"database.username"] + ";Password="******"database.password"] + ";Database=" + conf["database.database"] + ";SearchPath=" + conf["database.schema"]; var db = new NpgsqlConnection(connectstring); db.Open(); return db; }
static int Main(string[] args) { string userConfigFile = null; // Parse parameters foreach (var arg in args) { #if DEBUG if (arg == "-ircdebug") IrcDebugToStdError = true; #endif if (arg.StartsWith("-config=")) { userConfigFile = arg.Substring(8); } } // Get configuration loaded IniConfiguration conf; string confPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar + (userConfigFile ?? "settings.ini"); try { conf = new IniConfiguration(confPath); } catch (FileNotFoundException) { if (userConfigFile == null) { using (StreamWriter wr = new StreamWriter(new FileStream(confPath, FileMode.Append), Encoding.UTF8)) { wr.WriteLine(Properties.Resources.ConfigTemplate); } Console.Error.WriteLine("Configuration file settings.ini was not found. A new one has been created for you."); Console.Error.WriteLine("Edit it to suit your needs and try again."); } else { Console.Error.WriteLine("Specified configuration file was not found."); } return 1; } // Prepare main class _q = new IRCQueueBot(conf); try { _q.LoadServices(); } catch (Exception) { // Despite an exception thrown, some logging events may have made it into the queue. // Continuing normally, exiting only after the queue has been cleared. _q.Enqueue(new ExitErrorSignal()); } _q.Enqueue(new BotStartSignal()); // Hook up console cancel handler and exception reporter Console.CancelKeyPress += Console_CancelKeyPress; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // Enter main loop return _q.RunQueue(); }
internal IRCQueueBot(IniConfiguration mainConfig) { _startTime = DateTime.Now; _conf = mainConfig; _queue = new BlockingCollection<Event>(new ConcurrentQueue<Event>()); }