using System; using System.Collections.Generic; using System.Linq; using IrcTokens; namespace IrcStates { public class Server { private readonly StatefulDecoder _decoder; public Dictionary>> LineHandlers; private Dictionary TempCaps; public Server(string name) { Name = name; Registered = false; Modes = new List(); Motd = new List(); _decoder = new StatefulDecoder(); LineHandlers = new Dictionary>>(); Users = new Dictionary(); Channels = new Dictionary(); ISupport = new ISupport(); HasCap = false; TempCaps = new Dictionary(); AvailableCaps = new Dictionary(); AgreedCaps = new List(); } 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 Modes { get; set; } public List Motd { get; set; } public Dictionary Users { get; set; } public Dictionary Channels { get; set; } public Dictionary AvailableCaps { get; set; } public List 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, data.Length); if (lines == null) throw new ServerDisconnectedException(); var emits = lines.Select(ParseTokens).ToList(); return null; } public Emit ParseTokens(Line line) { if (line != null && !LineHandlers.ContainsKey(line.Command)) return null; var ret = new Emit(); var handlers = LineHandlers[line.Command] .Select(callback => callback(line.Command, line)) .Where(emit => emit != null); foreach (var emit in handlers) { emit.Command = line.Command; ret = emit; } return ret; } } }