I may move "Kelsier.Common" back into "Kelsier". I'm not yet sure.
*sigh*.
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; }
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");
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() {
}
}
- class InvalidStateException : Exception { }
+ public class InvalidStateException : Exception { }
- class Stator {
+ public class Stator {
public byte[] buffer = new byte[1];
public StringBuilder buffersb = new StringBuilder();
}
//
using System;
-namespace Kelsier {
+namespace Kelsier.Common {
public class Channel {
public string name { get; private set; }
public Channel(string name) {
//
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; }
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;
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));
}
}
}
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;
}
}
- class PlaceholdersException : Exception { }
+ public class PlaceholdersException : Exception { }
}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Kelsier.Common {
+ public class Hook {
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Kelsier.Common {
+ public delegate void HookCallback(Command ci);
+ public interface IModule {
+
+ }
+}
--- /dev/null
+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) {
+ }
+ }
+}
--- /dev/null
+<?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
--- /dev/null
+// 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();
+ }
+}
--- /dev/null
+// 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;
+ }
+ }
+}
+
--- /dev/null
+// 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));
+ }
+ }
+}
+
--- /dev/null
+// 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 { }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Kelsier {
+ public class Hook {
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Kelsier.Common {
+ public delegate void HookCallback(Command ci);
+ public interface IModule {
+
+ }
+}
--- /dev/null
+<?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
--- /dev/null
+// 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;
+ }
+ }
+}
--- /dev/null
+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>();
+ }
+ }
+}
--- /dev/null
+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")]
--- /dev/null
+// 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;
+ }
+ }
+}
+
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]; }
}
-
-
}
<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>
<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>
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
$3.inheritsScope = text/x-csharp
$3.scope = text/x-csharp
EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
EndGlobal
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; }
}
}
- class LogOutput {
+ public class LogOutput {
public TextWriter writer { get; private set; }
public bool open;
public LogOutput(TextWriter writer) {
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;
+ }
+ }
}
}
<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
//
using System;
-namespace Kelsier {
+namespace Kelsier.Common {
public class User {
public string nick { get; private set; }
public User(string nick) {
<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>