Exemplo n.º 1
0
        void InitialGridScan()
        {
            // Save before?

            MyVisualScriptLogicProvider.SendChatMessage("Scanning for offending grids..", "SERVER", 0, "Red");
            MyAPIGateway.Entities.GetEntities(entityList);

            foreach (var entity in entityList)
            {
                IMyCubeGrid grid = entity as IMyCubeGrid;

                if (grid == null)
                {
                    continue;
                }

                if (BroadcastManager.ContainsEntityId(grid.EntityId))
                {
                    continue;
                }

                GridValidator gridValidator = new GridValidator(grid.EntityId);
                GridStatus    gridStatus    = gridValidator.Validate(Config);

                if (gridStatus > GridStatus.Marked)
                {
                    MyVisualScriptLogicProvider.SendChatMessage("Tracking [" + grid.CustomName + "] - " + Enum.GetName(typeof(GridStatus), gridStatus), "SERVER", 0);

                    if (Config.AlertOwner)
                    {
                        BroadcastInfo broadcastInfo = gridValidator.GridToBroadcastInfo();
                        if (broadcastInfo.Location == Vector3D.Zero)
                        {
                            continue;
                        }

                        BroadcastError err = BroadcastManager.AddBroadcastInfo(broadcastInfo, false);

                        if (err == BroadcastError.Ok)
                        {
                            double timeInMinutes = (double)Config.GracePeriod / 60.0;

                            MyVisualScriptLogicProvider.SendChatMessage(
                                $"Warning [{grid.CustomName}] may be BROADCAST in {timeInMinutes} minutes." +
                                $" If this is not intentional please review the grid policy and correct immediately.",
                                "SERVER",
                                gridValidator.ownerId,
                                "Red");
                        }
                    }

                    trackedGrids.Add(grid.EntityId);
                }
            }
            MyVisualScriptLogicProvider.SendChatMessage($"Tracking {trackedGrids.Count} grids for possible broadcast", "SERVER", 0, "Red");
            entityList.Clear();
        }
Exemplo n.º 2
0
        public override void UpdateAfterSimulation()
        {
            tickCounter += 1;

            if (tickCounter < 60)
            {
                return;
            }
            else
            {
                tickCounter = 0;
            }

            // Todo - Implement proper timers and callbacks, this is all gross
            if (scanTimer <= 0)
            {
                if (graceTimer == Config.GracePeriod - 1)
                {
                    InitialGridScan();
                }
                else if (graceTimer <= 0)
                {
                    TrackedGridScan();

                    broadcastTimer = Config.BroadcastTime;
                    gpsTimer       = Config.GPSDiscardTime;
                    graceTimer     = Config.GracePeriod;
                    scanTimer      = Config.ScanInterval;
                }

                graceTimer -= 1;
            }
            else
            {
                scanTimer -= 1;
            }

            if (broadcastTimer > 0)
            {
                broadcastTimer -= 1;
                gpsTimer       -= 1;
                if (gpsTimer == 0)
                {
                    // Built in GPS DiscardAt is broken?
                    MyVisualScriptLogicProvider.RemoveGPSForAll(Config.SignalText);
                    gpsTimer = -1;
                }
            }
            else if (broadcastTimer == 0)
            {
                BroadcastManager.TrashBroadcasted();
                broadcastTimer = -1;
            }
        }
Exemplo n.º 3
0
        static void TrackedGridScan()
        {
            int count = 0;

            MyVisualScriptLogicProvider.SendChatMessage("Checking for grids to broadcast..", "SERVER", 0, "Red");
            List <long> gridsToTrash = new List <long>();

            foreach (long entityId in trackedGrids)
            {
                // Validating twice, it maybe better to instead listen for events on the grid
                GridValidator gridValidator = new GridValidator(entityId);
                GridStatus    gridStatus    = gridValidator.Validate(Config);

                if (gridStatus > GridStatus.Marked)
                {
                    BroadcastInfo  broadcastInfo = gridValidator.GridToBroadcastInfo();
                    BroadcastError err           = BroadcastManager.AddBroadcastInfo(broadcastInfo, true);

                    switch (err)
                    {
                    case BroadcastError.NotEnoughBlocks:
                    case BroadcastError.NotEnoughFatBlocks:
                    case BroadcastError.TooFarFromPlayers:
                        MyVisualScriptLogicProvider.SendChatMessage($"Trashing {broadcastInfo} {Enum.GetName(typeof(BroadcastError), err)}", "SERVER", 0, "Red");
                        gridsToTrash.Add(entityId);
                        break;

                    case BroadcastError.TooCloseToPlayers:
                        MyVisualScriptLogicProvider.SendChatMessage($"Ignoring {broadcastInfo} {Enum.GetName(typeof(BroadcastError), err)}", "SERVER", 0, "Red");
                        break;

                    default:
                        MyVisualScriptLogicProvider.SendChatMessage($"Broadcasting {broadcastInfo}", "SERVER", 0, "Red");
                        count++;
                        break;
                    }
                }
            }

            Util.TrashGrids(gridsToTrash);
            trackedGrids.Clear();
        }