示例#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();
        }
示例#2
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();
        }