Beispiel #1
0
        private NetPeer OnConnectionSolved(ConnectionRequest request)
        {
            bool isConnectingPeer;

            lock (_connectingPeers)
            {
                isConnectingPeer = _connectingPeers.Contains(request.RemoteEndPoint);
            }

            if (!isConnectingPeer)
            {
                return(null);
            }

            if (request.Result == ConnectionRequestResult.Reject)
            {
                NetUtils.DebugWrite(ConsoleColor.Cyan, "[NM] Peer connect reject.");
            }
            else if (GetPeersCount(ConnectionState.Connected | ConnectionState.InProgress) < _maxConnections)
            {
                //response with id
                var netPeer = new NetPeer(this, request.RemoteEndPoint, request.ConnectionId);
                NetUtils.DebugWrite(ConsoleColor.Cyan, "[NM] Received peer connection Id: {0}, EP: {1}",
                                    netPeer.ConnectId, netPeer.EndPoint);

                //add peer to list
                lock (_connectingPeers)
                {
                    _connectingPeers.Remove(request.RemoteEndPoint);
                    _peers.Add(request.RemoteEndPoint, netPeer);
                }

                var netEvent = CreateEvent(NetEventType.Connect);
                netEvent.Peer = netPeer;
                EnqueueEvent(netEvent);
                return(netPeer);
            }

            lock (_connectingPeers)
            {
                _connectingPeers.Remove(request.RemoteEndPoint);
            }

            return(null);
        }
        void IConnectionRequestListener.OnConnectionSolved(ConnectionRequest request, byte[] rejectData, int start, int length)
        {
            if (request.Result == ConnectionRequestResult.Reject)
            {
                NetUtils.DebugWrite(ConsoleColor.Cyan, "[NM] Peer connect reject.");
                request.Peer.Reject(request.ConnectionId, request.ConnectionNumber, rejectData, start, length);
            }
            else
            {
                //Accept
                request.Peer.Accept(request.ConnectionId, request.ConnectionNumber);

                //Add event
                CreateEvent(NetEvent.EType.Connect, request.Peer);

                NetUtils.DebugWrite(ConsoleColor.Cyan, "[NM] Received peer connection Id: {0}, EP: {1}",
                                    request.Peer.ConnectId, request.Peer.EndPoint);
            }
        }
Beispiel #3
0
        private void OnConnectionSolved(ConnectionRequest request, byte[] rejectData, int start, int length)
        {
            if (request.Result == ConnectionRequestResult.Reject)
            {
                NetUtils.DebugWrite(ConsoleColor.Cyan, "[NM] Peer connect reject.");
                request.Peer.Shutdown(rejectData, start, length, false);
            }
            else
            {
                //Accept
                request.Peer.Accept(request.ConnectionId, request.ConnectionNumber);

                //Add event
                var netEvent = CreateEvent(NetEventType.Connect);
                netEvent.Peer = request.Peer;
                EnqueueEvent(netEvent);

                NetUtils.DebugWrite(ConsoleColor.Cyan, "[NM] Received peer connection Id: {0}, EP: {1}",
                                    request.Peer.ConnectId, request.Peer.EndPoint);
            }
        }
Beispiel #4
0
        private NetPeer OnConnectionSolved(ConnectionRequest request)
        {
            lock (_peers)
            {
                lock (_connectingPeers)
                {
                    if (_connectingPeers.Contains(request.RemoteEndPoint))
                    {
                        _connectingPeers.Remove(request.RemoteEndPoint);
                    }
                    else
                    {
                        return(null);
                    }
                }
                if (request.Result == ConnectionRequestResult.Reject)
                {
                    NetUtils.DebugWrite(ConsoleColor.Cyan, "[NM] Peer connect reject.");
                }
                else
                {
                    //response with id
                    var netPeer = new NetPeer(this, request.RemoteEndPoint, request.ConnectionId);
                    NetUtils.DebugWrite(ConsoleColor.Cyan, "[NM] Received peer connection Id: {0}, EP: {1}",
                                        netPeer.ConnectId, netPeer.EndPoint);

                    //add peer to list
                    _peers.Add(request.RemoteEndPoint, netPeer);

                    var netEvent = CreateEvent(NetEventType.Connect);
                    netEvent.Peer = netPeer;
                    EnqueueEvent(netEvent);
                    return(netPeer);
                }
            }
            return(null);
        }
Beispiel #5
0
 public void OnConnectionRequest(LiteNetLib.ConnectionRequest request)
 {
     request.Accept();
 }
Beispiel #6
0
 void INetEventListener.OnConnectionRequest(ConnectionRequest request)
 {
     ConnectionRequestEvent?.Invoke(request);
 }
 void INetEventListener.OnConnectionRequest(ConnectionRequest request)
 {
     if (ConnectionRequestEvent != null)
         ConnectionRequestEvent(request);
 }