void read(Link link, Data data) { if (data.Intern) { var cmd = StringEnum <InternalCommands>(data.Cmds[0]); link.debugCommand(false, link, cmd); if (cmd == InternalCommands.connect) { write(link, true, EnumString(InternalCommands.ok)); lock (link) { link.ID = SGuid.Parse(data.Cmds[1]); link.state = LinkStates.ready; joinClient?.Invoke(link.ID); } debugNotice(this); } if (cmd == InternalCommands.disconnect && link.state == LinkStates.ready) { disconnect(link, StringEnum <LeaveReason>(data.Cmds[1]), data.Cmds[2]); } } else { write(link, true, EnumString(InternalCommands.ok)); foreach (string cmd in data.Cmds) { received(Directive.Parse(cmd)); } } }
internal void debugHigh(Connection c, ManagedEvents action, SGuid id, string reason = "") { if (trackHigh) { tHigh.Add(new object[] { Now, action, id, reason }); } }
public Client(string hostname, ushort port, SGuid?customID = null) { tcp = new TcpClient(); this.hostname = hostname; this.port = port; ID = customID ?? SGuid.NewSGuid(); }
public void Write(SGuid id, params Directive[] msgs) { Link link = _clients.Find(a => a.ID == id); if (link != null) { write(link, false, msgs.AllSerialize()); } }
public Server(ushort port, SGuid?customID = null) { tcp = new TcpListener(IPAddress.Any, port); this.port = port; state = LinkStates.ready; ID = customID ?? SGuid.NewSGuid(); _clients = new List <Link>(); clock = new Clock(serverTick, tick); }
public Link(TcpClient c, SGuid id = default(SGuid)) { client = c; clock = new Clock(linkTick, read); pingPong = new PingPong(this, timeout); sending = false; buffer = ""; sendQueue = new Queue <Data>(); ID = id; state = LinkStates.creating; }
public void Kick(SGuid id, string reason) { Link link; lock (_clients) link = _clients.Find(a => a.ID == id); if (link != null) { var rsn = LeaveReason.kicked; write(link, true, EnumString(InternalCommands.disconnect), EnumString(rsn), reason); disconnect(link, rsn, reason); } }