forked from FreeApophis/ircddotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://svn.origo.ethz.ch/ircddotnet/trunk@14 3fea7bcf-81c2-4a08-a3b7-d3cc9173df77
- Loading branch information
1 parent
a2a7541
commit 123286a
Showing
8 changed files
with
267 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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/>. | ||
*/ | ||
|
||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace IrcD.Commands | ||
{ | ||
public abstract class CommandBase | ||
{ | ||
protected CommandBase(IrcDaemon ircDaemon, string name) | ||
{ | ||
IrcDaemon = ircDaemon; | ||
this.name = name; | ||
} | ||
|
||
protected IrcDaemon IrcDaemon; | ||
protected StringBuilder Command; | ||
|
||
private readonly string name; | ||
|
||
public string Name | ||
{ | ||
get | ||
{ | ||
return name; | ||
} | ||
} | ||
|
||
public abstract void Handle(UserInfo info, List<string> args); | ||
public abstract void Send(InfoBase receiver, object[] args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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/>. | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Dynamic; | ||
using System.Linq; | ||
using System.Text; | ||
using IrcD.Utils; | ||
|
||
namespace IrcD.Commands | ||
{ | ||
|
||
public class CommandList : DynamicObject | ||
{ | ||
private readonly Dictionary<string, CommandBase> commandList = new Dictionary<string, CommandBase>(); | ||
|
||
public void Add(CommandBase command) | ||
{ | ||
commandList.Add(command.Name, command); | ||
} | ||
|
||
public void Handle(string command, UserInfo info, List<string> args) | ||
{ | ||
CommandBase commandObject; | ||
|
||
if (commandList.TryGetValue(command, out commandObject)) | ||
{ | ||
commandObject.Handle(info, args); | ||
} | ||
else | ||
{ | ||
#if DEBUG | ||
Logger.Log("Command " + command + "is not yet implemented"); | ||
#endif | ||
|
||
if (info.Registered) | ||
{ | ||
// we only inform the client about invalid commands if he is already successfully registered | ||
// we dont want to make "wrong protocol ping-pong" | ||
//TODO: | ||
//SendUnknownCommand(info, command); | ||
} | ||
|
||
} | ||
|
||
#if DEBUG | ||
var parsedLine = new StringBuilder(); | ||
parsedLine.Append("[" + info.Usermask + "]-[" + command + "]"); | ||
|
||
foreach (string arg in args) | ||
{ | ||
parsedLine.Append("-<" + arg + ">"); | ||
} | ||
|
||
Logger.Log(parsedLine.ToString()); | ||
|
||
#endif | ||
} | ||
|
||
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) | ||
{ | ||
try | ||
{ | ||
CommandBase command; | ||
|
||
if (commandList.TryGetValue(binder.Name, out command)) | ||
{ | ||
command.Send((InfoBase)args[0], args.Skip(1).ToArray()); | ||
} | ||
result = null; | ||
return true; | ||
} | ||
catch (Exception) | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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/>. | ||
*/ | ||
|
||
using System.Collections.Generic; | ||
namespace IrcD.Commands | ||
{ | ||
public class Ping : CommandBase | ||
{ | ||
public Ping(IrcDaemon ircDaemon) | ||
: base(ircDaemon, "PING") | ||
{ } | ||
|
||
public override void Handle(UserInfo info, List<string> args) | ||
{ | ||
if (!info.Registered) | ||
{ | ||
// SendNotRegistered(info); | ||
return; | ||
} | ||
|
||
IrcDaemon.Commands.Pong(); | ||
} | ||
|
||
public override void Send(InfoBase receiver, object[] args) | ||
{ | ||
Command.Length = 0; | ||
Command.Append(IrcDaemon.ServerPrefix); | ||
Command.Append(" PING "); | ||
|
||
receiver.WriteLine(Command); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.