예제 #1
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();
        }
예제 #2
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");
        }