示例#1
0
 private void RemoveClient(Remote r)
 {
     r.ReceiveCount = 100;
     Connection.Block(r);
     if (r.Data == null)
     {
         return;
     }
     _Clients.Remove((ClientInfo)r.Data);
     ConnectionSelectForm.Log("[D] Client " + _Clients.Count);
 }
示例#2
0
 public void OnPacket(Remote r)
 {
     var type = (PacketType)Parent.Connection.Buffer.ReadByte();
     switch (type)
     {
         case PacketType.NewConnection:
             //TODO
             return;
         case PacketType.ClientReady:
             ConnectionSelectForm.Log("Ready " + r.ToString());
             _Ready[RemoteIndex(r)] = true;
             CheckReady();
             return;
         case PacketType.ClientStatus:
             //ignore
             return;
         case PacketType.ClientInputData:
             //
             Parent.Connection.Buffer.ReadBytes(_ByteBuffer);
             Parent._InputHandler.ReceiveNetworkData(RemoteIndex(r), _ByteBuffer);
             return;
         default:
             break;
     }
 }
示例#3
0
            public void OnPacket(Remote r)
            {
                var type = (PacketType)_Parent.Connection.Buffer.ReadByte();
                switch (type)
                {
                    case PacketType.None:
                        //empty packet
                        r.ReceiveCount -= 1;
                        _Parent.Connection.Buffer.Write(PacketType.None);
                        _Parent.Connection.Send(r);
                        return;
                    case PacketType.NewConnection:
                        if (r.ReceiveCount == 1)
                        {
                            ClientInfo ci = new ClientInfo();
                            ci.Remote = r;
                            r.Data = ci;
                            _Parent._Clients.Add(ci);

                            //just reply
                            SendStatus(r);

                            ConnectionSelectForm.Log("New client " + r.ToString());
                            ConnectionSelectForm.Log("[A] Client " + _Parent._Clients.Count);
                            return;
                        }
                        break;
                    case PacketType.ClientStatus:
                        if (r.ReceiveCount != 1)
                        {
                            //TODO check if active client
                            //we don't need any information, just reply
                            SendStatus(r);

                            ConnectionSelectForm.Log("Client status " + r.ToString());
                            return;
                        }
                        break;
                    default:
                        break;
                }
                ConnectionSelectForm.Log("Error");
                _Parent.RemoveClient(r);
            }
示例#4
0
 private void SendStatus(Remote r)
 {
     _Parent.Connection.Buffer.Write(PacketType.ServerStatus);
     _Parent.Connection.Send(r);
 }
 public bool Receive(out Remote r)
 {
     var rr = Receive();
     r = rr;
     return rr != null;
 }
示例#6
0
 private int RemoteIndex(Remote r)
 {
     return ((ClientInfo)r.Data).PlayerIndex;
 }
 public void Block(Remote r)
 {
     var k = GetKey(ref r.Address);
     _BlockRemote.Add(k);
     _RemoteList.Remove(k);
 }
        private Remote FindRemote(ref WinSock.sockaddr_in addr)
        {
            var val = GetKey(ref addr);
            if (_BlockRemote.Contains(val))
            {
                return null;
            }
            Remote ret;
            if (_RemoteList.TryGetValue(val, out ret))
            {
                ret.LastReceived = _Clock.ElapsedMilliseconds;
                return ret;
            }

            ret = new Remote(ref addr, _Clock.ElapsedMilliseconds);
            _RemoteList.Add(val, ret);
            return ret;
        }
        public bool UpdateRemoteList(Remote r, long receiveTimeout, long activeTimeout)
        {
            //
            return true;

            long removeSend = _Clock.ElapsedMilliseconds - receiveTimeout;
            long activeTime = _Clock.ElapsedMilliseconds - activeTimeout;
            _ToRemove.Clear();

            if (r.LastReceived < r.LastSend && r.LastSend < removeSend ||
                r.LastSend < activeTime && r.LastReceived < activeTime)
            {
                _RemoteList.Remove(GetKey(ref r.Address));
                return false;
            }
            return true;
        }
示例#10
0
 public void Unblock(Remote r)
 {
     var k = GetKey(ref r.Address);
     _BlockRemote.Remove(k);
 }
示例#11
0
 public void Send(Remote r)
 {
     if (WinSock.sendto(_Socket, Buffer.Pointer, Buffer.Length, 0, ref r.Address, WinSock.sockaddr_in.Size) < 0)
     {
         throw new NetworkException(Marshal.GetLastWin32Error());
     }
 }