// Kelsier project - entrypoint and global state code (Kelsier.cs) // Written by the Jobbig codeteam. // Copyright 2013 John Runyon. // // This file is part of the Kelsier project. // // Kelsier is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . using System; using System.Collections.Generic; using System.Linq; using System.Text; using MySql.Data.MySqlClient; using System.IO; namespace Kelsier { class Root { static public Database db { get; private set; } static public Logger log { get; private set; } static private Dictionary bots; // accessed by this.bot(int id) static void Main(string[] args) { StreamWriter fileout = new StreamWriter("kelsier.log", false); fileout.AutoFlush = true; LogOutput[] outputs = new LogOutput[] { new LogOutput(Console.Out), new LogOutput(fileout) }; log = new Logger("Root", new LogOutput[] { new LogOutput(Console.Out) }, outputs, outputs); db = new Database(Properties.Settings.Default.dbstr); List botids = new List(); MySqlDataReader rdr = db.queryReader("SELECT id FROM bots"); while (rdr.Read()) { botids.Add(rdr.GetInt32("id")); } rdr.Close(); bots = new Dictionary(); foreach (int key in botids) { bots.Add(key, new Bot(key)); bots[key].connect(); } while (true) { System.Threading.Thread.Sleep(2000); } } static Bot bot(int id) { return bots[id]; } } }