diff options
Diffstat (limited to 'IrcStates')
-rw-r--r-- | IrcStates/Casemap.cs | 43 | ||||
-rw-r--r-- | IrcStates/Channel.cs | 69 | ||||
-rw-r--r-- | IrcStates/Emit.cs | 6 | ||||
-rw-r--r-- | IrcStates/ISupport.cs | 7 | ||||
-rw-r--r-- | IrcStates/IrcStates.csproj | 21 | ||||
-rw-r--r-- | IrcStates/Numeric.cs | 49 | ||||
-rw-r--r-- | IrcStates/Server.cs | 6 | ||||
-rw-r--r-- | IrcStates/Tests/Cap.cs | 9 | ||||
-rw-r--r-- | IrcStates/Tests/Casemap.cs | 9 | ||||
-rw-r--r-- | IrcStates/Tests/Channel.cs | 9 | ||||
-rw-r--r-- | IrcStates/Tests/Emit.cs | 9 | ||||
-rw-r--r-- | IrcStates/Tests/ISupport.cs | 10 | ||||
-rw-r--r-- | IrcStates/Tests/Mode.cs | 9 | ||||
-rw-r--r-- | IrcStates/Tests/Motd.cs | 9 | ||||
-rw-r--r-- | IrcStates/Tests/User.cs | 9 | ||||
-rw-r--r-- | IrcStates/Tests/Who.cs | 9 | ||||
-rw-r--r-- | IrcStates/User.cs | 28 |
17 files changed, 311 insertions, 0 deletions
diff --git a/IrcStates/Casemap.cs b/IrcStates/Casemap.cs new file mode 100644 index 0000000..484c490 --- /dev/null +++ b/IrcStates/Casemap.cs @@ -0,0 +1,43 @@ +using System; + +namespace IrcStates +{ + public static class Casemap + { + public enum CaseMapping + { + Rfc1459, + Ascii + } + + private const string AsciiUpperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + private const string AsciiLowerChars = "abcdefghijklmnopqrstuvwxyz"; + private const string Rfc1459UpperChars = AsciiUpperChars + @"[]~\"; + private const string Rfc1459LowerChars = AsciiLowerChars + @"{}^|"; + + private static string Replace(string s, string upper, string lower) + { + for (var i = 0; i < upper.Length; ++i) + { + s = s.Replace(upper[i], lower[i]); + } + + return s; + } + + public static string CaseFold(CaseMapping mapping, string s) + { + if (s != null) + { + return mapping switch + { + CaseMapping.Rfc1459 => Replace(s, Rfc1459UpperChars, Rfc1459LowerChars), + CaseMapping.Ascii => Replace(s, AsciiUpperChars, AsciiLowerChars), + _ => throw new ArgumentOutOfRangeException(nameof(mapping), mapping, null) + }; + } + + return string.Empty; + } + } +} diff --git a/IrcStates/Channel.cs b/IrcStates/Channel.cs new file mode 100644 index 0000000..1850e51 --- /dev/null +++ b/IrcStates/Channel.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace IrcStates +{ + public class Channel + { + public string Name { get; set; } + public string NameLower { get; set; } + public Dictionary<string, User> Users { get; set; } + public string Topic { get; set; } + public string TopicSetter { get; set; } + public DateTime TopicTime { get; set; } + public DateTime Created { get; set; } + public Dictionary<string, List<string>> ListModes { get; set; } + public Dictionary<string, string> Modes { get; set; } + + public override string ToString() + { + return $"Channel(name={Name})"; + } + + public void SetName(string name, string nameLower) + { + Name = name; + NameLower = nameLower; + } + + public void AddMode(string ch, string param, bool listMode) + { + if (listMode) + { + if (!ListModes.ContainsKey(ch)) + { + ListModes[ch] = new List<string>(); + } + + if (ListModes[ch].Contains(param)) + { + ListModes[ch].Add(param ?? string.Empty); + } + } + else + { + Modes[ch] = param; + } + } + + public void RemoveMode(string ch, string param) + { + if (ListModes.ContainsKey(ch)) + { + if (ListModes[ch].Contains(param)) + { + ListModes[ch].Remove(param); + if (!ListModes[ch].Any()) + { + ListModes.Remove(ch); + } + } + } + else if (Modes.ContainsKey(ch)) + { + Modes.Remove(ch); + } + } + } +} diff --git a/IrcStates/Emit.cs b/IrcStates/Emit.cs new file mode 100644 index 0000000..7fc41ae --- /dev/null +++ b/IrcStates/Emit.cs @@ -0,0 +1,6 @@ +namespace IrcStates +{ + public class Emit + { + } +} diff --git a/IrcStates/ISupport.cs b/IrcStates/ISupport.cs new file mode 100644 index 0000000..91e6d6d --- /dev/null +++ b/IrcStates/ISupport.cs @@ -0,0 +1,7 @@ +// ReSharper disable InconsistentNaming +namespace IrcStates +{ + public class ISupport + { + } +} diff --git a/IrcStates/IrcStates.csproj b/IrcStates/IrcStates.csproj new file mode 100644 index 0000000..7500c8b --- /dev/null +++ b/IrcStates/IrcStates.csproj @@ -0,0 +1,21 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>netcoreapp3.1</TargetFramework> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8"> + <PrivateAssets>all</PrivateAssets> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + </PackageReference> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.0" /> + <PackageReference Include="MSTest.TestAdapter" Version="2.1.1" /> + <PackageReference Include="MSTest.TestFramework" Version="2.1.1" /> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\IrcTokens\IrcTokens.csproj" /> + </ItemGroup> + +</Project> diff --git a/IrcStates/Numeric.cs b/IrcStates/Numeric.cs new file mode 100644 index 0000000..f5525f6 --- /dev/null +++ b/IrcStates/Numeric.cs @@ -0,0 +1,49 @@ +// ReSharper disable InconsistentNaming +namespace IrcStates +{ + public static class Numeric + { + public const string RPL_WELCOME = "001"; + public const string RPL_ISUPPORT = "005"; + public const string RPL_MOTD = "372"; + public const string RPL_MOTDSTART = "375"; + public const string RPL_UMODEIS = "221"; + public const string RPL_VISIBLEHOST = "396"; + + public const string RPL_CHANNELMODEIS = "324"; + public const string RPL_CREATIONTIME = "329"; + public const string RPL_TOPIC = "332"; + public const string RPL_TOPICWHOTIME = "333"; + + public const string RPL_WHOREPLY = "352"; + public const string RPL_WHOSPCRPL = "354"; + public const string RPL_ENDOFWHO = "315"; + public const string RPL_NAMREPLY = "353"; + public const string RPL_ENDOFNAMES = "366"; + + public const string RPL_BANLIST = "367"; + public const string RPL_ENDOFBANLIST = "368"; + public const string RPL_QUIETLIST = "728"; + public const string RPL_ENDOFQUIETLIST = "729"; + + public const string RPL_SASLSUCCESS = "903"; + public const string ERR_SASLFAIL = "904"; + public const string ERR_SASLTOOLONG = "905"; + public const string ERR_SASLABORTED = "906"; + public const string ERR_SASLALREADY = "907"; + public const string RPL_SASLMECHS = "908"; + + public const string RPL_WHOISUSER = "311"; + public const string RPL_WHOISSERVER = "312"; + public const string RPL_WHOISOPERATOR = "313"; + public const string RPL_WHOISIDLE = "317"; + public const string RPL_WHOISCHANNELS = "319"; + public const string RPL_WHOISACCOUNT = "330"; + public const string RPL_WHOISHOST = "378"; + public const string RPL_WHOISMODES = "379"; + public const string RPL_WHOISSECURE = "671"; + public const string RPL_ENDOFWHOIS = "318"; + + public const string ERR_NOSUCHCHANNEL = "403"; + } +} diff --git a/IrcStates/Server.cs b/IrcStates/Server.cs new file mode 100644 index 0000000..9f97f47 --- /dev/null +++ b/IrcStates/Server.cs @@ -0,0 +1,6 @@ +namespace IrcStates +{ + public class Server + { + } +} diff --git a/IrcStates/Tests/Cap.cs b/IrcStates/Tests/Cap.cs new file mode 100644 index 0000000..dcd0e50 --- /dev/null +++ b/IrcStates/Tests/Cap.cs @@ -0,0 +1,9 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace IrcStates.Tests +{ + [TestClass] + public class Cap + { + } +} diff --git a/IrcStates/Tests/Casemap.cs b/IrcStates/Tests/Casemap.cs new file mode 100644 index 0000000..fef9a31 --- /dev/null +++ b/IrcStates/Tests/Casemap.cs @@ -0,0 +1,9 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace IrcStates.Tests +{ + [TestClass] + public class Casemap + { + } +} diff --git a/IrcStates/Tests/Channel.cs b/IrcStates/Tests/Channel.cs new file mode 100644 index 0000000..0de5f37 --- /dev/null +++ b/IrcStates/Tests/Channel.cs @@ -0,0 +1,9 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace IrcStates.Tests +{ + [TestClass] + public class Channel + { + } +} diff --git a/IrcStates/Tests/Emit.cs b/IrcStates/Tests/Emit.cs new file mode 100644 index 0000000..f4495c5 --- /dev/null +++ b/IrcStates/Tests/Emit.cs @@ -0,0 +1,9 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace IrcStates.Tests +{ + [TestClass] + public class Emit + { + } +} diff --git a/IrcStates/Tests/ISupport.cs b/IrcStates/Tests/ISupport.cs new file mode 100644 index 0000000..aa6260a --- /dev/null +++ b/IrcStates/Tests/ISupport.cs @@ -0,0 +1,10 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +// ReSharper disable InconsistentNaming + +namespace IrcStates.Tests +{ + [TestClass] + public class ISupport + { + } +} diff --git a/IrcStates/Tests/Mode.cs b/IrcStates/Tests/Mode.cs new file mode 100644 index 0000000..e7b70f4 --- /dev/null +++ b/IrcStates/Tests/Mode.cs @@ -0,0 +1,9 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace IrcStates.Tests +{ + [TestClass] + public class Mode + { + } +} diff --git a/IrcStates/Tests/Motd.cs b/IrcStates/Tests/Motd.cs new file mode 100644 index 0000000..8ca7f07 --- /dev/null +++ b/IrcStates/Tests/Motd.cs @@ -0,0 +1,9 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace IrcStates.Tests +{ + [TestClass] + public class Motd + { + } +} diff --git a/IrcStates/Tests/User.cs b/IrcStates/Tests/User.cs new file mode 100644 index 0000000..540d31f --- /dev/null +++ b/IrcStates/Tests/User.cs @@ -0,0 +1,9 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace IrcStates.Tests +{ + [TestClass] + public class User + { + } +} diff --git a/IrcStates/Tests/Who.cs b/IrcStates/Tests/Who.cs new file mode 100644 index 0000000..359991c --- /dev/null +++ b/IrcStates/Tests/Who.cs @@ -0,0 +1,9 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace IrcStates.Tests +{ + [TestClass] + public class Who + { + } +} diff --git a/IrcStates/User.cs b/IrcStates/User.cs new file mode 100644 index 0000000..9bc5ce8 --- /dev/null +++ b/IrcStates/User.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; + +namespace IrcStates +{ + public class User + { + private string NickName; + private string NickNameLower; + + public string UserName { get; set; } + public string HostName { get; set; } + public string RealName { get; set; } + public string Account { get; set; } + public string Away { get; set; } + public HashSet<string> Channels { get; set; } + + public override string ToString() + { + return $"User(nickname={NickName})"; + } + + public void SetNickName(string nick, string nickLower) + { + NickName = nick; + NickNameLower = nickLower; + } + } +} |