public ServerMonitorManageServerViewModel(ILog log, Guid serverId, UpdateClient updateClient) { _log = log; _serverId = serverId; _updateClient = updateClient; _updateClient.MissionHandler += UpdateClientOnMissionHandler; SetMissionCommand = new ActionCommand(() => { var m = SelectedMission; if (m != null) { var mn = m.Name; _updateClient.SendCommandAsync(UpdateClient.CommandType.Mission, mn); } }, () => SelectedMission != null); RefreshCommand = new ActionCommand(() => _updateClient.SendCommandAsync(UpdateClient.CommandType.Missions)); InitCommand = new ActionCommand(async() => { await _updateClient.SendCommandAsync(UpdateClient.CommandType.Init); MessageBox.Show("Executed", "Server command", MessageBoxButton.OK); }); ShutdownCommand = new ActionCommand(async () => { await _updateClient.SendCommandAsync(UpdateClient.CommandType.Shutdown); MessageBox.Show("Executed", "Server command", MessageBoxButton.OK); }); ReassignCommand = new ActionCommand(async () => { await _updateClient.SendCommandAsync(UpdateClient.CommandType.Reassign); MessageBox.Show("Executed", "Server command", MessageBoxButton.OK); }); RestartCommand = new ActionCommand(async () => { await _updateClient.SendCommandAsync(UpdateClient.CommandType.Restart); MessageBox.Show("Executed", "Server command", MessageBoxButton.OK); }); LockCommand = new ActionCommand(async () => { await _updateClient.SendCommandAsync(UpdateClient.CommandType.Lock); MessageBox.Show("Executed", "Server command", MessageBoxButton.OK); }); UnlockCommand = new ActionCommand(async () => { await _updateClient.SendCommandAsync(UpdateClient.CommandType.Unlock); MessageBox.Show("Executed", "Server command", MessageBoxButton.OK); }); LoadBansCommand = new ActionCommand(async () => { await _updateClient.SendCommandAsync(UpdateClient.CommandType.LoadBans); MessageBox.Show("Executed", "Server command", MessageBoxButton.OK); }); LoadScriptsCommand = new ActionCommand(async () => { await _updateClient.SendCommandAsync(UpdateClient.CommandType.LoadScripts); MessageBox.Show("Executed", "Server command", MessageBoxButton.OK); }); LoadEventsCommand = new ActionCommand(async () => { await _updateClient.SendCommandAsync(UpdateClient.CommandType.LoadEvents); MessageBox.Show("Executed", "Server command", MessageBoxButton.OK); }); }
public ServerMonitorModel(ServerInfo currentServer, ILog log, bool console = false) { _currentServer = currentServer; _log = log; _console = console; var host = IPHelper.GetIPAddress(_currentServer.Host); if (string.IsNullOrEmpty(host)) { var message = string.Format("Host is incorrect for server {0}", _currentServer.Name); _log.Error(message); throw new Exception(message); } SteamQueryViewModel = new ServerMonitorSteamQueryViewModel(_currentServer.Host, _currentServer.Port, _log); _updateClient = new UpdateClient(host, _currentServer.Port, _currentServer.Password, _log); _updateClient.PlayerHandler += (s, e) => PlayersViewModel.SetData(e); if (!console) { _updateClient.BanHandler += (s, e) => BansViewModel.SetData(e); _updateClient.AdminHandler += (s, e) => AdminsViewModel.SetData(e); } _updateClient.ConnectHandler += _updateClient_ConnectHandler; _updateClient.DisconnectHandler += _updateClient_DisconnectHandler; if (!console) { _updateClient.RConAdminLog += (s, e) => _updateClient.SendCommandAsync(UpdateClient.CommandType.Admins); } _updateClient.PlayerLog += (s, e) => _updateClient.SendCommandAsync(UpdateClient.CommandType.Players); if (!console) { _updateClient.BanLog += async (s, e) => { await _updateClient.SendCommandAsync(UpdateClient.CommandType.Players); await _updateClient.SendCommandAsync(UpdateClient.CommandType.Bans); }; } _updateClient.ConnectingHandler += (s, e) => RaisePropertyChanged("Connected"); PlayersViewModel = new ServerMonitorPlayerViewModel(_log, currentServer, _updateClient); if (!console) { BansViewModel = new ServerMonitorBansViewModel(_log, currentServer.Id, _updateClient); AdminsViewModel = new ServerMonitorAdminsViewModel(_log, currentServer, new ActionCommand(() => _updateClient.SendCommandAsync(UpdateClient.CommandType.Admins))); ManageServerViewModel = new ServerMonitorManageServerViewModel(_log, currentServer.Id, _updateClient); PlayerListModelView = new PlayerListModelView(_log, _updateClient, currentServer.Id); } ChatViewModel = new ServerMonitorChatViewModel(_log, currentServer.Id, _updateClient); _updateClientPeriodic = new UpdateClientPeriodic(_updateClient, log); _updateClientPeriodic.Start(); }