Пример #1
0
        private async void AcceptMessage()
        {
            if (enabled)
            {
                //Await message
                object acceptedObject = await standardizedTCP.ReadObject();

                //Check for error
                if (acceptedObject == null)
                {
                    //Error has occured
                    Disable();
                    return;
                }
                else
                {
                    AcceptMessage();
                }

                if (acceptedObject is IClientMessage)
                {
                    lock (messageLock)
                    {
                        clientMessages.Add((IClientMessage)acceptedObject);
                    }
                }
                else
                {
                    throw new Exception("Message of invalid type received in stream.");
                }
            }
        }
Пример #2
0
        private async void EstablishClient(LobbySorter lobbySorter)
        {
            //Wait for client info object
            object receivedObject;

            do
            {
                //Wait for object
                receivedObject = await standardizedTCP.ReadObject();

                //Ensure no error
                if (receivedObject == null)
                {
                    //Error in connection, close
                    Close(true, false);
                    return;
                }
            }while (!(receivedObject is ClientInfoMessage));

            //Cast to client info
            clientInfo = ((ClientInfoMessage)receivedObject).ClientInfo;

            //Send client to lobbies
            ServerInfo serverInfo;

            lobby       = lobbySorter.Invoke(this, out serverInfo);
            ClientIndex = serverInfo.ClientIndex;

            //Send server information
            SendMessage(new ServerInfoMessage(serverInfo));

            //Send client information
            lobby.ForwardToClients(this, new PeerClientInfoMessage(PeerClientInfo));

            //Request client information
            lobby.SendClientInformation(this);

            //Start client readers
            ClientReaderTCP();
            ClientReaderUDP();
        }