about summary refs log tree commit diff
path: root/IrcStates
diff options
context:
space:
mode:
Diffstat (limited to 'IrcStates')
-rw-r--r--IrcStates/Casemap.cs11
-rw-r--r--IrcStates/Numeric.cs3
-rw-r--r--IrcStates/Server.cs75
-rw-r--r--IrcStates/ServerDisconnectedException.cs9
-rw-r--r--IrcStates/ServerException.cs9
-rw-r--r--IrcStates/User.cs2
6 files changed, 99 insertions, 10 deletions
diff --git a/IrcStates/Casemap.cs b/IrcStates/Casemap.cs
index 484c490..67867c5 100644
--- a/IrcStates/Casemap.cs
+++ b/IrcStates/Casemap.cs
@@ -17,10 +17,7 @@ namespace IrcStates
 
         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]);
-            }
+            for (var i = 0; i < upper.Length; ++i) s = s.Replace(upper[i], lower[i]);
 
             return s;
         }
@@ -28,14 +25,12 @@ namespace IrcStates
         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)
+                    CaseMapping.Ascii   => Replace(s, AsciiUpperChars, AsciiLowerChars),
+                    _                   => throw new ArgumentOutOfRangeException(nameof(mapping), mapping, null)
                 };
-            }
 
             return string.Empty;
         }
diff --git a/IrcStates/Numeric.cs b/IrcStates/Numeric.cs
index f5525f6..3cd63b3 100644
--- a/IrcStates/Numeric.cs
+++ b/IrcStates/Numeric.cs
@@ -1,8 +1,10 @@
 // ReSharper disable InconsistentNaming
+
 namespace IrcStates
 {
     public static class Numeric
     {
+#pragma warning disable CA1707 // Identifiers should not contain underscores
         public const string RPL_WELCOME = "001";
         public const string RPL_ISUPPORT = "005";
         public const string RPL_MOTD = "372";
@@ -45,5 +47,6 @@ namespace IrcStates
         public const string RPL_ENDOFWHOIS = "318";
 
         public const string ERR_NOSUCHCHANNEL = "403";
+#pragma warning restore CA1707 // Identifiers should not contain underscores
     }
 }
diff --git a/IrcStates/Server.cs b/IrcStates/Server.cs
index 9f97f47..c20e041 100644
--- a/IrcStates/Server.cs
+++ b/IrcStates/Server.cs
@@ -1,6 +1,79 @@
-namespace IrcStates
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using IrcTokens;
+
+namespace IrcStates
 {
     public class Server
     {
+        private readonly StatefulDecoder _decoder;
+
+        public Dictionary<string, List<Func<string, Line, Emit>>> LineHandlers;
+
+        private Dictionary<string, string> TempCaps;
+
+        public Server(string name)
+        {
+            Name          = name;
+            Registered    = false;
+            Modes         = new List<string>();
+            Motd          = new List<string>();
+            _decoder      = new StatefulDecoder();
+            LineHandlers  = new Dictionary<string, List<Func<string, Line, Emit>>>();
+            Users         = new Dictionary<string, User>();
+            Channels      = new Dictionary<string, Channel>();
+            ISupport      = new ISupport();
+            HasCap        = false;
+            TempCaps      = new Dictionary<string, string>();
+            AvailableCaps = new Dictionary<string, string>();
+            AgreedCaps    = new List<string>();
+        }
+
+        public string Name { get; set; }
+        public string NickName { get; set; }
+        public string NickNameLower { get; set; }
+        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 bool Registered { get; set; }
+        public List<string> Modes { get; set; }
+        public List<string> Motd { get; set; }
+        public Dictionary<string, User> Users { get; set; }
+        public Dictionary<string, Channel> Channels { get; set; }
+        public Dictionary<string, string> AvailableCaps { get; set; }
+        public List<string> AgreedCaps { get; set; }
+
+        public ISupport ISupport { get; set; }
+        public bool HasCap { get; set; }
+
+        public override string ToString()
+        {
+            return $"Server(name={Name})";
+        }
+
+        public List<(Line, Emit)> Recv(byte[] data)
+        {
+            var lines = _decoder.Push(data);
+            if (lines == null) throw new ServerDisconnectedException();
+
+            var emits = lines.Select(ParseTokens).ToList();
+            return null;
+        }
+
+        private Emit ParseTokens(Line line)
+        {
+            Emit ret;
+            if (LineHandlers.ContainsKey(line.Command))
+                foreach (var callback in LineHandlers[line.Command])
+                {
+                    var emit = callback(line.Command, line);
+                }
+
+            throw new NotImplementedException();
+        }
     }
 }
diff --git a/IrcStates/ServerDisconnectedException.cs b/IrcStates/ServerDisconnectedException.cs
new file mode 100644
index 0000000..636acec
--- /dev/null
+++ b/IrcStates/ServerDisconnectedException.cs
@@ -0,0 +1,9 @@
+using System;
+
+namespace IrcStates
+{
+    public class ServerDisconnectedException : Exception
+    {
+
+    }
+}
diff --git a/IrcStates/ServerException.cs b/IrcStates/ServerException.cs
new file mode 100644
index 0000000..328b141
--- /dev/null
+++ b/IrcStates/ServerException.cs
@@ -0,0 +1,9 @@
+using System;
+
+namespace IrcStates
+{
+    public class ServerException : Exception
+    {
+
+    }
+}
diff --git a/IrcStates/User.cs b/IrcStates/User.cs
index 9bc5ce8..3fea024 100644
--- a/IrcStates/User.cs
+++ b/IrcStates/User.cs
@@ -21,7 +21,7 @@ namespace IrcStates
 
         public void SetNickName(string nick, string nickLower)
         {
-            NickName = nick;
+            NickName      = nick;
             NickNameLower = nickLower;
         }
     }