Пример #1
0
        /// <summary>
        /// On a new thread setup all the required information
        /// </summary>
        /// <param name="newClient">The TcpClient used for communication</param>
        private void SetupNewClient(TcpClient newClient)
        {
            var serverReference = new ServerClientReference(Guid.NewGuid(), newClient, OnClientStatusChanged, ListenerCancelToken);

            serverReference.OnClientWon += OnWinnerFound;
            OnClientStatusChanged?.Invoke(serverReference, ConnectionType.Connected);
        }
Пример #2
0
 private void SetClientStatus(ClientStatus status)
 {
     ClientStatus = status;
     OnClientStatusChanged?.Invoke(this, status);
 }
 private void Client_OnClientEvent(ClientStateEventArgs args)
 => OnClientStatusChanged?.Invoke(args);
Пример #4
0
        private void v_ReceivedMessage(object peer)
        {
            NetIncomingMessage msg = Server.ReadMessage();

            switch (msg.MessageType)
            {
            case NetIncomingMessageType.Error:
                OnError?.Invoke(msg.ReadString());

                break;



            case NetIncomingMessageType.StatusChanged:
                OnClientStatusChanged?.Invoke(msg.SenderConnection, msg.SenderConnection.Status);

                if (msg.SenderConnection.Status == NetConnectionStatus.Connected)
                {
                    OnClientConnected?.Invoke(msg.SenderConnection);
                }

                break;


            case NetIncomingMessageType.ConnectionApproval:
                v_HandleConnectionAuth(msg);

                break;


            case NetIncomingMessageType.Data:
                v_HandlePacket(msg);

                break;


            case NetIncomingMessageType.DiscoveryRequest:
                if (!DiscoveryResponse(msg, Server, out NetOutgoingMessage resp))
                {
                    break;
                }

                Server.SendDiscoveryResponse(resp, msg.SenderEndPoint);

                break;


            case NetIncomingMessageType.VerboseDebugMessage:
            case NetIncomingMessageType.DebugMessage:
                OnDebugMessage?.Invoke(msg.ReadString());

                break;


            case NetIncomingMessageType.WarningMessage:
                OnWarningMessage?.Invoke(msg.ReadString());

                break;


            case NetIncomingMessageType.ErrorMessage:
                OnErrorMessage?.Invoke(msg.ReadString());

                break;
            }
            Server.Recycle(msg);
        }