Beispiel #1
0
 private async Task ProcessEnterLobbyCommand(string playerID, string ipAddress)
 {
     if (_playerList.ContainsKey(playerID))
     {
         // TODO: need to handle case where we are logging in a second time, possibly after disconnecting.
         // For now, simply tell the old client to close.
         LobbyCommandPacket ejectUser = new LobbyCommandPacket(playerID, LobbyCommands.EjectThisUser);
         string             address   = _playerList[playerID].IPAddress;
         NetworkPacket      reply     = await _connection.ConnectAndWaitResponse(address, NetworkPorts.LobbyClientPort, ejectUser);
     }
     else
     {
         PlayerData player = new PlayerData(new Player(playerID), ipAddress, NetworkPorts.GameClientPort);
         _playerList.Add(playerID, player);
     }
 }
Beispiel #2
0
        private async Task <NetworkPacket> SendLobbyCommand(string playerID, LobbyCommands command, string args = null)
        {
            try
            {
                LobbyCommandPacket commandPacket = new LobbyCommandPacket(playerID, command, args);
                return(await _connection.ConnectAndWaitResponse(_serverAddress, NetworkPorts.LobbyServerPort, commandPacket));
            } catch (Exception)
            {
                // TODO throw custom exception for gameview to deal with
                // for now, fire LobbyCommand.Disconnected.
                LobbyCommandPacket packet = new LobbyCommandPacket("Client", LobbyCommands.Disconnected);
                OnLobbyCommand(packet);
            }

            return(null as NetworkPacket);
        }