public void AddPlayerToServer(Server server, Player player)
        {
            Dispatcher.Invoke(DispatcherPriority.Normal, new Procedure(() =>
            {
                if (server.Players == null)
                {
                    server.Players = new ObservableCollection<Player>();
                }

                server.Players.Add(player);
            }));
        }
Example #2
0
        private void ConnectToServer(Server server)
        {
            if (server == null)
            {
                return;
            }

            if (server.State != Server.StateEnum.Succeeded)
            {
                return;
            }

            launcher = LauncherFactory.CreateLauncher(server.SourceEngine);
            launcher.JoiningServer = true;
            launcher.ServerSourceEngine = server.SourceEngine;
            launcher.ServerAddress = server.Address;
            launcher.ServerGameFolderName = server.GameFolder;
            launcher.ServerMapName = server.Map;
            launcher.Interface = (ILauncher)this;

            try
            {
                launcher.Verify();
            }
            catch (Launcher.AbortLaunchException)
            {
                return;
            }
            catch (ApplicationException ex)
            {
                Common.Message(this, null, ex);
                return;
            }
            catch (Exception ex)
            {
                Common.Message(this, null, ex, MessageWindow.Flags.Error);
                return;
            }

            canOpenServer = false;
            MinimiseToTray();

            // launch the game
            try
            {
                launcher.Run();
            }
            catch (Exception ex)
            {
                RestoreFromTray();
                FileOperationList.Execute();
                canOpenServer = true;
                Common.Message(this, "Error launching game.", ex, MessageWindow.Flags.Error);
                return;
            }

            SystemTrayIcon.Text = "Looking for game process...";

            // enable the tray context menu
            TrayContextMenuEnable(true);
        }
        public void SetServerProperty(Server server, String propertyName, Object propertyValue)
        {
            Dispatcher.Invoke(DispatcherPriority.Normal, new Procedure(() =>
            {
                PropertyInfo piMatch = Common.FirstOrDefault<PropertyInfo>(typeof(Server).GetProperties(), pi => pi.Name == propertyName);

                if (piMatch != null)
                {
                    piMatch.SetValue(server, propertyValue, null);
                }
                else
                {
                    Debug.Fail(String.Format("Invalid server property \"{0}\"", propertyName));
                }
            }));
        }