Example #1
0
        private bool FilterServer(ServerObservable server)
        {
            if (!_showEmpty && server.Players == 0)
            {
                return(false);
            }
            if (!_showFull && server.Players == server.MaxPlayers)
            {
                return(false);
            }
            if (!_showPassworded && server.RequiresPw)
            {
                return(false);
            }
            if (server.Players < _minPlayers)
            {
                return(false);
            }
            if (server.Players > _maxPlayers)
            {
                return(false);
            }
            if (server.Latency != uint.MaxValue && server.Latency > _maxLatency)
            {
                return(false);
            }
            if (!_searchString.Equals(String.Empty) && !Regex.IsMatch(server.Name, Regex.Escape(_searchString), RegexOptions.IgnoreCase))
            {
                return(false);
            }

            return(true);
        }
        private void ServerBrowserOnMouseDoubleClick(Object sender, MouseButtonEventArgs e)
        {
            FrameworkElement source = e.OriginalSource as FrameworkElement;
            ServerObservable server = source.DataContext as ServerObservable;

            _viewModel.DoJoin(server);
        }
        private void ServerBrowserOnSelectionChanged(Object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0)
            {
                _viewModel.SelectedServer = null;
                return;
            }

            ServerObservable server = e.AddedItems[0] as ServerObservable;

            _viewModel.SelectedServer = server;
            _viewModel.DoPingOne(server);
        }
        public async void DoPingOne(ServerObservable server)
        {
            PingResult result = await _serverList.PingOne(server.Address);

            // Disable and enable filtering and sorting on latency to prevent servers from moving/disappearing.
            if (_serversView.CurrentSort.Equals("Latency"))
            {
                _serversView.DisableLiveUpdates("Latency");
            }
            HandlePingResult(result);
            if (_serversView.CurrentSort.Equals("Latency"))
            {
                _serversView.EnableLiveUpdates("Latency");
            }
        }
        private void HandlePingResult(PingResult result)
        {
            if (result == null)
            {
                return;
            }

            if (_servers.Contains(result.Address))
            {
                ServerObservable server = _servers[result.Address];
                if (result.Reply.Status == IPStatus.Success)
                {
                    server.Latency = (uint)result.Reply.RoundtripTime;
                }
                else
                {
                    server.Latency = uint.MaxValue;
                }
            }
        }
        public async void DoRefresh()
        {
            Exception exception = null;

            try
            {
                IEnumerable <Server> newServers = await _serverList.Refresh();

                ISet <ServerObservable> removedServers = new HashSet <ServerObservable>(_servers.Values);
                foreach (Server serverData in newServers)
                {
                    ServerObservable server = Mapper.Map <Server, ServerObservable>(serverData);

                    if (_servers.Contains(server.Key))
                    {
                        ServerObservable existingServer = _servers[serverData.Address];
                        Mapper.Map(server, existingServer);
                    }
                    else
                    {
                        _servers.Add(server);
                    }
                    removedServers.Remove(server);
                }

                foreach (ServerObservable serverData in removedServers)
                {
                    _servers.Remove(serverData.Key);
                }

                DoPingAll();
            }
            catch (Exception e) { exception = e; }

            if (exception != null)
            {
                await _popupService.ShowMessageBox("Error refreshing server list",
                                                   "Could not refresh the server list. " + exception.Message, MessageBoxImage.Error);
            }
        }
 public void CopyAddress(ServerObservable server)
 {
     Clipboard.SetText(server.Address);
 }
        public async void DoJoin(ServerObservable server)
        {
            if (server != null)
            {
                String name = _configuration.Name;
                if (name == null || name.Equals(String.Empty))
                {
                    await _popupService.ShowMessageBox("No player name",
                                                       "Please fill in a player name in the top right corner of the application.", MessageBoxImage.Hand);

                    return;
                }

                String installLocation = _configuration.InstallLocation;
                if (!IsValidInstallLocation(installLocation))
                {
                    installLocation = _launcher.InstallLocationFromRegistry();
                }
                if (!IsValidInstallLocation(installLocation))
                {
                    installLocation = _launcher.DefaultInstallLocation();
                }
                if (!IsValidInstallLocation(installLocation))
                {
                    MessageBoxResult result = await _popupService.ShowMessageBox(
                        "Could not determine RenegadeX's installation location",
                        "Could not determine the RenegadeX's installation location, please locate the installation directory in the following popup.",
                        MessageBoxImage.Question, MessageBoxButton.OKCancel);

                    if (result == MessageBoxResult.OK)
                    {
                        installLocation = await _popupService.ShowFolderDialog("Choose RenegadeX installation location");
                    }
                    else
                    {
                        installLocation = String.Empty;
                        return;
                    }
                }
                if (!IsValidInstallLocation(installLocation))
                {
                    await _popupService.ShowMessageBox("Invalid installation location",
                                                       "The specified installation location is invalid.", MessageBoxImage.Error);

                    installLocation = String.Empty;
                    return;
                }

                String password = String.Empty;
                if (server.RequiresPw)
                {
                    password = _popupService.ShowInputDialog("Password required", "Please fill in the server's password.", true);
                    if (password == null)
                    {
                        return;
                    }
                }

                Exception exception = null;
                try
                {
                    await _launcher.Launch(installLocation, server.Address, name, password);
                }
                catch (Exception e) { exception = e; }

                if (exception != null)
                {
                    await _popupService.ShowMessageBox("Error launching game", "Could not launch the game. " +
                                                       exception.Message, MessageBoxImage.Error);
                }
            }
        }
        private bool FilterServer(ServerObservable server)
        {
            if (!_showEmpty && server.Players == 0)
                return false;
            if (!_showFull && server.Players == server.MaxPlayers)
                return false;
            if (!_showPassworded && server.RequiresPw)
                return false;
            if (server.Players < _minPlayers)
                return false;
            if (server.Players > _maxPlayers)
                return false;
            if (server.Latency != uint.MaxValue && server.Latency > _maxLatency)
                return false;
            if (!_searchString.Equals(String.Empty) && !Regex.IsMatch(server.Name, Regex.Escape(_searchString), RegexOptions.IgnoreCase))
                return false;

            return true;
        }
 public void CopyAddress(ServerObservable server)
 {
     Clipboard.SetText(server.Address);
 }
        public async void DoJoin(ServerObservable server)
        {
            if (server != null)
            {
                String name = _configuration.Name;
                if (name == null || name.Equals(String.Empty))
                {
                    await _popupService.ShowMessageBox("No player name",
                        "Please fill in a player name in the top right corner of the application.", MessageBoxImage.Hand);
                    return;
                }

                String installLocation = _configuration.InstallLocation;
                if (!IsValidInstallLocation(installLocation))
                {
                    installLocation = _launcher.InstallLocationFromRegistry();
                }
                if (!IsValidInstallLocation(installLocation))
                {
                    installLocation = _launcher.DefaultInstallLocation();
                }
                if (!IsValidInstallLocation(installLocation))
                {
                    MessageBoxResult result = await _popupService.ShowMessageBox(
                        "Could not determine RenegadeX's installation location",
                        "Could not determine the RenegadeX's installation location, please locate the installation directory in the following popup.",
                        MessageBoxImage.Question, MessageBoxButton.OKCancel);
                    if (result == MessageBoxResult.OK)
                        installLocation = await _popupService.ShowFolderDialog("Choose RenegadeX installation location");
                    else
                    {
                        installLocation = String.Empty;
                        return;
                    }
                }
                if (!IsValidInstallLocation(installLocation))
                {
                    await _popupService.ShowMessageBox("Invalid installation location",
                        "The specified installation location is invalid.", MessageBoxImage.Error);
                    installLocation = String.Empty;
                    return;
                }

                String password = String.Empty;
                if (server.RequiresPw)
                {
                    password = _popupService.ShowInputDialog("Password required", "Please fill in the server's password.", true);
                    if (password == null)
                        return;
                }

                Exception exception = null;
                try
                {
                    await _launcher.Launch(installLocation, server.Address, name, password);
                }
                catch (Exception e) { exception = e; }

                if (exception != null)
                    await _popupService.ShowMessageBox("Error launching game", "Could not launch the game. " +
                        exception.Message, MessageBoxImage.Error);
            }
        }
        public async void DoPingOne(ServerObservable server)
        {
            PingResult result = await _serverList.PingOne(server.Address);

            // Disable and enable filtering and sorting on latency to prevent servers from moving/disappearing.
            if (_serversView.CurrentSort.Equals("Latency"))
                _serversView.DisableLiveUpdates("Latency");
            HandlePingResult(result);
            if (_serversView.CurrentSort.Equals("Latency"))
                _serversView.EnableLiveUpdates("Latency");
        }