diff options
author | Ben Harris <ben@tilde.team> | 2020-04-28 00:35:52 -0400 |
---|---|---|
committer | Ben Harris <ben@tilde.team> | 2020-04-28 00:35:52 -0400 |
commit | 80afa2c0aec37b7f98cc22615417c36672e695da (patch) | |
tree | 63ca3e309a5daa5093e54bdfdb493115c7a3d942 /IrcStates/Server.cs | |
parent | 933a4f85604e21445c9bac8272d64cf3e6f65e00 (diff) |
tidy up, work on stateful
Diffstat (limited to 'IrcStates/Server.cs')
-rw-r--r-- | IrcStates/Server.cs | 75 |
1 files changed, 74 insertions, 1 deletions
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(); + } } } |