Пример #1
0
        public PlayerListModelView(ILog log, UpdateClient updateClient, Guid serverId)
        {
            _log = log;
            _updateClient = updateClient;
            _serverId = serverId;

            _playerHelper = new PlayerHelper(_log, serverId, _updateClient);
            _selectedOptions = "Name,IP,Guid,Comment";
        }
Пример #2
0
        //  private readonly SelfServiceReference.Arma3ServiceContractClient Arma3ServiceContractClient = new Arma3ServiceContractClient(new InstanceContext(new Callback()));
        public ServerWorker(ServerInfo serverInfo, ILog log)
        {
            _log = log;

            var ip = IPHelper.GetIPAddress(serverInfo.Host);
            _client = new UpdateClient(ip, serverInfo.Port, serverInfo.Password, log);

            _client.ChatMessageHandler += _client_ChatMessageHandler;
        }
        public ServerMonitorChatViewModel(ILog log, Guid serverId, UpdateClient updateClient)
        {
            _log = log;
            _serverId = serverId;
            _updateClient = updateClient;

            AutoScroll = true;
            EnableChat = true;

            _chatHelper = new ChatHelper(_log, _serverId);
            _updateClient.ChatMessageHandler += _updateClient_ChatMessageHandler;

            ShowHistoryCommand = new ActionCommand(() =>
            {
                var model = new ChatHistoryViewModel(serverId);
                model.StartDate = DateTime.UtcNow.AddHours(-5);
                var wnd = new ChatHistory(model);
                wnd.Show();
                wnd.Activate();
            });
        }
Пример #4
0
        public UpdateClientPeriodic(UpdateClient updateClient, ILog log)
        {
            _updateClient = updateClient;
            _log = log;

            //_updateTimerPlayers = new Timer((args) =>
            //{
            //    try
            //    {
            //        if (_updateClient.Connected)
            //        {
            //            _updateClient.SendCommand(UpdateClient.CommandType.Players);

            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        _log.Error(e);
            //    }
            //});

            //_updateTimerBans = new Timer((args) =>
            //{
            //    try
            //    {
            //        if (_updateClient.Connected)
            //        {
            //            _updateClient.SendCommand(UpdateClient.CommandType.Bans);

            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        _log.Error(e);
            //    }
            //});

            //_updateTimerAdmins = new Timer((args) =>
            //{
            //    try
            //    {
            //        if (_updateClient.Connected)
            //        {
            //            _updateClient.SendCommand(UpdateClient.CommandType.Admins);

            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        _log.Error(e);
            //    }
            //});

            _updateTimerKeepAlive = new Timer(args =>
            {
                try
                {
                    if (!_updateClient.Connected && !_updateClient.Disposed)
                    {
                        _updateClient.Disconnect();
                        _updateClient.Connect();
                    }
                }
                catch (Exception e)
                {
                    _log.Error(e);
                }
            });
        }
        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);
            });
        }
Пример #6
0
        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();
        }