Esempio n. 1
0
        private void InputUnreliable(byte[] buffer, int msgLength)
        {
            unreliable.Input(buffer, msgLength);
            Thread.VolatileWrite(ref lastReceived, stopWatch.ElapsedMilliseconds);

            if (isWaiting && unreliable.PeekSize() > 0)
            {
                dataAvailable?.TrySetResult();
            }
        }
Esempio n. 2
0
        void AcceptLoop()
        {
            try
            {
                while (true)
                {
                    TcpClient client = listener.AcceptTcpClient();

                    var conn = new Connection(client, certificate);

                    // handshake needs its own thread as it needs to wait for message from client
                    var receiveThread = new Thread(() => HandshakeAndReceiveLoop(conn))
                    {
                        IsBackground = true
                    };
                    receiveThread.Start();
                }
            }
            catch (SocketException)
            {
                // fine,  someone stopped the connection
            }
            catch (Exception ex)
            {
                listenCompletion.TrySetException(ex);
            }
            finally
            {
                listenCompletion.TrySetResult();
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     New incoming connection from someone. We check to see if its same as in address atm for security.
        /// </summary>
        /// <param name="result">The data we need to process to make a accept the new connection request.</param>
        protected override void OnNewConnection(OnIncomingConnectionRequestInfo result)
        {
            if (_initialWait)
            {
                return;
            }

            if (Options.ConnectionAddress == result.RemoteUserId)
            {
                EpicManager.P2PInterface.AcceptConnection(
                    new AcceptConnectionOptions
                {
                    LocalUserId  = EpicManager.AccountId.ProductUserId,
                    RemoteUserId = result.RemoteUserId,
                    SocketId     = result.SocketId
                });

                _connectedComplete.TrySetResult();

                SocketName = result.SocketId;
            }
            else
            {
                if (Logger.logEnabled)
                {
                    if (Transport.transportDebug)
                    {
                        DebugLogger.RegularDebugLog("[Client] - P2P Acceptance Request from unknown host ID.",
                                                    LogType.Error);
                    }
                }
            }
        }
 /// <summary>
 /// プレイヤを死亡させる
 /// </summary>
 public void Kill()
 {
     if (_isDead)
     {
         return;
     }
     _isDead = true;
     _uts.TrySetResult(); // UniTaskを完了させる
 }
Esempio n. 5
0
        /// <summary>
        ///     Stop listening to the port
        /// </summary>
        public override void Disconnect()
        {
            _listenCompletionSource?.TrySetResult();

            _server?.Shutdown();
            _server = null;

            _client?.Disconnect();
            _client = null;
        }
Esempio n. 6
0
        /// <summary>
        ///     Shutdown the transport and disconnect server and clients.
        /// </summary>
        public override void Disconnect()
        {
            Config.PacketCache = new byte[Config.MaxPacketSizeInKb * 1024];

            _listenCompletionSource?.TrySetResult();

            _enetInitialized = false;

            _server?.Shutdown();
            _server = null;

            Library.Deinitialize();
        }
Esempio n. 7
0
 /// <summary>
 ///     Stop listening to the port
 /// </summary>
 public override void Disconnect()
 {
     socket?.Close();
     socket = null;
     ListenCompletionSource?.TrySetResult();
 }
Esempio n. 8
0
        /// <summary>
        ///     Internal data received from server.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="clientEpicId"></param>
        /// <param name="socket"></param>
        protected override void OnReceiveInternalData(InternalMessage type, ProductUserId clientEpicId, SocketId socket)
        {
            if (!Connected || _initialWait)
            {
                return;
            }

            switch (type)
            {
            case InternalMessage.Accept:

                if (Logger.logEnabled)
                {
                    if (Transport.transportDebug)
                    {
                        DebugLogger.RegularDebugLog(
                            "[Client] - Received internal message of server accepted our request to connect.");
                    }
                }

                _connectedComplete?.TrySetResult();

                break;

            case InternalMessage.Disconnect:
                Disconnect();

                if (Logger.logEnabled)
                {
                    if (Transport.transportDebug)
                    {
                        DebugLogger.RegularDebugLog(
                            "[Client] - Received internal message to disconnect epic user.");
                    }
                }

                break;

            case InternalMessage.TooManyUsers:

                if (Logger.logEnabled)
                {
                    if (Transport.transportDebug)
                    {
                        DebugLogger.RegularDebugLog(
                            "[Client] - Received internal message that there are too many users connected to server.",
                            LogType.Warning);
                    }
                }

                Error.Invoke(Result.LobbyTooManyPlayers, "Too many users currently connected.");

                break;

            default:

                if (Logger.logEnabled)
                {
                    if (Transport.transportDebug)
                    {
                        DebugLogger.RegularDebugLog(
                            $"[Client] - Cannot process internal message {type}. If this is anything other then {InternalMessage.Data} something has gone wrong.",
                            LogType.Warning);
                    }
                }
                break;
            }
        }