Пример #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();
        }
Пример #3
0
        public static BroadcastError AddBroadcastInfo(BroadcastInfo broadcastInfo, bool broadcast = false)
        {
            HashSet <long> playersToNotify;
            BroadcastError err = PlayersWithinSafeRange(broadcastInfo.Location, out playersToNotify);

            if (err == BroadcastError.TooCloseToPlayers || err == BroadcastError.TooFarFromPlayers)
            {
                return(err);
            }
            else
            {
                err = ValidateBlockRequirements(broadcastInfo);

                if (err != BroadcastError.Ok)
                {
                    return(err);
                }

                if (err == BroadcastError.Ok && broadcast == true)
                {
                    foreach (long identityId in playersToNotify)
                    {
                        // If player near owned Antenna consider adding more detils to grid description and increasing range
                        // e.g. Antenna Size (big/small), Est. Grid Power, Grid Name, Ship/Station
                        IMyGps myGPS = AddGPSToPlayer(identityId, broadcastInfo);

                        if (myGPS != null)
                        {
                            broadcastInfo.MyGps.Add(myGPS);
                        }
                    }
                    BroadcastingGrids.Add(broadcastInfo);
                    MyVisualScriptLogicProvider.SendChatMessage($"Broadcasting {BroadcastingGrids.Count} offending grids", "SERVER", 0, "Red");
                }

                return(BroadcastError.Ok);
            }
        }