public ServerInfoControl(ServerInfo serverInfo) { InitializeComponent(); _model = new ServerMonitorModel(serverInfo, new Log()); this.DataContext = _model; //_model.Connect(); Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted; }
private static ServerMonitorModel OpenServerInfo(ServerInfo obj, ILog log) { var model = new ServerMonitorModel(obj, log, true); model.ChatViewModel.ChatMessageEventHandler += (s, e) => { Console.WriteLine(@"{0} {1:t}:{2}", model.CurrentServer.Name, e.Date.ToLocalTime(), e.Message); Console.WriteLine(); }; return model; }
public ServerInfoModel() { var model = new ServerInfo(); model.Id = Guid.Empty; _info = model; }
public ServerInfoModel(ServerInfo info) { _info = info; if (_info != null) { Host = _info.Host; Port = _info.Port; Password = _info.Password; Name = _info.Name; } }
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(); }