]> jfr.im git - z_archive/kelsier.git/commitdiff
preparing for modules!
authorJohn Runyon <redacted>
Sun, 14 Apr 2013 17:15:55 +0000 (12:15 -0500)
committerJohn Runyon <redacted>
Sun, 14 Apr 2013 17:15:55 +0000 (12:15 -0500)
I may move "Kelsier.Common" back into "Kelsier". I'm not yet sure.
*sigh*.

27 files changed:
Bot.cs
Channel.cs
Command.cs
Database.cs
Hook.cs [new file with mode: 0644]
IModule.cs [new file with mode: 0644]
Info.cs [new file with mode: 0644]
Kelsier.Common.csproj [new file with mode: 0644]
Kelsier.Common/Bot.cs [new file with mode: 0644]
Kelsier.Common/Channel.cs [new file with mode: 0644]
Kelsier.Common/Command.cs [new file with mode: 0644]
Kelsier.Common/Database.cs [new file with mode: 0644]
Kelsier.Common/Hook.cs [new file with mode: 0644]
Kelsier.Common/IModule.cs [new file with mode: 0644]
Kelsier.Common/Kelsier.Common.csproj [new file with mode: 0644]
Kelsier.Common/Logger.cs [new file with mode: 0644]
Kelsier.Common/ModuleList.cs [new file with mode: 0644]
Kelsier.Common/Properties/AssemblyInfo.cs [new file with mode: 0644]
Kelsier.Common/User.cs [new file with mode: 0644]
Kelsier.cs
Kelsier.csproj
Kelsier.sln
Logger.cs
Properties/Settings.Designer.cs
Properties/Settings.settings
User.cs
app.config

diff --git a/Bot.cs b/Bot.cs
index 12ea5031d74e16bb90fe329814712b73642b3d69..3384faa6564e90b38c898f161b189cd1d868bcbd 100644 (file)
--- a/Bot.cs
+++ b/Bot.cs
@@ -27,8 +27,8 @@
 using System.Net;
 using System.Net.Sockets;
 
-namespace Kelsier {
-    class Bot {
+namespace Kelsier.Common {
+    public class Bot {
         public int id { get; private set; }
 
         public string nick { get; private set; }
@@ -49,9 +49,9 @@ class Bot {
         public Bot(int id) {
             this.id = id;
 
-            this.log = new Logger(id.ToString("0000"), Root.log);
+            this.log = new Logger(id.ToString("0000"), Info.log);
 
-            MySqlDataReader rdr = Root.db.queryReader("SELECT nick, ident, realname, bindip, server, serverport FROM bots WHERE id = @id", new object[] { "@id", id });
+            MySqlDataReader rdr = Info.db.queryReader("SELECT nick, ident, realname, bindip, server, serverport FROM bots WHERE id = @id", new object[] { "@id", id });
             rdr.Read();
 
             this.nick = rdr.GetString("nick");
@@ -153,7 +153,7 @@ class Bot {
                        
                        User user = new User(nick);
                        
-                       Command cmd = new Command(cmdstr, args, user, chan, chanmsg);
+                       Command cmd = new Command(this, cmdstr, args, user, chan, chanmsg);
                }
 
         private void register() {
@@ -163,9 +163,9 @@ class Bot {
         }
     }
 
-    class InvalidStateException : Exception { }
+    public class InvalidStateException : Exception { }
 
-    class Stator {
+    public class Stator {
         public byte[] buffer = new byte[1];
         public StringBuilder buffersb = new StringBuilder();
     }
index e194226e85ac04fd1888c09f7a3b14ec9f94df36..41ee5f2fa9d8c68446a489c0f886a93b3416e917 100644 (file)
@@ -20,7 +20,7 @@
 // 
 
 using System;
-namespace Kelsier {
+namespace Kelsier.Common {
        public class Channel {
                public string name { get; private set; }
                public Channel(string name) {
index 82abeedf6f8acf528af66c865b7909949840bb2d..fb48995cfce77b372272e50edbc157789f2081b0 100644 (file)
@@ -20,8 +20,9 @@
 // 
 
 using System;
-namespace Kelsier {
+namespace Kelsier.Common {
        public class Command {
+        public Bot bot { get; private set; }
                public string cmd { get; private set; }
                public string[] args { get; private set; }
                public User user { get; private set; }
@@ -29,7 +30,8 @@ public class Command {
                public bool chanmsg { get; private set; }
                public string replyTo { get; private set; }
                
-               public Command(string cmd, string[] args, User user, Channel chan, bool chanmsg) {
+               public Command(Bot bot, string cmd, string[] args, User user, Channel chan, bool chanmsg) {
+            this.bot = bot;
                        this.cmd = cmd;
                        this.args = args;
                        this.user = user;
@@ -39,8 +41,6 @@ public class Command {
                                this.replyTo = chan.name;
                        else
                                this.replyTo = user.nick;
-                       
-                       Root.log.debug(String.Format("cmd={0},args={1},user={2},chan={3},chanmsg={4},replyTo={5}", cmd, args.Length, user.nick, chan.name, chanmsg, replyTo));
                }
        }
 }
index cecc7eea200c9351acd01e52824498cec075cf18..463e608f924483cb8153948b2a78ea2b91b90c91 100644 (file)
@@ -24,8 +24,8 @@
 using System.Text;
 using MySql.Data.MySqlClient;
 
-namespace Kelsier {
-    class Database {
+namespace Kelsier.Common {
+    public class Database {
         public MySqlConnection dbh { get; private set; }
 
         private string dbinfo;
@@ -106,5 +106,5 @@ class Database {
         }
     }
 
-    class PlaceholdersException : Exception { }
+    public class PlaceholdersException : Exception { }
 }
diff --git a/Hook.cs b/Hook.cs
new file mode 100644 (file)
index 0000000..13a355e
--- /dev/null
+++ b/Hook.cs
@@ -0,0 +1,9 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Kelsier.Common {
+    public class Hook {
+    }
+}
diff --git a/IModule.cs b/IModule.cs
new file mode 100644 (file)
index 0000000..312e643
--- /dev/null
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Kelsier.Common {
+    public delegate void HookCallback(Command ci);
+    public interface IModule {
+
+    }
+}
diff --git a/Info.cs b/Info.cs
new file mode 100644 (file)
index 0000000..fc75fd7
--- /dev/null
+++ b/Info.cs
@@ -0,0 +1,51 @@
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Kelsier.Common {
+    static public class Info {
+        static public Database db;
+        static public Logger log;
+
+        static public string moduledir;
+
+        static private Dictionary<string, IModule> _modules = new Dictionary<string,IModule>();
+        static private Dictionary<string, Hook> _hooks = new Dictionary<string,Hook>();
+        static private Dictionary<int, Bot> _bots = new Dictionary<int,Bot>();
+
+        static public Dictionary<string, IModule> modules { get { return _modules; } }
+        static public Dictionary<string, Hook> hooks { get { return _hooks; } }
+        static public Dictionary<int, Bot> bots { get { return _bots; } }
+
+
+        static public void refreshmods() {
+            foreach (string name in Info.modules.Keys)
+                unloadmod(name);
+
+            string[] modulefiles;
+            modulefiles = Directory.GetFiles(moduledir + @"\autoload");
+
+            foreach (string file in modulefiles)
+                loadmodfile(file);
+        }
+
+        static public void loadmodfile(string file) {
+
+        }
+        static public void loadmod(string name) {
+            string filename = name + ".kel.dll";
+            if (File.Exists(moduledir + @"\autoload\" + filename))
+                loadmodfile(moduledir + @"\autoload\" + filename);
+            else if (File.Exists(moduledir + @"\" + filename))
+                loadmodfile(moduledir + @"\" + filename);
+            else
+                throw new FileNotFoundException();
+        }
+        static public void unloadmod(string name) {
+        }
+        static public void reloadmod(string name) {
+        }
+    }
+}
diff --git a/Kelsier.Common.csproj b/Kelsier.Common.csproj
new file mode 100644 (file)
index 0000000..48da753
--- /dev/null
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{57920460-A8DC-4862-8002-CE42C423DDBF}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Kelsier.Common</RootNamespace>
+    <AssemblyName>Kelsier.Common</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL" />
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Bot.cs" />
+    <Compile Include="Channel.cs" />
+    <Compile Include="Command.cs" />
+    <Compile Include="Database.cs" />
+    <Compile Include="Hook.cs" />
+    <Compile Include="IModule.cs" />
+    <Compile Include="Logger.cs" />
+    <Compile Include="Info.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="User.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file
diff --git a/Kelsier.Common/Bot.cs b/Kelsier.Common/Bot.cs
new file mode 100644 (file)
index 0000000..a94763e
--- /dev/null
@@ -0,0 +1,179 @@
+// Kelsier project - Bot state and parser code (Bot.cs)
+// Written by the Jobbig codeteam. <http://jobbig.eu/code/>
+// 
+// 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 <http://www.gnu.org/licenses/>.
+//
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MySql.Data.MySqlClient;
+using System.Net;
+using System.Net.Sockets;
+
+namespace Kelsier.Common {
+    public class Bot {
+        public int id { get; private set; }
+
+        public string nick { get; private set; }
+        public string ident { get; private set; }
+        public string realname { get; private set; }
+        public string localip { get; private set; }
+        public string server { get; private set; }
+        public int serverport { get; private set; }
+
+        private IPEndPoint local;
+
+        private Socket s;
+        public bool online { get; private set; }
+
+        public Logger log { get; private set; }
+        public Database db { get; private set; }
+
+        public char trigger;
+
+
+        public Bot(int id, Database db, Logger log) {
+            this.trigger = '!';
+
+            this.id = id;
+
+            this.log = new Logger(id.ToString("0000"), log);
+            this.db = db;
+
+            MySqlDataReader rdr = db.queryReader("SELECT nick, ident, realname, bindip, server, serverport FROM bots WHERE id = @id", new object[] { "@id", id });
+            rdr.Read();
+
+            this.nick = rdr.GetString("nick");
+            this.ident = rdr.GetString("ident");
+            this.realname = rdr.GetString("realname");
+
+            if (rdr.IsDBNull(rdr.GetOrdinal("bindip"))) {
+                this.localip = null;
+                this.local = new IPEndPoint(IPAddress.Any, 0);
+            } else {
+                this.localip = rdr.GetString("bindip");
+                this.local = new IPEndPoint(IPAddress.Parse(this.localip), 0);
+            }
+
+            this.server = rdr.GetString("server");
+            this.serverport = rdr.GetInt32("serverport");
+        }
+
+        public string connect() {
+            if (online) throw new InvalidStateException();
+
+            s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+            s.Bind(local);
+            s.Connect(server, serverport);
+                       
+                       register();
+
+            Stator rcvstate = new Stator();
+            s.BeginReceive(rcvstate.buffer, 0, 1, SocketFlags.None, new AsyncCallback(dataIn), rcvstate);
+
+            return "TODO";
+        }
+
+        public void dataIn(IAsyncResult ar) {
+            Stator rcvstate = (Stator)ar.AsyncState;
+            s.EndReceive(ar);
+
+            if (rcvstate.buffer[0] == '\n') {
+                               string linein = rcvstate.buffersb.ToString();
+                               processData(linein);
+                rcvstate = new Stator();
+            } else if (rcvstate.buffer[0] != '\r') {
+                rcvstate.buffersb.Append(Encoding.ASCII.GetString(rcvstate.buffer, 0, 1));
+            }
+            s.BeginReceive(rcvstate.buffer, 0, 1, SocketFlags.None, new AsyncCallback(dataIn), rcvstate);
+        }
+        private void send(string data, params object[] args) {
+            log.info(">>> " + data);
+            s.Send(Encoding.ASCII.GetBytes(data + "\n"));
+        }
+
+        private void processData(string data) {
+            log.info("<<< " + data);
+
+                       string[] parts;
+                       string source = null;
+                       if (data.StartsWith(":")) {
+                               parts = data.Split((char[])null, 2, StringSplitOptions.RemoveEmptyEntries);
+                               source = parts[0].Substring(1);
+                               data = parts[1];
+                       }
+                       
+                       parts = data.Split((char[])null, 2, StringSplitOptions.RemoveEmptyEntries);
+                       if (parts[0] == "PRIVMSG") {
+                               processMsg(source, parts[1]);
+                       } else if (parts[0] == "376") {
+                               send("JOIN #jobbig"); // TODO
+                       } else if (parts[0] == "PING") {
+                               send("PONG "+parts[1]);
+                       }
+        }
+               // processMsg("DimeCadmium!dime@jobbig.eu", "#mustis :hi");
+               private void processMsg(string source, string data) {
+                       string[] dataparts = data.Split((char[])null, 2, StringSplitOptions.RemoveEmptyEntries);
+                       
+                       string nick = (source.Split(new char[] { '!' }))[0];
+                       string target = dataparts[0];
+                       string message = dataparts[1];
+                       if (message.StartsWith(":"))
+                               message = message.Substring(1);
+                       string[] msgparts = message.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
+                       
+            if (msgparts[0][0] != trigger)
+                return;
+                       string cmdstr = msgparts[0].Substring(1);
+                       string[] args;
+                       bool chanmsg;
+                       Channel chan;
+                       if (target.StartsWith("#")) {
+                               chanmsg = true;
+                               args = new string[msgparts.Length - 1];
+                               Array.Copy(msgparts, 1, args, 0, msgparts.Length - 1);
+                               chan = new Channel(target);
+                       } else {
+                               chanmsg = false;
+                               args = new string[msgparts.Length - 2];
+                               Array.Copy(msgparts, 2, args, 0, msgparts.Length - 2);
+                               chan = new Channel(msgparts[1]);
+                       }
+                       
+                       User user = new User(nick);
+                       
+                       Command cmd = new Command(this, cmdstr, args, user, chan, chanmsg);
+               }
+
+        private void register() {
+            send(String.Format("NICK {0}", nick));
+            send(String.Format("USER {0} * * :{1}", ident, realname));
+            online = true;
+        }
+    }
+
+    public class InvalidStateException : Exception { }
+
+    public class Stator {
+        public byte[] buffer = new byte[1];
+        public StringBuilder buffersb = new StringBuilder();
+    }
+}
diff --git a/Kelsier.Common/Channel.cs b/Kelsier.Common/Channel.cs
new file mode 100644 (file)
index 0000000..41ee5f2
--- /dev/null
@@ -0,0 +1,31 @@
+// Kelsier project - Channel info code (Channel.cs)
+// Written by the Jobbig codeteam. <http://jobbig.eu/code/>
+// 
+// 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 <http://www.gnu.org/licenses/>.
+// 
+
+using System;
+namespace Kelsier.Common {
+       public class Channel {
+               public string name { get; private set; }
+               public Channel(string name) {
+                       this.name = name;
+               }
+       }
+}
+
diff --git a/Kelsier.Common/Command.cs b/Kelsier.Common/Command.cs
new file mode 100644 (file)
index 0000000..330734f
--- /dev/null
@@ -0,0 +1,49 @@
+// Kelsier project - Command info code (Command.cs)
+// Written by the Jobbig codeteam. <http://jobbig.eu/code/>
+// 
+// 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 <http://www.gnu.org/licenses/>.
+// 
+
+using System;
+namespace Kelsier.Common {
+       public class Command {
+        public Bot bot { get; private set; }
+               public string cmd { get; private set; }
+               public string[] args { get; private set; }
+               public User user { get; private set; }
+               public Channel chan { get; private set; }
+               public bool chanmsg { get; private set; }
+               public string replyTo { get; private set; }
+               
+               public Command(Bot bot, string cmd, string[] args, User user, Channel chan, bool chanmsg) {
+            this.bot = bot;
+                       this.cmd = cmd;
+                       this.args = args;
+                       this.user = user;
+                       this.chan = chan;
+                       this.chanmsg = chanmsg;
+                       if (chanmsg)
+                               this.replyTo = chan.name;
+                       else
+                               this.replyTo = user.nick;
+                       
+                       bot.log.debug(String.Format("cmd={0},args={1},user={2},chan={3},chanmsg={4},replyTo={5}", cmd, args.Length, user.nick, chan.name, chanmsg, replyTo));
+               }
+       }
+}
+
diff --git a/Kelsier.Common/Database.cs b/Kelsier.Common/Database.cs
new file mode 100644 (file)
index 0000000..463e608
--- /dev/null
@@ -0,0 +1,110 @@
+// Kelsier project - Database interaction code (Database.cs)
+// Written by the Jobbig codeteam. <http://jobbig.eu/code/>
+// 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 <http://www.gnu.org/licenses/>.
+//
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MySql.Data.MySqlClient;
+
+namespace Kelsier.Common {
+    public class Database {
+        public MySqlConnection dbh { get; private set; }
+
+        private string dbinfo;
+
+
+        /// <summary>
+        /// Construct a Database, using the MySQL connector string.
+        /// </summary>
+        /// <param name="dbinfo">Connector string</param>
+        public Database(string dbinfo) {
+            this.dbinfo = dbinfo;
+
+            dbh = new MySqlConnection(this.dbinfo);
+            dbh.Open();
+        }
+        public Database(Database copy) {
+            this.dbinfo = copy.dbinfo;
+
+            dbh = new MySqlConnection(this.dbinfo);
+            dbh.Open();
+        }
+
+        ~Database() {
+            dbh.Close();
+        }
+
+        public int execute(string query) {
+            MySqlCommand cmdo = new MySqlCommand(query, dbh);
+            return cmdo.ExecuteNonQuery();
+        }
+        public int execute(string query, object[] keys) {
+            MySqlCommand cmdo = new MySqlCommand();
+            cmdo.Connection = dbh;
+            cmdo.CommandText = query;
+            cmdo.Prepare();
+
+            for (int i = 0; i < keys.Length; i += 2) {
+                cmdo.Parameters.AddWithValue(keys[i].ToString(), keys[i + 1]);
+            }
+
+            return cmdo.ExecuteNonQuery();
+        }
+
+        public object queryScalar(string query) {
+            MySqlCommand cmdo = new MySqlCommand(query, dbh);
+            return cmdo.ExecuteScalar();
+        }
+        public object queryScalar(string query, object[] keys) {
+            MySqlCommand cmdo = new MySqlCommand();
+            cmdo.Connection = dbh;
+            cmdo.CommandText = query;
+            cmdo.Prepare();
+
+            for (int i = 0; i < keys.Length; i += 2) {
+                cmdo.Parameters.AddWithValue(keys[i].ToString(), keys[i + 1]);
+            }
+
+            return cmdo.ExecuteScalar();
+        }
+
+        public MySqlDataReader queryReader(string query) {
+            MySqlCommand cmdo = new MySqlCommand(query, dbh);
+            return cmdo.ExecuteReader();
+        }
+        public MySqlDataReader queryReader(string query, object[] keys) {
+            if (keys.Length % 2 != 0) {
+                throw new PlaceholdersException();
+            }
+            MySqlCommand cmdo = new MySqlCommand();
+            cmdo.Connection = dbh;
+            cmdo.CommandText = query;
+            cmdo.Prepare();
+
+            for (int i = 0; i < keys.Length; i += 2) {
+                cmdo.Parameters.AddWithValue(keys[i].ToString(), keys[i + 1]);
+            }
+            return cmdo.ExecuteReader();
+        }
+    }
+
+    public class PlaceholdersException : Exception { }
+}
diff --git a/Kelsier.Common/Hook.cs b/Kelsier.Common/Hook.cs
new file mode 100644 (file)
index 0000000..11df883
--- /dev/null
@@ -0,0 +1,9 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Kelsier {
+    public class Hook {
+    }
+}
diff --git a/Kelsier.Common/IModule.cs b/Kelsier.Common/IModule.cs
new file mode 100644 (file)
index 0000000..312e643
--- /dev/null
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Kelsier.Common {
+    public delegate void HookCallback(Command ci);
+    public interface IModule {
+
+    }
+}
diff --git a/Kelsier.Common/Kelsier.Common.csproj b/Kelsier.Common/Kelsier.Common.csproj
new file mode 100644 (file)
index 0000000..900d25d
--- /dev/null
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{57920460-A8DC-4862-8002-CE42C423DDBF}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Kelsier.Common</RootNamespace>
+    <AssemblyName>Kelsier.Common</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL" />
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Bot.cs" />
+    <Compile Include="Channel.cs" />
+    <Compile Include="Command.cs" />
+    <Compile Include="Database.cs" />
+    <Compile Include="IModule.cs" />
+    <Compile Include="Logger.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="User.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file
diff --git a/Kelsier.Common/Logger.cs b/Kelsier.Common/Logger.cs
new file mode 100644 (file)
index 0000000..1478662
--- /dev/null
@@ -0,0 +1,111 @@
+// Kelsier project - Logging code (Logger.cs)
+// Written by the Jobbig codeteam. <http://jobbig.eu/code/>
+// 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 <http://www.gnu.org/licenses/>.
+//
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+
+namespace Kelsier.Common {
+    public class Logger {
+        public LogOutput[] debugs { get; private set; }
+        public LogOutput[] infos { get; private set; }
+        public LogOutput[] errors { get; private set; }
+        public string from { get; private set; }
+
+        /// <summary>
+        /// Construct a Logger, writing to the specified TextWriter objects. Use an empty array to disable an output.
+        /// </summary>
+        /// <param name="debugs">Array of TextWriter's to use for debug output</param>
+        /// <param name="infos">...for info output</param>
+        /// <param name="errors">...for error output</param>
+        public Logger(string from, LogOutput[] debugs, LogOutput[] infos, LogOutput[] errors) {
+            int fromid;
+            if (Int32.TryParse(from, out fromid)) {
+                this.from = fromid.ToString("0000");
+            } else {
+                this.from = from;
+            }
+
+            this.debugs = debugs;
+            this.infos = infos;
+            this.errors = errors;
+
+            if (from == "Root") {
+                this.debug("Starting Root logging (debug) here at "+DateTime.Now.ToString("F"));
+                this.info("Starting Root logging (info) here at "+DateTime.Now.ToString("F"));
+                this.error("Starting Root logging (error) here at "+DateTime.Now.ToString("F"));
+            }
+        }
+        public Logger(string from, Logger copy) {
+            this.from = from;
+
+            this.debugs = copy.debugs;
+            this.infos = copy.infos;
+            this.errors = copy.infos;
+        }
+
+        /// <summary>
+        /// Debug logging.
+        /// </summary>
+        /// <param name="msg">Log message (with formatting placeholders, if desired)</param>
+        /// <param name="args">Formatting replacements.</param>
+        public void debug(object msg) {
+            foreach (LogOutput outw in debugs) {
+                if (outw.open)
+                    outw.writer.WriteLine("(D@" + DateTime.Now.ToString("HH:mm:ss") + ")[" + from + "] " + msg.ToString());
+            }
+        }
+
+        /// <summary>
+        /// Info logging.
+        /// </summary>
+        /// <param name="msg">Log message (with formatting placeholders, if desired)</param>
+        /// <param name="args">Formatting replacements.</param>
+        public void info(object msg) {
+            foreach (LogOutput outw in infos) {
+                if (outw.open)
+                    outw.writer.WriteLine("(I@" + DateTime.Now.ToString("HH:mm:ss") + ")[" + from + "] " + msg.ToString());
+            }
+        }
+
+        /// <summary>
+        /// Error logging.
+        /// </summary>
+        /// <param name="msg">Log message (with formatting placeholders, if desired)</param>
+        /// <param name="args">Formatting replacements.</param>
+        public void error(object msg) {
+            foreach (LogOutput outw in errors) {
+                if (outw.open)
+                    outw.writer.WriteLine("(E@" + DateTime.Now.ToString("HH:mm:ss") + ")[" + from + "] " + msg.ToString());
+            }
+        }
+    }
+
+    public class LogOutput {
+        public TextWriter writer { get; private set; }
+        public bool open;
+        public LogOutput(TextWriter writer) {
+            this.writer = writer;
+            this.open = true;
+        }
+    }
+}
diff --git a/Kelsier.Common/ModuleList.cs b/Kelsier.Common/ModuleList.cs
new file mode 100644 (file)
index 0000000..39da1c1
--- /dev/null
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Kelsier.Common {
+    public class ModuleList {
+        static public ModuleList() {
+            modules = new Dictionary<string, IModule>();
+            hooks = new Dictionary<string, Hook>();
+        }
+    }
+}
diff --git a/Kelsier.Common/Properties/AssemblyInfo.cs b/Kelsier.Common/Properties/AssemblyInfo.cs
new file mode 100644 (file)
index 0000000..3f152c7
--- /dev/null
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Kelsier.Common")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Kelsier.Common")]
+[assembly: AssemblyCopyright("Copyright ©  2013")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("598dab1a-6251-4341-be77-10a6c86e87d0")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Kelsier.Common/User.cs b/Kelsier.Common/User.cs
new file mode 100644 (file)
index 0000000..bb83019
--- /dev/null
@@ -0,0 +1,31 @@
+// Kelsier project - User info code (User.cs)
+// Written by the Jobbig codeteam. <http://jobbig.eu/code/>
+// 
+// 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 <http://www.gnu.org/licenses/>.
+// 
+
+using System;
+namespace Kelsier.Common {
+       public class User {
+               public string nick { get; private set; }
+               public User(string nick) {
+                       this.nick = nick;
+               }
+       }
+}
+
index 5b2c6616eaf6ebcd0e20916c34b7166c75133edb..fae9e6f3b254351f2f098700181df2ef0d7f72bb 100644 (file)
 using System.Text;
 using MySql.Data.MySqlClient;
 using System.IO;
+using Kelsier.Common;
 
 namespace Kelsier {
-    class Root {
-        static public Database db { get; private set; }
-        static public Logger log { get; private set; }
-
-        static private Dictionary<int, Bot> bots; // accessed by this.bot(int id)
+    static public class Root {
+        static void Main(string[] args) {
 
+            if (Properties.Settings.Default.datadir == ".")
+                Info.moduledir = Directory.GetCurrentDirectory() + @"\modules";
+            else
+                Info.moduledir = Properties.Settings.Default.datadir + @"\modules";
+            Info.refreshmods();
 
-        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);
+            Info.log = new Logger("Root", new LogOutput[] { new LogOutput(Console.Out) }, outputs, outputs);
 
-            db = new Database(Properties.Settings.Default.dbstr);
+            Info.db = new Database(Properties.Settings.Default.dbstr);
 
             List<int> botids = new List<int>();
-            MySqlDataReader rdr = db.queryReader("SELECT id FROM bots");
+            MySqlDataReader rdr = Info.db.queryReader("SELECT id FROM bots");
             while (rdr.Read()) {
                 botids.Add(rdr.GetInt32("id"));
             }
             rdr.Close();
-
-            bots = new Dictionary<int, Bot>();
             foreach (int key in botids) {
-                bots.Add(key, new Bot(key));
-                bots[key].connect();
+                Info.bots.Add(key, new Bot(key));
+                Info.bots[key].connect();
             }
 
             while (true) {
                 System.Threading.Thread.Sleep(2000);
             }
         }
-
-        static Bot bot(int id) { return bots[id]; }
     }
-
-
 }
index 1fd3b0d33d76ec2c45fd22bb55b807a0547cb4f9..cae6dd3decd48569f84827e05f71105752768fc8 100644 (file)
@@ -59,9 +59,6 @@
     <Reference Include="MySql.Data" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Bot.cs" />
-    <Compile Include="Database.cs" />
-    <Compile Include="Logger.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Properties\Settings.Designer.cs">
       <AutoGen>True</AutoGen>
@@ -69,9 +66,6 @@
       <DependentUpon>Settings.settings</DependentUpon>
     </Compile>
     <Compile Include="Kelsier.cs" />
-    <Compile Include="User.cs" />
-    <Compile Include="Command.cs" />
-    <Compile Include="Channel.cs" />
   </ItemGroup>
   <ItemGroup>
     <WCFMetadata Include="Service References\" />
       <Install>true</Install>
     </BootstrapperPackage>
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="Kelsier.Common.csproj">
+      <Project>{57920460-A8DC-4862-8002-CE42C423DDBF}</Project>
+      <Name>Kelsier.Common</Name>
+    </ProjectReference>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>
     <PostBuildEvent>
index a5f905bc4f0076212fef526fe0a86e36305c3ac8..ecaf8aebd739f9bd2c9682def96eb62d91b1c01f 100644 (file)
@@ -1,18 +1,43 @@
 
 Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual Studio 2010
+# Visual C# Express 2010
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kelsier", "Kelsier.csproj", "{64010C48-6927-4DA5-AE7F-0AD0301DC851}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kelsier.Common", "Kelsier.Common.csproj", "{57920460-A8DC-4862-8002-CE42C423DDBF}"
+EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|Any CPU = Debug|Any CPU
+               Debug|Mixed Platforms = Debug|Mixed Platforms
                Debug|x86 = Debug|x86
+               Release|Any CPU = Release|Any CPU
+               Release|Mixed Platforms = Release|Mixed Platforms
                Release|x86 = Release|x86
        EndGlobalSection
        GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {64010C48-6927-4DA5-AE7F-0AD0301DC851}.Debug|Any CPU.ActiveCfg = Debug|x86
+               {64010C48-6927-4DA5-AE7F-0AD0301DC851}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+               {64010C48-6927-4DA5-AE7F-0AD0301DC851}.Debug|Mixed Platforms.Build.0 = Debug|x86
                {64010C48-6927-4DA5-AE7F-0AD0301DC851}.Debug|x86.ActiveCfg = Debug|x86
                {64010C48-6927-4DA5-AE7F-0AD0301DC851}.Debug|x86.Build.0 = Debug|x86
+               {64010C48-6927-4DA5-AE7F-0AD0301DC851}.Release|Any CPU.ActiveCfg = Release|x86
+               {64010C48-6927-4DA5-AE7F-0AD0301DC851}.Release|Mixed Platforms.ActiveCfg = Release|x86
+               {64010C48-6927-4DA5-AE7F-0AD0301DC851}.Release|Mixed Platforms.Build.0 = Release|x86
                {64010C48-6927-4DA5-AE7F-0AD0301DC851}.Release|x86.ActiveCfg = Release|x86
                {64010C48-6927-4DA5-AE7F-0AD0301DC851}.Release|x86.Build.0 = Release|x86
+               {57920460-A8DC-4862-8002-CE42C423DDBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+               {57920460-A8DC-4862-8002-CE42C423DDBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+               {57920460-A8DC-4862-8002-CE42C423DDBF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+               {57920460-A8DC-4862-8002-CE42C423DDBF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+               {57920460-A8DC-4862-8002-CE42C423DDBF}.Debug|x86.ActiveCfg = Debug|Any CPU
+               {57920460-A8DC-4862-8002-CE42C423DDBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+               {57920460-A8DC-4862-8002-CE42C423DDBF}.Release|Any CPU.Build.0 = Release|Any CPU
+               {57920460-A8DC-4862-8002-CE42C423DDBF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+               {57920460-A8DC-4862-8002-CE42C423DDBF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+               {57920460-A8DC-4862-8002-CE42C423DDBF}.Release|x86.ActiveCfg = Release|Any CPU
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
        EndGlobalSection
        GlobalSection(MonoDevelopProperties) = preSolution
                StartupItem = Kelsier.csproj
@@ -33,7 +58,4 @@ Global
                $3.inheritsScope = text/x-csharp
                $3.scope = text/x-csharp
        EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
 EndGlobal
index 503e80c9086a9cf66050023044b10084d8eb749c..1478662206a5ebcecf81d3269922e33b8aeb6b27 100644 (file)
--- a/Logger.cs
+++ b/Logger.cs
@@ -24,9 +24,9 @@
 using System.Text;
 using System.IO;
 
-namespace Kelsier {
-    class Logger {
-        public LogOutput[] debugs {get; private set; }
+namespace Kelsier.Common {
+    public class Logger {
+        public LogOutput[] debugs { get; private set; }
         public LogOutput[] infos { get; private set; }
         public LogOutput[] errors { get; private set; }
         public string from { get; private set; }
@@ -100,7 +100,7 @@ class Logger {
         }
     }
 
-    class LogOutput {
+    public class LogOutput {
         public TextWriter writer { get; private set; }
         public bool open;
         public LogOutput(TextWriter writer) {
index 4635f71023e17b42b99f31e8d8e2b1d9718f6103..77d4c944d9235c18d5341a4022e481fd0aa17271 100644 (file)
@@ -34,5 +34,17 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio
                 this["dbstr"] = value;
             }
         }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute(".")]
+        public string datadir {
+            get {
+                return ((string)(this["datadir"]));
+            }
+            set {
+                this["datadir"] = value;
+            }
+        }
     }
 }
index ab3e2f04033e952ec387c9473ea9fb53a9eef5fc..b64b5b5ee5a50aa25df64a343f3d0222ddc968ea 100644 (file)
@@ -5,5 +5,8 @@
     <Setting Name="dbstr" Type="System.String" Scope="User">
       <Value Profile="(Default)">server=localhost;userid=kelsier;password=mistborn;database=kelsier</Value>
     </Setting>
+    <Setting Name="datadir" Type="System.String" Scope="User">
+      <Value Profile="(Default)">.</Value>
+    </Setting>
   </Settings>
 </SettingsFile>
\ No newline at end of file
diff --git a/User.cs b/User.cs
index 10ef1d5142a1cbd04138ba748c9a2cab781a9362..bb830196d7a0f710464f7533739aa1de120a9b08 100644 (file)
--- a/User.cs
+++ b/User.cs
@@ -20,7 +20,7 @@
 // 
 
 using System;
-namespace Kelsier {
+namespace Kelsier.Common {
        public class User {
                public string nick { get; private set; }
                public User(string nick) {
index b31a9d7c5ef4e36a0955d56d62de8441f7ae2234..86c96dce6367ceefde068d3fdd6dfae72e50c361 100644 (file)
@@ -10,6 +10,9 @@
             <setting name="dbstr" serializeAs="String">
                 <value>server=localhost;userid=kelsier;password=mistborn;database=kelsier</value>
             </setting>
+            <setting name="datadir" serializeAs="String">
+                <value>.</value>
+            </setting>
         </Kelsier.Properties.Settings>
     </userSettings>
 <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup></configuration>