예제 #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));
         }
     }
 }
예제 #2
0
 internal void debugHigh(Connection c, ManagedEvents action, SGuid id, string reason = "")
 {
     if (trackHigh)
     {
         tHigh.Add(new object[] { Now, action, id, reason });
     }
 }
예제 #3
0
파일: Client.cs 프로젝트: hnjm/NetLib
 public Client(string hostname, ushort port, SGuid?customID = null)
 {
     tcp           = new TcpClient();
     this.hostname = hostname;
     this.port     = port;
     ID            = customID ?? SGuid.NewSGuid();
 }
예제 #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());
            }
        }
예제 #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);
 }
예제 #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;
 }
예제 #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);
            }
        }