public async Task ServerName()
 {
     try
     {
         var serverInfoCommand         = new ServerInfoCommand().ExecuteAsync(Interface.XfQueryBot.QueryClient);
         var serverInfoCommandResponse = serverInfoCommand.Result;
         var onlineUsers = serverInfoCommandResponse.NumberOfClientsOnline;
         var onlineQuery = serverInfoCommandResponse.NumberOfQueryClientsOnline;
         var realClients = onlineUsers - onlineQuery;
         var maxClients  = serverInfoCommandResponse.MaximumClientsAllowed;
         var percent     = (int)Math.Round((double)(100 * realClients) / maxClients);
         var virtualServerModification = new VirtualServerModification
         {
             Name = _config.ServerName
                    .Replace("[ONLINEUSERS]", realClients.ToString())
                    .Replace("[MAXUSERS]", maxClients.ToString())
                    .Replace("[ONLINEPERCENT]", percent.ToString())
                    .Replace("[ONLINEQUERY]", onlineQuery.ToString())
         };
         await new ServerEditCommand(virtualServerModification).ExecuteAsync(Interface.XfQueryBot.QueryClient);
     }
     catch (Exception ex)
     {
         _log.Error($"({_extension.Name}) : {ex}");
     }
 }
Exemple #2
0
        public RconClient()
        {
            log.Debug("RconClient startup");
            Random rnd = new Random();

            _doneCommand = "$^!(\"done." + rnd.Next(0, int.MaxValue) + ".done\")!^$"; // Some random string that won't show up in any of our data

            MapInfo = new Dictionary <string, MapInfo>();

            AddMaps();

            PlayerListCommand = new PlayerListCommand(this);
            ServerInfoCommand = new ServerInfoCommand(this);
            //GetAdminListCommand = new GetAdminListCommand(this);
            ClientChatBufferCommand = new ClientChatBufferCommand(this);
            Command = new SimpleCommand(this);

            LoadModules();
        }
Exemple #3
0
        private async void StartPollingTimers()
        {
            log.Trace("StartPollingTimers(): Start.");

            var c1 = new CancellationTokenSource();
            var c2 = new CancellationTokenSource();
            var c3 = new CancellationTokenSource();
            var c4 = new CancellationTokenSource();


            Task.Run(async() =>
            {
                try
                {
                    await PeriodicTaskFactory.Start(
                        () => PlayerListCommand.RefreshPlayerList(),
                        cancelToken: c1.Token,
                        intervalInMilliseconds:
                        this.Config.PollIntervalMs_PlayerListCommand,
                        delayInMilliseconds: 1000,
                        synchronous: true);
                }
                catch (OperationCanceledException operationCanceledException) { }
                catch (Exception exception) { }
            });
            Task.Run(async() =>
            {
                try
                {
                    await PeriodicTaskFactory.Start(
                        () =>
                        ServerInfoCommand.RefreshServerInfo(),
                        cancelToken: c2.Token,
                        intervalInMilliseconds: this.Config.PollIntervalMs_ServerInfoCommand,
                        delayInMilliseconds: 1000,
                        synchronous: true);
                }
                catch (OperationCanceledException operationCanceledException) { }
                catch (Exception exception) { }
            });
            Task.Run(async() =>
            {
                try
                {
                    await PeriodicTaskFactory.Start(
                        () =>
                        ClientChatBufferCommand.RefreshClientChatBufferCommand(),
                        cancelToken: c3.Token,
                        intervalInMilliseconds: this.Config.PollIntervalMs_ClientChatBufferCommand,
                        delayInMilliseconds: 1000,
                        synchronous: true);
                }
                catch (OperationCanceledException operationCanceledException) { }
                catch (Exception exception) { }
            });
            //Task.Run(async () =>
            //{
            //    try
            //    {
            //        await PeriodicTaskFactory.Start(() => GetAdminListCommand.RefreshAdminList(), cancelToken: c4.Token, intervalInMilliseconds: this.Config.PollIntervalMs_AdminListCommand, delayInMilliseconds: 1000, synchronous: true);
            //    }
            //    catch (OperationCanceledException operationCanceledException) { }
            //});



            _pollingTimerCancelAction = new Action(() =>
            {
                c1.Cancel();
                c2.Cancel();
                c3.Cancel();
                c4.Cancel();
            });

            //while (true)
            //{
            //    PlayerListCommand.RefreshPlayerList();
            //    ServerInfoCommand.RefreshServerInfo();
            //    ClientChatBufferCommand.RefreshClientChatBufferCommand();
            //    //GetAdminListCommand.RefreshAdminList();

            //    await Task.Delay(StatusPullDelayMs);
            //    if (!_connected)
            //        break;
            //}
            log.Trace("StartPollingTimers(): End");
        }