Ejemplo n.º 1
0
        private async Task <NetworkPacket> ProcessRequest(StreamSocket socket, NetworkPacket packet)
        {
            AcknowledgePacket acknowledgement = new AcknowledgePacket();

            if (packet.Type == PacketType.LobbyCommand)
            {
                LobbyCommandPacket command  = packet as LobbyCommandPacket;
                string             playerID = command.PlayerID;

                switch ((int)command.Command)
                {
                case (int)LobbyCommands.EnterLobby:
                    string playerIPAddress = command.Data;
                    await ProcessEnterLobbyCommand(playerID, playerIPAddress);

                    break;

                case (int)LobbyCommands.LeaveLobby:
                    await ProcessLeaveLobbyCommand(playerID);

                    break;

                case (int)LobbyCommands.HostGame:
                    string hostIPAddress = command.Data;
                    await ProcessHostGameCommand(playerID, hostIPAddress);

                    break;

                case (int)LobbyCommands.JoinGame:
                    string hostID = command.Data;
                    await ProcessJoinGameCommand(playerID, hostID);

                    break;

                case (int)LobbyCommands.LeaveGame:
                    await ProcessLeaveGameCommand(playerID);

                    break;

                case (int)LobbyCommands.SetupGame:
                    await ProcessSetupGameCommand(playerID);

                    break;
                }
                await UpdateAllClients();
            }
            return(acknowledgement);
        }
Ejemplo n.º 2
0
        private async Task <NetworkPacket> ProcessRequest(StreamSocket socket, NetworkPacket packet)
        {
            AcknowledgePacket acknowledgement = new AcknowledgePacket();

            if (packet.Type == PacketType.LobbyCommand)
            {
                LobbyCommandPacket command = packet as LobbyCommandPacket;
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                              () => { OnLobbyCommand(command); });
            }
            else if (packet.Type == PacketType.LobbyData)
            {
                LobbyData lobbyData = packet as LobbyData;
                _playerList = lobbyData._playerList;
                _gameList   = lobbyData._gameList;
                OnPropertyChanged("playerList");
                OnPropertyChanged("gamesList");
            }
            return(acknowledgement);
        }