Esempio 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;
                }
                try
                {
                    await UpdateAllClients();
                } catch (Exception)
                {
                    throw;
                }
                OnPropertyChanged("gamesList");
                OnPropertyChanged("playerList");
            }
            return(acknowledgement);
        }
Esempio n. 2
0
        private async Task SendLobbyCommandToClient(PlayerData player, LobbyCommands command)
        {
            LobbyCommandPacket commandPacket = new LobbyCommandPacket(player.PlayerID, command);

            try
            {
                await _connection.ConnectAndWaitResponse(player.IPAddress, NetworkPorts.LobbyClientPort, commandPacket);
            } catch (Exception e)
            {
                log("Failed to send command to remote client: HResult=" + e.HResult);
                log("Command: " + commandPacket.Command + " Player: " + player.PlayerID);
            }
        }
Esempio n. 3
0
 private async Task EjectUser(string playerID)
 {
     // Send an command to the client to disconnect
     try
     {
         string             address   = _playerList[playerID].IPAddress;
         LobbyCommandPacket ejectUser = new LobbyCommandPacket(playerID, LobbyCommands.EjectThisUser);
         NetworkPacket      reply     = await _connection.ConnectAndWaitResponse(address, NetworkPorts.LobbyClientPort, ejectUser);
     } catch (Exception)
     {
         // but if it doesn't work (possibly the client is disconnected) then we can safely ignore it and move on
         // the new client will use the old data.
     }
 }
Esempio n. 4
0
 internal LobbyCommandEventArgs(LobbyCommandPacket packet)
 {
     Packet = packet;
 }