Modified:
trunk/Client/Channel.cs
trunk/Client/Client.cs
trunk/Client/Events.cs
trunk/Client/Mode.cs
trunk/Client/ModeMap.cs
trunk/Client/Nickname.cs
Log:
FxCop compatibility restored. Minor other changes that I can't all remember.
Modified: trunk/Client/Channel.cs
==============================================================================
--- trunk/Client/Channel.cs (original)
+++ trunk/Client/Channel.cs Thu Jul 26 21:55:18 2007
@@ -18,7 +18,7 @@
banlist = new List<Nickname>(),
invitelist = new List<Nickname>(),
exceptlist = new List<Nickname>();
- private ModeContainer modes = new ModeContainer();
+ private ModeCollection modes = new ModeCollection();
private string topic = String.Empty;
private string key = String.Empty;
private int limit = Int32.MaxValue;
@@ -35,13 +35,16 @@
public string Key {
get { return key; }
}
+ public int Limit {
+ get { return limit; }
+ }
public DateTime TopicSetTime {
get { return lastSet; }
}
public Nickname TopicSetter {
get { return topicSetter; }
}
- public ModeContainer Mode {
+ public ModeCollection Mode {
get { return modes; }
}
public Collection<Nickname> Nicknames {
@@ -74,15 +77,15 @@
this.owner = owner;
this.name = name;
}
- internal void AddModeChange(Nickname sender, Mode mode, ModeOperations op)
+ internal void AddModeChange(Nickname sender, Mode mode, ModeOperation op)
{
- if(op == ModeOperations.Add)
+ if(op == ModeOperation.Add)
this.modes += mode;
- else if(op == ModeOperations.Remove)
+ else if(op == ModeOperation.Remove)
this.modes -= mode;
- if(mode.ModeType == Modes.Limit)
+ if(mode.ModeType == ModeName.Limit)
limit = ((IntMode)mode).Parameter;
- if(mode.ModeType == Modes.Key)
+ if(mode.ModeType == ModeName.Key)
key = ((StringMode)mode).Parameter;
ModeEventArgs e = new ModeEventArgs();
e.Mode = mode;
@@ -159,12 +162,13 @@
if(PublicAction != null)
PublicAction(this, e);
}
- internal void OnJoinNicklist(Nickname[] list)
+ internal void OnJoinNicklist(Collection<Nickname> list)
{
nicknames.AddRange(list);
NicklistEventArgs e = new NicklistEventArgs();
e.Channel = this;
- e.Nicklist = list;
+ foreach(Nickname entry in list)
+ e.Nicklist.Add(entry);
if(Nicklist != null)
Nicklist(this, e);
}
@@ -196,23 +200,23 @@
{
string message = String.Empty;
Owner.SendMessage(String.Format(System.Globalization.CultureInfo.CurrentCulture, Strings.PartMessage, name));
- if(HasMode(Modes.Key)) message = Strings.JoinWithPassMessage;
+ if(HasMode(ModeName.Key)) message = Strings.JoinWithPassMessage;
else message = Strings.JoinWithoutPassMessage;
Owner.SendMessage(String.Format(System.Globalization.CultureInfo.CurrentCulture, message, Name, key));
}
public void SetMode(Mode mode)
{
- ChangeMode(mode, ModeOperations.Add);
+ ChangeMode(mode, ModeOperation.Add);
}
public void UnsetMode(Mode mode)
{
- ChangeMode(mode, ModeOperations.Remove);
+ ChangeMode(mode, ModeOperation.Remove);
}
- public void ChangeMode(Mode mode, ModeOperations op)
+ public void ChangeMode(Mode mode, ModeOperation op)
{
- Owner.ChangeMode(Name, mode, op);
+ Owner.ChangeMode(mode, op);
}
- public bool HasMode(Modes mode)
+ public bool HasMode(ModeName mode)
{
return Mode.HasMode(mode);
}
Modified: trunk/Client/Client.cs
==============================================================================
--- trunk/Client/Client.cs (original)
+++ trunk/Client/Client.cs Thu Jul 26 21:55:18 2007
@@ -6,6 +6,7 @@
using System.Net.Security;
using System.Globalization;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
@@ -15,8 +16,6 @@
public sealed class Client : IDisposable
{
#region public attributes
- public static Dictionary<Modes, string> SymbolTable = new Dictionary<Modes, string>();
- public static Dictionary<string, Modes> ModeTable = new Dictionary<string,Modes>();
public string Server {
get { return server; }
set { server = value; }
@@ -116,7 +115,7 @@
new Thread(delegate() { TopicChange(this, e); }).Start();
new Thread(delegate(){channel.AddTopic(sender, topic, time);}).Start();
}
- private void OnModeChange(Nickname sender, Mode mode, ModeOperations op)
+ private void OnModeChange(Nickname sender, Mode mode, ModeOperation op)
{
ModeEventArgs e = new ModeEventArgs();
e.Sender = sender;
@@ -279,11 +278,12 @@
if(ErrorMessage != null)
new Thread(delegate() { ErrorMessage(this, e); }).Start();
}
- private void OnNicklist(Channel channel, Nickname[] list)
+ private void OnNicklist(Channel channel, Collection<Nickname> list)
{
NicklistEventArgs e = new NicklistEventArgs();
e.Channel = channel;
- e.Nicklist = list;
+ foreach(Nickname entry in list)
+ e.Nicklist.Add(entry);
if(Nicklist != null)
new Thread(delegate(){Nicklist(this, e);}).Start();
new Thread(delegate(){channel.OnJoinNicklist(list);}).Start();
@@ -305,7 +305,7 @@
private RemoteCertificateValidationCallback Sslcertvalidator;
private bool abort;
private bool debug;
- private bool registered = false;
+ private bool registered;
#endregion
#region public methods
/// <summary>
@@ -430,7 +430,7 @@
throw new ArgumentNullException("action");
else if(message == null)
throw new ArgumentNullException("message");
- else throw new ArgumentException();
+ else throw new ArgumentNullException("target");
}
/// <summary>
///
@@ -494,23 +494,28 @@
/// <param name="target"></param>
/// <param name="mode"></param>
/// <param name="op"></param>
- public void ChangeMode(string target, Mode mode, ModeOperations op)
+ public void ChangeMode(Mode mode, ModeOperation op)
{
- if(mode is NicknameMode)
+ NicknameMode nm;
+ StringMode sm;
+ IntMode im;
+ if((nm = mode as NicknameMode) != null)
+ {
SendMessage(String.Format(CultureInfo.CurrentCulture, Strings.ModeWithParamsMessage,
- mode.Target.ToString(), (op == ModeOperations.Add ? "+" : "-") + ModeMap.Instance.ModeToCharTable[mode.ModeType],
- ((NicknameMode)mode).Parameter));
- else if(mode is StringMode)
+ mode.Target.ToString(), (op == ModeOperation.Add ? "+" : "-") + ModeMap.Instance.ModeToCharTable[mode.ModeType],
+ nm.Parameter));
+ }
+ else if((sm = mode as StringMode) != null)
SendMessage(String.Format(CultureInfo.CurrentCulture, Strings.ModeWithParamsMessage,
- mode.Target.ToString(), (op == ModeOperations.Add ? "+" : "-") + ModeMap.Instance.ModeToCharTable[mode.ModeType],
- ((StringMode)mode).Parameter));
- else if(mode is IntMode)
+ mode.Target.ToString(), (op == ModeOperation.Add ? "+" : "-") + ModeMap.Instance.ModeToCharTable[mode.ModeType],
+ sm.Parameter));
+ else if((im = mode as IntMode) != null)
SendMessage(String.Format(CultureInfo.CurrentCulture, Strings.ModeWithParamsMessage,
- mode.Target.ToString(), (op == ModeOperations.Add ? "+" : "-") + ModeMap.Instance.ModeToCharTable[mode.ModeType],
- ((IntMode)mode).Parameter));
+ mode.Target.ToString(), (op == ModeOperation.Add ? "+" : "-") + ModeMap.Instance.ModeToCharTable[mode.ModeType],
+ im.Parameter));
else
SendMessage(String.Format(CultureInfo.CurrentCulture, Strings.ModeWithoutParamsMessage,
- mode.Target.ToString(), (op == ModeOperations.Add ? "+" : "-") + ModeMap.Instance.ModeToCharTable[mode.ModeType]));
+ mode.Target.ToString(), (op == ModeOperation.Add ? "+" : "-") + ModeMap.Instance.ModeToCharTable[mode.ModeType]));
}
/// <summary>
///
@@ -602,7 +607,7 @@
string[] messageParts = message.Split(new char[]{' '}, 4);
if(messageParts.Length == 2)
{
- // ping/pong event
+ // ping/pong event, so we just parse it and be done since it's a short and simple message
OnPing(messageParts[1].Substring(1));
}
if(messageParts.Length >= 3)
@@ -776,7 +781,7 @@
if(name.StartsWith(":"))
name = name.Substring(1);
string temp = name.ToUpperInvariant();
- List<Modes> tmpmode = new List<Modes>();
+ List<ModeName> tmpmode = new List<ModeName>();
while(temp[0] < 65 || temp[0] > 90)
{
// ordinarily we parse the mode here, but that can't happen until we figure out the modes possible from the server
@@ -784,7 +789,7 @@
name = name.Substring(1);
temp = name.ToUpperInvariant();
}
- args.Nicklist = new Nickname[] {new Nickname(name, tmpmode.ToArray())};
+ args.Nicklist.Add(new Nickname(name, tmpmode.ToArray()));
}
}
else if(action.CompareTo("366") == 0)
@@ -807,7 +812,7 @@
#region mode change
else if(action.CompareTo("mode") == 0)
{
- ModeOperations op = ModeOperations.Add;
+ ModeOperation op = ModeOperation.Add;
Mode mode = null;
string[] modeParts = messageParts[3].Split(' ');
string modes = modeParts[0];
@@ -826,8 +831,8 @@
{
switch(c)
{
- case '+': op = ModeOperations.Add; break;
- case '-': op = ModeOperations.Remove; break;
+ case '+': op = ModeOperation.Add; break;
+ case '-': op = ModeOperation.Remove; break;
default:
if((modes.Length - i) == parameters.Length)
{
@@ -835,23 +840,20 @@
Nickname tmpnick;
if(Int32.TryParse(parameters[(modes.Length-i-1)], out result))
mode = new IntMode(channel, ModeMap.Instance.CharToModeTable[c], result);
- else if(global::Irc.Nickname.TryParse(parameters[(modes.Length-i-1)], out tmpnick))
+ else if(Irc.Nickname.TryParse(parameters[(modes.Length-i-1)], out tmpnick))
mode = new NicknameMode(channel, ModeMap.Instance.CharToModeTable[c], tmpnick);
else
mode = new StringMode(channel, ModeMap.Instance.CharToModeTable[c], parameters[(modes.Length-i-1)]);
- OnModeChange(nick, mode, op);
- }
- else
+
+ } else
{
mode = new Mode(channel, ModeMap.Instance.CharToModeTable[c]);
- OnModeChange(nick, mode, op);
}
break;
}
i++;
}
- }
- else
+ } else
{
// user mode
Nickname user = new Nickname(messageParts[2]);
@@ -860,8 +862,8 @@
{
switch(c)
{
- case '+': op = ModeOperations.Add; break;
- case '-': op = ModeOperations.Remove; break;
+ case '+': op = ModeOperation.Add; break;
+ case '-': op = ModeOperation.Remove; break;
default:
if((modes.Length - i) == parameters.Length)
{
@@ -874,8 +876,7 @@
else
mode = new StringMode(user, ModeMap.Instance.CharToModeTable[c], parameters[(modes.Length-i-1)]);
OnModeChange(nick, mode, op);
- }
- else
+ } else
{
mode = new Mode(user, ModeMap.Instance.CharToModeTable[c]);
OnModeChange(nick, mode, op);
Modified: trunk/Client/Events.cs
==============================================================================
--- trunk/Client/Events.cs (original)
+++ trunk/Client/Events.cs Thu Jul 26 21:55:18 2007
@@ -10,18 +10,6 @@
public abstract override string ToString();
}
- //internal interface ParameterizedModeEventArgs
- //{
- // string Parameter { get; set; }
- //}
- //internal interface ChannelMode
- //{
- // Channel Target { get; set; }
- //}
- //internal interface UserMode
- //{
- // Nickname Target { get; set; }
- //}
internal interface ChannelMessage
{
Channel Target { get; set; }
@@ -36,7 +24,7 @@
{
private Nickname sender;
private Mode mode;
- private ModeOperations op;
+ private ModeOperation op;
public Nickname Sender
{
@@ -48,64 +36,11 @@
get { return mode; }
set { mode = value; }
}
- public ModeOperations Operation {
+ public ModeOperation Operation {
get { return op; }
set { op = value; }
}
}
- //[CLSCompliant(true)]
- //public sealed class ParameterizedChannelModeEventArgs : ModeEventArgs, ParameterizedModeEventArgs, ChannelMode
- //{
- // private string parameter;
- // private Channel channel;
- // public string Parameter
- // {
- // get { return parameter; }
- // set { parameter = value; }
- // }
- // public Channel Target
- // {
- // get { return channel; }
- // set { channel = value; }
- // }
- //}
- //[CLSCompliant(true)]
- //public sealed class ChannelModeEventArgs : ModeEventArgs, ChannelMode
- //{
- // private Channel target;
- // public Channel Target
- // {
- // get { return target; }
- // set { target = value; }
- // }
- //}
- //[CLSCompliant(true)]
- //public sealed class ParameterizedUserModeEventArgs : ModeEventArgs, ParameterizedModeEventArgs, UserMode
- //{
- // private string parameter;
- // private Nickname target;
- // public string Parameter
- // {
- // get { return parameter; }
- // set { parameter = value; }
- // }
- // public Nickname Target
- // {
- // get { return target; }
- // set { target = value; }
- // }
- //}
- //[CLSCompliant(true)]
- //public sealed class UserModeEventArgs : ModeEventArgs, UserMode
- //{
- // private Nickname target;
- // public Nickname Target
- // {
- // get { return target; }
- // set { target = value; }
- // }
- //}
-
[CLSCompliant(true)]
public class MessageEventArgs : EventArgs
{
@@ -150,11 +85,13 @@
private Nickname oldNick;
private Nickname newNick;
- public Nickname OldNick {
+ public Nickname OldNick
+ {
get { return oldNick; }
set { oldNick = value; }
}
- public Nickname NewNick {
+ public Nickname NewNick
+ {
get { return newNick; }
set { newNick = value; }
}
@@ -165,11 +102,13 @@
private string server;
private string message;
- public string Server {
+ public string Server
+ {
get { return server; }
set { server = value; }
}
- public string Message {
+ public string Message
+ {
get { return message; }
set { message = value; }
}
@@ -182,19 +121,23 @@
private DateTime time;
private string newTopic;
- public Channel Channel {
+ public Channel Channel
+ {
get { return channel; }
set { channel = value; }
}
- public Nickname Sender {
+ public Nickname Sender
+ {
get { return sender; }
set { sender = value; }
}
- public DateTime Time {
+ public DateTime Time
+ {
get { return time; }
set { time = value; }
}
- public string NewTopic {
+ public string NewTopic
+ {
get { return newTopic; }
set { newTopic = value; }
}
@@ -204,7 +147,8 @@
{
private string key;
- public string Key {
+ public string Key
+ {
get { return key; }
set { key = value; }
}
@@ -214,7 +158,8 @@
{
private string rawMessage;
- public string RawMessage {
+ public string RawMessage
+ {
get { return rawMessage; }
set { rawMessage = value; }
}
@@ -226,15 +171,18 @@
private JoinMode mode;
private Channel channel;
- public Nickname User {
+ public Nickname User
+ {
get { return user; }
set { user = value; }
}
- public Channel Channel {
+ public Channel Channel
+ {
get { return channel; }
set { channel = value; }
}
- public JoinMode Mode {
+ public JoinMode Mode
+ {
get { return mode; }
set { mode = value; }
}
@@ -245,11 +193,13 @@
private string server;
private int port;
- public string Server {
+ public string Server
+ {
get { return server; }
set { server = value; }
}
- public int Port {
+ public int Port
+ {
get { return port; }
set { port = value; }
}
@@ -260,11 +210,13 @@
private string server;
private string motd;
- public string Server {
+ public string Server
+ {
get { return server; }
set { server = value; }
}
- public string Motd {
+ public string Motd
+ {
get { return motd; }
set { motd = value; }
}
@@ -295,13 +247,12 @@
[CLSCompliant(true)]
public sealed class NicklistEventArgs : EventArgs
{
- private List<Nickname> nicklist = new List<Nickname>();
+ private Collection<Nickname> nicklist = new Collection<Nickname>();
private Channel channel;
- public Nickname[] Nicklist
+ public Collection<Nickname> Nicklist
{
- get { return nicklist.ToArray(); }
- set { nicklist.AddRange(value); }
+ get { return nicklist; }
}
public Channel Channel
{
Modified: trunk/Client/Mode.cs
==============================================================================
--- trunk/Client/Mode.cs (original)
+++ trunk/Client/Mode.cs Thu Jul 26 21:55:18 2007
@@ -5,12 +5,12 @@
namespace Irc
{
- public enum ModeOperations
+ public enum ModeOperation
{
Add,
Remove
}
- public enum Modes
+ public enum ModeName
{
None,
TopicOperatorOnly,
@@ -25,28 +25,27 @@
HiddenHostmask,
Owner,
Protected,
- Op,
- HalfOp,
+ Operator,
+ HalfOperator,
Voice,
Devoice
}
[CLSCompliant(true)]
public class Mode
{
- public Mode(Target t, Modes m)
+ public Mode(Target target, ModeName modes)
{
- target = t;
- mode = m;
+ this.target = target;
+ mode = modes;
}
private Target target;
- private Modes mode;
+ private ModeName mode;
public override bool Equals(object obj)
{
- if(!(obj is Mode))
- return false;
- else
- return ((Mode)obj).ModeType == mode && ((Mode)obj).Target == target;
+ Mode m = obj as Mode;
+ if(m == null) return false;
+ return m.ModeType == mode && m.Target == target;
}
public override int GetHashCode()
{
@@ -55,7 +54,7 @@
public Target Target {
get { return target; }
}
- public Modes ModeType
+ public ModeName ModeType
{
get { return mode; }
}
@@ -63,16 +62,15 @@
[CLSCompliant(true)]
public class NicknameMode : Mode
{
- public NicknameMode(Target t, Modes m, Nickname p) : base(t, m)
+ public NicknameMode(Target target, ModeName modes, Nickname param) : base(target, modes)
{
- parameter = p;
+ parameter = param;
}
public override bool Equals(object obj)
{
- if(!(obj is NicknameMode))
- return false;
- else
- return ((NicknameMode)obj).Parameter == parameter && base.Equals(obj);
+ NicknameMode m = obj as NicknameMode;
+ if(m == null) return false;
+ return m.Parameter == parameter && base.Equals(obj);
}
public override int GetHashCode()
{
@@ -86,16 +84,15 @@
[CLSCompliant(true)]
public class IntMode : Mode
{
- public IntMode(Target t, Modes m, int p) : base(t, m)
+ public IntMode(Target target, ModeName modes, int param) : base(target, modes)
{
- parameter = p;
+ parameter = param;
}
public override bool Equals(object obj)
{
- if(!(obj is IntMode))
- return false;
- else
- return ((IntMode)obj).Parameter == parameter && base.Equals(obj);
+ IntMode m = obj as IntMode;
+ if(m == null) return false;
+ return m.Parameter == parameter && base.Equals(obj);
}
public override int GetHashCode()
{
@@ -109,16 +106,15 @@
[CLSCompliant(true)]
public class StringMode : Mode
{
- public StringMode(Target t, Modes m, string p) : base (t, m)
+ public StringMode(Target target, ModeName modes, string param) : base (target, modes)
{
- parameter = p;
+ parameter = param;
}
public override bool Equals(object obj)
{
- if(!(obj is StringMode))
- return false;
- else
- return ((StringMode)obj).Parameter == parameter && base.Equals(obj);
+ StringMode m = obj as StringMode;
+ if(m == null) return false;
+ return m.Parameter == parameter && base.Equals(obj);
}
public override int GetHashCode()
{
@@ -130,31 +126,41 @@
}
}
[CLSCompliant(true)]
- public class ModeContainer : IComparable<ModeContainer>, IEnumerable<Mode>
+ public class ModeCollection : IComparable<ModeCollection>, IEnumerable<Mode>
{
private List<Mode> modes = new List<Mode>();
public Collection<Mode> ModeList {
get { return new Collection<Mode>(modes); }
}
- public static ModeContainer operator +(ModeContainer container, Mode mode)
+ public ModeCollection Add(Mode mode)
{
- ModeContainer cont = new ModeContainer();
+ return this + mode;
+ }
+ public ModeCollection Subtract(Mode mode)
+ {
+ return this - mode;
+ }
+ public static ModeCollection operator +(ModeCollection container, Mode mode)
+ {
+ ModeCollection cont = new ModeCollection();
cont.modes.AddRange(container.ModeList);
cont.modes.Add(mode);
return cont;
}
- public static ModeContainer operator -(ModeContainer container, Mode mode)
+ public static ModeCollection operator -(ModeCollection container, Mode mode)
{
- ModeContainer cont = new ModeContainer();
+ ModeCollection cont = new ModeCollection();
cont.modes.AddRange(container.ModeList);
cont.modes.Remove(mode);
return cont;
}
- public static implicit operator string(ModeContainer m)
+ public static implicit operator string(ModeCollection modes)
{
- return m.ToString();
+ if(modes != null)
+ return modes.ToString();
+ else return String.Empty;
}
- public static bool operator ==(ModeContainer cont1, ModeContainer cont2)
+ public static bool operator ==(ModeCollection cont1, ModeCollection cont2)
{
if(cont1 == null || cont2 == null)
if(cont1 == null && cont2 == null)
@@ -166,7 +172,7 @@
return false;
return true;
}
- public static bool operator !=(ModeContainer cont1, ModeContainer cont2)
+ public static bool operator !=(ModeCollection cont1, ModeCollection cont2)
{
return !(cont1 == cont2);
}
@@ -176,9 +182,9 @@
}
public override bool Equals(object obj)
{
- return this == (ModeContainer)obj;
+ return this == (ModeCollection)obj;
}
- public bool HasMode(Modes mode)
+ public bool HasMode(ModeName mode)
{
foreach(Mode m in ModeList)
if(m.ModeType == mode)
@@ -189,16 +195,16 @@
{
return ToString("G", System.Globalization.CultureInfo.CurrentCulture);
}
- public string ToString(string p)
+ public string ToString(string format)
{
- return ToString(p, System.Globalization.CultureInfo.CurrentCulture);
+ return ToString(format, System.Globalization.CultureInfo.CurrentCulture);
}
- public string ToString(string p, IFormatProvider fp)
+ public string ToString(string format, IFormatProvider formatProvider)
{
if(ModeMap.Instance.ModeToCharTable.Count == 0 || ModeMap.Instance.ModeToSymbolTable.Count == 0)
throw new FormatException("Tables unavailable!");
string ret = String.Empty;
- switch(p)
+ switch(format)
{
case "G": case null:
foreach(Mode mode in modes)
@@ -210,16 +216,16 @@
}
break;
case "S": case "s":
- if(HasMode(Modes.None)) ret = "";
- if(HasMode(Modes.Devoice)) ret = "-";
- if(HasMode(Modes.Voice)) ret = "+";
- if(HasMode(Modes.HalfOp)) ret = "%";
- if(HasMode(Modes.Op)) ret = "@";
- if(HasMode(Modes.Protected)) ret = "&";
- if(HasMode(Modes.Owner)) ret = "~";
+ if(HasMode(ModeName.None)) ret = "";
+ if(HasMode(ModeName.Devoice)) ret = "-";
+ if(HasMode(ModeName.Voice)) ret = "+";
+ if(HasMode(ModeName.HalfOperator)) ret = "%";
+ if(HasMode(ModeName.Operator)) ret = "@";
+ if(HasMode(ModeName.Protected)) ret = "&";
+ if(HasMode(ModeName.Owner)) ret = "~";
break;
default:
- throw new ArgumentException(String.Format(fp, Strings.NicknameFormatException, p), "format");
+ throw new ArgumentException(String.Format(formatProvider, Strings.NicknameFormatException, format), "format");
}
return ret;
}
@@ -227,17 +233,17 @@
{
return new ModeContainerEnumerator(this);
}
- public int CompareTo(ModeContainer other)
+ public int CompareTo(ModeCollection other)
{
return (other == this ? 0 : ModeList.Count - other.ModeList.Count);
}
- public static int operator >(ModeContainer cont1, ModeContainer cont2)
+ public static int operator >(ModeCollection cont1, ModeCollection cont2)
{
if(cont1 == null)
return -1;
return cont1.CompareTo(cont2);
}
- public static int operator <(ModeContainer cont1, ModeContainer cont2)
+ public static int operator <(ModeCollection cont1, ModeCollection cont2)
{
if(cont2 == null)
return 1;
@@ -249,12 +255,12 @@
}
}
[CLSCompliant(true)]
- public class ModeContainerEnumerator : IEnumerator<Mode>, IEnumerator
+ public sealed class ModeContainerEnumerator : IEnumerator<Mode>, IEnumerator
{
private int index;
- private ModeContainer container;
- internal ModeContainerEnumerator(ModeContainer cont) { container = cont; }
- public void Dispose() { }
+ private ModeCollection container;
+ internal ModeContainerEnumerator(ModeCollection cont) { container = cont; }
+ public void Dispose() { }
public void Reset() { index = 0; }
public Mode Current { get { return container.ModeList[index]; } }
object IEnumerator.Current { get { return (object)Current; } }
Modified: trunk/Client/ModeMap.cs
==============================================================================
--- trunk/Client/ModeMap.cs (original)
+++ trunk/Client/ModeMap.cs Thu Jul 26 21:55:18 2007
@@ -8,47 +8,47 @@
{
private static ModeMap instance = new ModeMap();
public static ModeMap Instance { get { return instance; } }
- public Dictionary<Modes, char> ModeToCharTable = new Dictionary<Modes, char>();
- public Dictionary<Modes, char> ModeToSymbolTable = new Dictionary<Modes, char>();
- public Dictionary<char, Modes> SymbolToModeTable = new Dictionary<char,Modes>();
- public Dictionary<char, Modes> CharToModeTable = new Dictionary<char, Modes>();
+ public Dictionary<ModeName, char> ModeToCharTable = new Dictionary<ModeName, char>();
+ public Dictionary<ModeName, char> ModeToSymbolTable = new Dictionary<ModeName, char>();
+ public Dictionary<char, ModeName> SymbolToModeTable = new Dictionary<char,ModeName>();
+ public Dictionary<char, ModeName> CharToModeTable = new Dictionary<char, ModeName>();
private ModeMap() {
// ModeToSymbolTable inits
- ModeToSymbolTable[Modes.Owner] = '~';
- ModeToSymbolTable[Modes.Protected] = '&';
- ModeToSymbolTable[Modes.Op] = '@';
- ModeToSymbolTable[Modes.HalfOp] = '%';
- ModeToSymbolTable[Modes.Voice] = '+';
- ModeToSymbolTable[Modes.Devoice] = '-';
+ ModeToSymbolTable[ModeName.Owner] = '~';
+ ModeToSymbolTable[ModeName.Protected] = '&';
+ ModeToSymbolTable[ModeName.Operator] = '@';
+ ModeToSymbolTable[ModeName.HalfOperator]= '%';
+ ModeToSymbolTable[ModeName.Voice] = '+';
+ ModeToSymbolTable[ModeName.Devoice] = '-';
// SymbolToModeTable inits
- SymbolToModeTable[ModeToSymbolTable[Modes.Owner]] = Modes.Owner;
- SymbolToModeTable[ModeToSymbolTable[Modes.Protected]] = Modes.Protected;
- SymbolToModeTable[ModeToSymbolTable[Modes.Op]] = Modes.Op;
- SymbolToModeTable[ModeToSymbolTable[Modes.HalfOp]] = Modes.HalfOp;
- SymbolToModeTable[ModeToSymbolTable[Modes.Voice]] = Modes.Voice;
- SymbolToModeTable[ModeToSymbolTable[Modes.Devoice]] = Modes.Devoice;
+ SymbolToModeTable[ModeToSymbolTable[ModeName.Owner]] = ModeName.Owner;
+ SymbolToModeTable[ModeToSymbolTable[ModeName.Protected]] = ModeName.Protected;
+ SymbolToModeTable[ModeToSymbolTable[ModeName.Operator]] = ModeName.Operator;
+ SymbolToModeTable[ModeToSymbolTable[ModeName.HalfOperator]] = ModeName.HalfOperator;
+ SymbolToModeTable[ModeToSymbolTable[ModeName.Voice]] = ModeName.Voice;
+ SymbolToModeTable[ModeToSymbolTable[ModeName.Devoice]] = ModeName.Devoice;
// ModeToChar inits
- ModeToCharTable[Modes.TopicOperatorOnly] = 't';
- ModeToCharTable[Modes.Registered] = 'r';
- ModeToCharTable[Modes.Secret] = 's';
- ModeToCharTable[Modes.NoExternalMessages]= 'n';
- ModeToCharTable[Modes.Moderated] = 'm';
- ModeToCharTable[Modes.Limit] = 'l';
- ModeToCharTable[Modes.Key] = 'k';
- ModeToCharTable[Modes.InviteOnly] = 'i';
- ModeToCharTable[Modes.Private] = 'p';
- ModeToCharTable[Modes.HiddenHostmask] = 'x';
+ ModeToCharTable[ModeName.TopicOperatorOnly] = 't';
+ ModeToCharTable[ModeName.Registered] = 'r';
+ ModeToCharTable[ModeName.Secret] = 's';
+ ModeToCharTable[ModeName.NoExternalMessages] = 'n';
+ ModeToCharTable[ModeName.Moderated] = 'm';
+ ModeToCharTable[ModeName.Limit] = 'l';
+ ModeToCharTable[ModeName.Key] = 'k';
+ ModeToCharTable[ModeName.InviteOnly] = 'i';
+ ModeToCharTable[ModeName.Private] = 'p';
+ ModeToCharTable[ModeName.HiddenHostmask] = 'x';
// CharToMode inits
- CharToModeTable[ModeToCharTable[Modes.TopicOperatorOnly]] = Modes.TopicOperatorOnly;
- CharToModeTable[ModeToCharTable[Modes.Registered]] = Modes.Registered;
- CharToModeTable[ModeToCharTable[Modes.Secret]] = Modes.Secret;
- CharToModeTable[ModeToCharTable[Modes.NoExternalMessages]]= Modes.NoExternalMessages;
- CharToModeTable[ModeToCharTable[Modes.Moderated]] = Modes.Moderated;
- CharToModeTable[ModeToCharTable[Modes.Limit]] = Modes.Limit;
- CharToModeTable[ModeToCharTable[Modes.Key]] = Modes.Key;
- CharToModeTable[ModeToCharTable[Modes.InviteOnly]] = Modes.InviteOnly;
- CharToModeTable[ModeToCharTable[Modes.Private]] = Modes.Private;
- CharToModeTable[ModeToCharTable[Modes.HiddenHostmask]] = Modes.HiddenHostmask;
+ CharToModeTable[ModeToCharTable[ModeName.TopicOperatorOnly]] = ModeName.TopicOperatorOnly;
+ CharToModeTable[ModeToCharTable[ModeName.Registered]] = ModeName.Registered;
+ CharToModeTable[ModeToCharTable[ModeName.Secret]] = ModeName.Secret;
+ CharToModeTable[ModeToCharTable[ModeName.NoExternalMessages]] = ModeName.NoExternalMessages;
+ CharToModeTable[ModeToCharTable[ModeName.Moderated]] = ModeName.Moderated;
+ CharToModeTable[ModeToCharTable[ModeName.Limit]] = ModeName.Limit;
+ CharToModeTable[ModeToCharTable[ModeName.Key]] = ModeName.Key;
+ CharToModeTable[ModeToCharTable[ModeName.InviteOnly]] = ModeName.InviteOnly;
+ CharToModeTable[ModeToCharTable[ModeName.Private]] = ModeName.Private;
+ CharToModeTable[ModeToCharTable[ModeName.HiddenHostmask]] = ModeName.HiddenHostmask;
}
}
}
Modified: trunk/Client/Nickname.cs
==============================================================================
--- trunk/Client/Nickname.cs (original)
+++ trunk/Client/Nickname.cs Thu Jul 26 21:55:18 2007
@@ -6,12 +6,12 @@
[CLSCompliant(true)]
public sealed class Nickname : Target, IComparable, IFormattable
{
- private ModeContainer accessLevel;
+ private ModeCollection accessLevel;
private string hostmask;
private string realname;
private string name;
- public ModeContainer AccessLevel {
+ public ModeCollection AccessLevel {
get { return accessLevel; }
}
public string Name
@@ -29,21 +29,22 @@
get { return hostmask; }
set { hostmask = value; }
}
- public Nickname(string nick, string real, string host, params Modes[] access)
+ public Nickname(string nick, string real, string host, params ModeName[] access)
{
Name = nick;
Realname = real;
Hostmask = host;
- accessLevel = new ModeContainer();
- foreach(Modes m in access)
- accessLevel += new Mode(this, m);
+ accessLevel = new ModeCollection();
+ if(access != null)
+ foreach(ModeName m in access)
+ accessLevel += new Mode(this, m);
}
- public Nickname(string nick) : this(nick, "*", "*", Modes.None) {}
- public Nickname(string nick, Modes access) : this(nick, "*", "*", access) {}
- public Nickname(string nick, Modes[] access) : this(nick, "*", "*", access) {}
- public Nickname(string nick, string host) : this(nick, "*", host, Modes.None) {}
- public Nickname(string nick, string real, string host) : this(nick, real, host, Modes.None) {}
+ public Nickname(string nick) : this(nick, "*", "*", ModeName.None) {}
+ public Nickname(string nick, ModeName access) : this(nick, "*", "*", access) {}
+ public Nickname(string nick, ModeName[] access) : this(nick, "*", "*", access) {}
+ public Nickname(string nick, string host) : this(nick, "*", host, ModeName.None) {}
+ public Nickname(string nick, string real, string host) : this(nick, real, host, ModeName.None) {}
public static Nickname Parse(string format)
{
Nickname result;
@@ -61,19 +62,19 @@
{
try {
result = Parse(format);
+ return true;
} catch(FormatException) {
result = null;
return false;
}
- return true;
}
public int CompareTo(object obj)
{
Nickname n = obj as Nickname;
if(n != null)
{
- string theirHostmask = n.ToString("f");
- string ourHostmask = ToString("f");
+ string theirHostmask = n.ToString("f", System.Globalization.CultureInfo.CurrentCulture);
+ string ourHostmask = ToString("f", System.Globalization.CultureInfo.CurrentCulture);
for(int i = 0, j = 0; i < theirHostmask.Length && j < ourHostmask.Length; )
{
if(ourHostmask[i] != theirHostmask[j])
@@ -103,9 +104,9 @@
}
public override bool Equals(object obj)
{
- Nickname n = obj as Nickname;
- if(n != null)
+ if(obj != null)
{
+ Nickname n = obj as Nickname;
try
{
return CompareTo(n) == 0;
@@ -128,7 +129,7 @@
{
return ToString(format, System.Globalization.CultureInfo.CurrentCulture);
}
- public string ToString(string format, IFormatProvider fp)
+ public string ToString(string format, IFormatProvider formatProvider)
{
switch(format)
{
@@ -137,11 +138,23 @@
case "G":case "g":case "n":case null:
return Name;
case "S":case "s":
- return AccessLevel.ToString("S") + Name;
+ return AccessLevel.ToString("S", System.Globalization.CultureInfo.CurrentCulture) + Name;
default:
- throw new FormatException(String.Format(fp, Strings.NicknameFormatException, format));
+ throw new FormatException(String.Format(formatProvider, Strings.NicknameFormatException, format));
}
}
+ public static bool operator ==(Nickname obj1, Nickname obj2)
+ {
+ if(obj1 != null)
+ return obj1.Equals(obj2);
+ else return false;
+ }
+ public static bool operator !=(Nickname obj1, Nickname obj2)
+ {
+ if(obj1 != null)
+ return !obj1.Equals(obj2);
+ else return false;
+ }
public static int operator >(Nickname obj1, Nickname obj2)
{
if(obj1 != null)
@@ -154,9 +167,11 @@
return obj2.CompareTo(obj1);
else return 1;
}
- public static implicit operator string(Nickname n)
+ public static implicit operator string(Nickname nick)
{
- return n.ToString();
+ if(nick != null)
+ return nick.ToString();
+ else return String.Empty;
}
}
}