예제 #1
0
        async Task BroadcastLaggyGrids(CancellationToken cancellationToken)
        {
            if (_config.PunishType != PunishType.Broadcast)
            {
                _entityGpsBroadcaster.ClearGpss();
                return;
            }

            var allGpsSources = new Dictionary <long, GridGpsSource>();

            foreach (var(player, rank) in _players.Entities.GetLaggiestEntities(true).Indexed())
            {
                var playerId = player.Id;
                if (!_grids.TryGetLaggiestGridOwnedBy(playerId, out var laggiestGrid))
                {
                    continue;
                }

                var gpsSource = new GridGpsSource(laggiestGrid.Id, player.LagNormal, player.PinRemainingTime, rank);
                allGpsSources[gpsSource.GridId] = gpsSource;
            }

            foreach (var(grid, rank) in _grids.Entities.GetLaggiestEntities(true).Indexed())
            {
                var gpsSource = new GridGpsSource(grid.Id, grid.LagNormal, grid.PinRemainingTime, rank);
                allGpsSources[gpsSource.GridId] = gpsSource;
            }

            await VRageUtils.MoveToGameLoop(cancellationToken);

            _entityGpsBroadcaster.ReplaceGpss(allGpsSources.Values);
            await VRageUtils.MoveToThreadPool(cancellationToken);

            Log.Trace("broadcast done");
        }
예제 #2
0
        public async Task Main(CancellationToken canceller)
        {
            Log.Info("started main");

            await VRageUtils.MoveToGameLoop(canceller);

            _entityGpsBroadcaster.ClearGpss();
            await VRageUtils.MoveToThreadPool(canceller);

            _questTracker.Clear();

            // Wait for some time during the session startup
            await TaskUtils.Delay(() => _config.FirstIdleTime.Seconds(), 1.Seconds(), canceller);

            IsIdle = false;

            Log.Info("started collector loop");

            // MAIN LOOP
            while (!canceller.IsCancellationRequested)
            {
                if (!_config.IsEnabled)
                {
                    _grids.Clear();
                    _players.Clear();
                    _questTracker.Clear();
                    _punishExecutor.Clear();
                    _punishChatFeed.Clear();

                    await VRageUtils.MoveToGameLoop(canceller);

                    _entityGpsBroadcaster.ClearGpss();

                    await Task.Delay(1.Seconds(), canceller);

                    return;
                }

                using var _ = CustomProfiling.Profile("AutoModerator.Main");

                await Profile(canceller);

                FixExemptBlockTypeCollection();
                Warn();
                AnnouncePunishments();
                await Punish(canceller);
                await AnnounceDeletedGrids(canceller);

                Log.Debug("interval done");
            }
        }