Skip to content

Commit

Permalink
Modes added
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.origo.ethz.ch/ircddotnet/trunk@11 3fea7bcf-81c2-4a08-a3b7-d3cc9173df77
  • Loading branch information
FreeApophis committed May 20, 2010
1 parent 2e5248f commit f6b1604
Show file tree
Hide file tree
Showing 26 changed files with 664 additions and 67 deletions.
26 changes: 18 additions & 8 deletions IrcD.Net/Database/DatabaseCommon.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
/*
* Erstellt mit SharpDevelop.
* Benutzer: apophis
* Datum: 21.03.2010
* Zeit: 02:20
* The ircd.net project is an IRC deamon implementation for the .NET Plattform
* It should run on both .NET and Mono
*
* Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
* Copyright (c) 2009-2010 Thomas Bruderer <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Data.SQLite;

namespace IrcD.Database
Expand All @@ -16,13 +26,13 @@ namespace IrcD.Database
/// </summary>
public class DatabaseCommon
{
private static SQLiteConnection sqLiteConnection = new SQLiteConnection("Data Source=ircd.db;FailIfMissing=true;");
private static readonly SQLiteConnection SqLiteConnection = new SQLiteConnection("Data Source=ircd.db;FailIfMissing=true;");

private static Main db;

public static Main Db {
get {
return db = db ?? new Main(sqLiteConnection);
return db = db ?? new Main(SqLiteConnection);
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion IrcD.Net/IrcD.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,24 @@
<Compile Include="IrcDaemon.cs" />
<Compile Include="IrcServer.cs" />
<Compile Include="Modes\ChannelMode.cs" />
<Compile Include="Modes\ChannelModes\ModeBanException.cs" />
<Compile Include="Modes\ChannelModes\ModeBan.cs" />
<Compile Include="Modes\ChannelModes\ModeColorless.cs" />
<Compile Include="Modes\ChannelModes\ModeKey.cs" />
<Compile Include="Modes\ChannelModes\ModeLimit.cs" />
<Compile Include="Modes\ChannelModes\ModeModerated.cs" />
<Compile Include="Modes\ChannelModes\ModeNoExternal.cs" />
<Compile Include="Modes\ChannelModes\ModePrivate.cs" />
<Compile Include="Modes\ChannelModes\ModeSecret.cs" />
<Compile Include="Modes\ChannelModes\ModeTopic.cs" />
<Compile Include="Modes\ChannelRanks\ModeOp.cs" />
<Compile Include="Modes\ChannelRanks\ModeVoice.cs" />
<Compile Include="Modes\ChannelRank.cs" />
<Compile Include="Modes\Mode.cs" />
<Compile Include="Modes\ModeList.cs" />
<Compile Include="Modes\UserMode.cs" />
<Compile Include="Modes\UserModes\ModeInvisible.cs" />
<Compile Include="Modes\UserModes\ModeRestricted.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReplyCode.cs" />
Expand All @@ -97,7 +111,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Commands\" />
<Folder Include="Modes\UserModes\" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
Expand Down
53 changes: 46 additions & 7 deletions IrcD.Net/IrcDaemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
using System.Net;
using System.Net.Sockets;
using System.Text;
using IrcD.Modes;
using IrcD.Modes.ChannelModes;
using IrcD.Modes.ChannelRanks;
using IrcD.Modes.UserModes;
using IrcD.Utils;

namespace IrcD
Expand All @@ -45,6 +49,11 @@ class IrcDaemon
private readonly Dictionary<string, Socket> nicks = new Dictionary<string, Socket>();
private readonly Dictionary<string, CommandDelegate> commands = new Dictionary<string, CommandDelegate>(StringComparer.CurrentCultureIgnoreCase);

// Supported
private readonly ModeList<ChannelRank> supportedRanks = new ModeList<ChannelRank>();
private readonly ModeList<ChannelMode> supportedChannelModes = new ModeList<ChannelMode>();
private readonly ModeList<UserMode> supportedUserModes = new ModeList<UserMode>();

private bool connected = true;
private byte[] buffer = new byte[MaxBufferSize];
private EndPoint ep = new IPEndPoint(0, 0);
Expand Down Expand Up @@ -83,6 +92,26 @@ public IrcDaemon()
AddRfcOptCommands();
// Nonstandard IRC Commands
AddNonRfcCommands();
// Add Modes
AddModes();
}

private void AddModes()
{
supportedRanks.Add(new ModeVoice());
supportedRanks.Add(new ModeOp());

supportedChannelModes.Add(new ModeBan());
supportedChannelModes.Add(new ModeBanException());
supportedChannelModes.Add(new ModeColorless());
supportedChannelModes.Add(new ModeKey());
supportedChannelModes.Add(new ModeLimit());
supportedChannelModes.Add(new ModeModerated());
supportedChannelModes.Add(new ModeNoExternal());
supportedChannelModes.Add(new ModePrivate());

supportedUserModes.Add(new ModeInvisible());
supportedUserModes.Add(new ModeRestricted());
}

void AddNonRfcCommands()
Expand Down Expand Up @@ -282,7 +311,7 @@ public void Parser(string line, Socket sock, UserInfo info)
else
{
#if DEBUG
Console.WriteLine("Command " + command + "is not yet implemented");
Logger.Log("Command " + command + "is not yet implemented");
#endif

if (info.Registered)
Expand All @@ -295,13 +324,17 @@ public void Parser(string line, Socket sock, UserInfo info)
}

#if DEBUG
Console.WriteLine(line);
Console.Write("[" + info.Usermask + "]-[" + command + "]");
Logger.Log(line);
var parsedLine = new StringBuilder();
parsedLine.Append("[" + info.Usermask + "]-[" + command + "]");

foreach (string arg in args)
{
Console.Write("-<" + arg + ">");
parsedLine.Append("-<" + arg + ">");
}
Console.WriteLine();

Logger.Log(parsedLine.ToString());

#endif
}

Expand Down Expand Up @@ -571,8 +604,14 @@ private void SendMyInfo(UserInfo info)
commandSB.AppendFormat(NumericFormat, (int)ReplyCode.MyInfo);
commandSB.Append(" ");
commandSB.Append(info.Nick);
commandSB.Append(" :<servername> <version> <available user modes> <available channel modes>");
commandSB.Append(serverCreated);
commandSB.Append(" :");
commandSB.Append(Options.ServerName);
commandSB.Append(" ");
commandSB.Append("ircD.Net.<version> <available user modes> <available channel modes>");
commandSB.Append(" ");
commandSB.Append(supportedUserModes.ToString());
commandSB.Append(" ");
commandSB.Append(supportedRanks.ToString() + supportedChannelModes);
commandSB.Append(ServerCRLF);
info.Socket.Send(Encoding.UTF8.GetBytes(commandSB.ToString()));
}
Expand Down
4 changes: 0 additions & 4 deletions IrcD.Net/IrcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;

namespace IrcD
{
Expand Down
25 changes: 20 additions & 5 deletions IrcD.Net/Modes/ChannelMode.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/*
* The ircd.net project is an IRC deamon implementation for the .NET Plattform
* It should run on both .NET and Mono
*
* Copyright (c) 2009-2010 Thomas Bruderer <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace IrcD.Modes
{
class ChannelMode : Mode
public class ChannelMode : Mode
{
public ChannelMode(char mode)
: base(mode)
Expand Down
23 changes: 19 additions & 4 deletions IrcD.Net/Modes/ChannelModes/ModeBan.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/*
* The ircd.net project is an IRC deamon implementation for the .NET Plattform
* It should run on both .NET and Mono
*
* Copyright (c) 2009-2010 Thomas Bruderer <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace IrcD.Modes.ChannelModes
{
Expand Down
31 changes: 31 additions & 0 deletions IrcD.Net/Modes/ChannelModes/ModeBanException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* The ircd.net project is an IRC deamon implementation for the .NET Plattform
* It should run on both .NET and Mono
*
* Copyright (c) 2009-2010 Thomas Bruderer <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace IrcD.Modes.ChannelModes
{
class ModeBanException : ChannelMode
{
public ModeBanException()
: base('e')
{
}
}
}

31 changes: 31 additions & 0 deletions IrcD.Net/Modes/ChannelModes/ModeColorless.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* The ircd.net project is an IRC deamon implementation for the .NET Plattform
* It should run on both .NET and Mono
*
* Copyright (c) 2009-2010 Thomas Bruderer <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


namespace IrcD.Modes.ChannelModes
{
public class ModeColorless : ChannelMode
{
public ModeColorless()
: base('c')
{
}
}
}
31 changes: 31 additions & 0 deletions IrcD.Net/Modes/ChannelModes/ModeKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* The ircd.net project is an IRC deamon implementation for the .NET Plattform
* It should run on both .NET and Mono
*
* Copyright (c) 2009-2010 Thomas Bruderer <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace IrcD.Modes.ChannelModes
{
class ModeKey : ChannelMode
{
public ModeKey()
: base('k')
{
}
}
}

31 changes: 31 additions & 0 deletions IrcD.Net/Modes/ChannelModes/ModeLimit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* The ircd.net project is an IRC deamon implementation for the .NET Plattform
* It should run on both .NET and Mono
*
* Copyright (c) 2009-2010 Thomas Bruderer <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace IrcD.Modes.ChannelModes
{
public class ModeLimit : ChannelMode
{
public ModeLimit() :
base('l')
{

}
}
}
Loading

0 comments on commit f6b1604

Please sign in to comment.