Esempio n. 1
0
 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));
         }
     }
 }
Esempio n. 2
0
 internal void debugHigh(Connection c, ManagedEvents action, SGuid id, string reason = "")
 {
     if (trackHigh)
     {
         tHigh.Add(new object[] { Now, action, id, reason });
     }
 }
Esempio n. 3
0
 public Client(string hostname, ushort port, SGuid?customID = null)
 {
     tcp           = new TcpClient();
     this.hostname = hostname;
     this.port     = port;
     ID            = customID ?? SGuid.NewSGuid();
 }
Esempio n. 4
0
        public void Write(SGuid id, params Directive[] msgs)
        {
            Link link = _clients.Find(a => a.ID == id);

            if (link != null)
            {
                write(link, false, msgs.AllSerialize());
            }
        }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 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;
 }
Esempio n. 7
0
        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);
            }
        }