]> jfr.im git - z_archive/kelsier.git/blob - Kelsier.cs
moar updates
[z_archive/kelsier.git] / Kelsier.cs
1 // Kelsier project - entrypoint and global state code (Kelsier.cs)
2 // Written by the Jobbig codeteam. <http://jobbig.eu/code/>
3 // Copyright 2013 John Runyon.
4 //
5 // This file is part of the Kelsier project.
6 //
7 // Kelsier is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
16 //
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 using System;
21 using System.Collections.Generic;
22 using System.Linq;
23 using System.Text;
24 using MySql.Data.MySqlClient;
25 using System.IO;
26
27 namespace Kelsier {
28 class Root {
29 static public Database db { get; private set; }
30 static public Logger log { get; private set; }
31
32 static private Dictionary<int, Bot> bots; // accessed by this.bot(int id)
33
34
35 static void Main(string[] args) {
36 StreamWriter fileout = new StreamWriter("kelsier.log", false);
37 fileout.AutoFlush = true;
38 LogOutput[] outputs = new LogOutput[] { new LogOutput(Console.Out), new LogOutput(fileout) };
39 log = new Logger("Root", new LogOutput[] { new LogOutput(Console.Out) }, outputs, outputs);
40
41 db = new Database(Properties.Settings.Default.dbstr);
42
43 List<int> botids = new List<int>();
44 MySqlDataReader rdr = db.queryReader("SELECT id FROM bots");
45 while (rdr.Read()) {
46 botids.Add(rdr.GetInt32("id"));
47 }
48 rdr.Close();
49
50 bots = new Dictionary<int, Bot>();
51 foreach (int key in botids) {
52 bots.Add(key, new Bot(key));
53 bots[key].connect();
54 }
55
56 while (true) {
57 System.Threading.Thread.Sleep(2000);
58 }
59 }
60
61 static Bot bot(int id) { return bots[id]; }
62 }
63
64
65 }