Skip to content

Commit

Permalink
Modes parser finished
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.origo.ethz.ch/ircddotnet/trunk@31 3fea7bcf-81c2-4a08-a3b7-d3cc9173df77
  • Loading branch information
FreeApophis committed Jun 3, 2010
1 parent ec5ac80 commit 15abd10
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 47 deletions.
116 changes: 92 additions & 24 deletions IrcD.Net/Modes/ChannelModeList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,67 @@ internal void Update(UserInfo info, ChannelInfo chan, IEnumerable<string> args)
plus = true;
}

var paramA = cmode as IParameterListA;
var paramB = cmode as IParameterB;
var paramC = cmode as IParameterC;
var iParam = cmode as IParameter;

if (paramA != null)
{

}
else if (paramB != null)
{

}
else if (paramC != null)
if (iParam != null)
{
var parameter = parameterTail.FirstOrDefault();
if (parameter != null)
{
parameterTail = parameterTail.Skip(1);
if (plus.Value)
{
if (!ContainsKey(cmode.Char))
{
Add(cmode);
}
((IParameter)this[cmode.Char]).Add(parameter);
if (lastprefix != '+')
{
validmode.Append(lastprefix = '+');
}
validmode.Append(cmode.Char);
validparam.Add(parameter);

}
else
{
if (ContainsKey(cmode.Char))
{
var paramA = cmode as IParameterListA;
if (paramA == null)
{
Remove(cmode.Char);
if (lastprefix != '-')
{
validmode.Append(lastprefix = '-');
}
validmode.Append(cmode.Char);
validparam.Add(parameter);
}
else
{
if (paramA.Parameter.Any(p => p == parameter))
{
paramA.Parameter.RemoveAll(p => p == parameter);
if (lastprefix != '-')
{
validmode.Append(lastprefix = '-');
}
validmode.Append(cmode.Char);
validparam.Add(parameter);
}
}
}
}
}
}
else if (cmode != null)
{
// Channel Mode without a parameter
if (plus.Value)
{
if (ContainsKey(cmode.Char))
{
continue;
}
else
if (!ContainsKey(cmode.Char))
{
Add(cmode);
if (lastprefix != '+')
Expand All @@ -147,11 +182,7 @@ internal void Update(UserInfo info, ChannelInfo chan, IEnumerable<string> args)
}
else
{
if (!ContainsKey(cmode.Char))
{
continue;
}
else
if (ContainsKey(cmode.Char))
{
Remove(cmode.Char);
if (lastprefix != '-')
Expand All @@ -160,12 +191,49 @@ internal void Update(UserInfo info, ChannelInfo chan, IEnumerable<string> args)
}
validmode.Append(cmode.Char);
}

}
}
else if (crank != null)
{
// Channel Rank (always need a parameter)
var parameter = parameterTail.FirstOrDefault();
if (parameter != null)
{
UserPerChannelInfo upci;
parameterTail = parameterTail.Skip(1);
if (chan.UserPerChannelInfos.TryGetValue(parameter, out upci))
{
if (plus.Value)
{
if (!upci.Modes.ContainsKey(crank.Char))
{
upci.Modes.Add(crank);
if (lastprefix != '+')
{
validmode.Append(lastprefix = '+');
}
validmode.Append(crank.Char);
validparam.Add(parameter);
}
}
else
{
if (upci.Modes.ContainsKey(crank.Char))
{
upci.Modes.Remove(crank.Char);
if (lastprefix != '-')
{
validmode.Append(lastprefix = '-');
}
validmode.Append(crank.Char);
validparam.Add(parameter);
}
}
}
else
{
info.IrcDaemon.Replies.SendUserNotInChannel(info, chan.Name, parameter);
}
}
}
else
{
Expand Down
11 changes: 8 additions & 3 deletions IrcD.Net/Modes/ChannelModes/IParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@

namespace IrcD.Modes.ChannelModes
{
public interface IParameterB
public interface IParameter
{
void Add(string parameter);
}

public interface IParameterB : IParameter
{
string Parameter { get; set; }
}

public interface IParameterC
public interface IParameterC : IParameter
{
string Parameter { get; set; }
}

public interface IParameterListA
public interface IParameterListA : IParameter
{
List<string> Parameter { get; }

Expand Down
5 changes: 5 additions & 0 deletions IrcD.Net/Modes/ChannelModes/ModeBan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@ public override bool HandleEvent(IrcCommandType ircCommand, ChannelInfo channel,
{
return true;
}

public void Add(string parameter)
{
banList.Add(parameter);
}
}
}
5 changes: 5 additions & 0 deletions IrcD.Net/Modes/ChannelModes/ModeBanException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public override bool HandleEvent(IrcCommandType ircCommand, ChannelInfo channel,
{
return true;
}

public void Add(string parameter)
{
banExceptionList.Add(parameter);
}
}
}

23 changes: 13 additions & 10 deletions IrcD.Net/Modes/ChannelModes/ModeInvite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


using System;
using System.Collections.Generic;
using IrcD.ServerReplies;

Expand All @@ -31,13 +29,8 @@ public ModeInvite()
: base('I')
{
}

public override bool HandleEvent(IrcCommandType ircCommand, ChannelInfo channel, UserInfo user, List<string> args)
{
return true;
}

private readonly List<string> inviteList = new List<string>();

public List<string> Parameter
{
get { return inviteList; }
Expand All @@ -47,9 +40,19 @@ public void SendList(UserInfo info, ChannelInfo chan)
{
foreach (var invite in inviteList)
{
info.IrcDaemon.Replies.SendExceptionList(info, chan, invite);
info.IrcDaemon.Replies.SendInviteList(info, chan, invite);
}
info.IrcDaemon.Replies.SendEndOfExceptionList(info, chan);
info.IrcDaemon.Replies.SendEndOfInviteList(info, chan);
}

public override bool HandleEvent(IrcCommandType ircCommand, ChannelInfo channel, UserInfo user, List<string> args)
{
return true;
}

public void Add(string parameter)
{
inviteList.Add(parameter);
}
}
}
5 changes: 5 additions & 0 deletions IrcD.Net/Modes/ChannelModes/ModeKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public override bool HandleEvent(IrcCommandType ircCommand, ChannelInfo channel,

return true;
}

public void Add(string parameter)
{
key = parameter;
}
}
}

20 changes: 16 additions & 4 deletions IrcD.Net/Modes/ChannelModes/ModeLimit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using IrcD.ServerReplies;

Expand All @@ -41,10 +42,16 @@ public string Parameter
}
set
{
if (int.TryParse(value, out limit))
{
limit = 0;
}
SetLimit(value);
}
}

private void SetLimit(string value)
{
int.TryParse(value, out limit);
if (limit < 1)
{
limit = 1;
}
}

Expand All @@ -61,5 +68,10 @@ public override bool HandleEvent(IrcCommandType ircCommand, ChannelInfo channel,
}
return true;
}

public void Add(string parameter)
{
SetLimit(parameter);
}
}
}
2 changes: 0 additions & 2 deletions IrcD.Net/Modes/ModeList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
*/

using System.Collections.Generic;
using System.Linq;
using System.Text;
using IrcD.Modes.ChannelModes;

namespace IrcD.Modes
{
Expand Down
6 changes: 2 additions & 4 deletions IrcD.Net/Modes/UserModes/ModeWallops.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@

namespace IrcD.Modes.UserModes
{
public class ModeWallops : UserMode
class ModeWallops : UserMode
{
public ModeWallops()
: base('w')
{

}
{ }

public override bool HandleEvent(IrcCommandType ircCommand, UserInfo user, List<string> args)
{
Expand Down
20 changes: 20 additions & 0 deletions IrcD.Net/ServerReplies/ServerReplies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,26 @@ public void SendNicknameInUse(UserInfo info, string nick)
info.WriteLine(response);
}


/// <summary>
/// Reply Code 441
/// </summary>
/// <param name="info"></param>
/// <param name="channel"></param>
/// <param name="nick"></param>
public void SendUserNotInChannel(UserInfo info, string channel, string nick)
{
BuildMessageHeader(info, ReplyCode.ErrorUserNotInChannel);

response.Append(" ");
response.Append(nick);
response.Append(" ");
response.Append(channel);
response.Append(" :They aren't on that channel");

info.WriteLine(response);
}

/// <summary>
/// Reply Code 442
/// </summary>
Expand Down

0 comments on commit 15abd10

Please sign in to comment.