public void DetectRotorguns()
        {
            List <string> args = Context.Args;

            bool gps = false;

            for (int i = 0; i < args.Count; i++)
            {
                if (args[i] == "-gps")
                {
                    gps = true;
                }
            }

            StringBuilder sb = new StringBuilder();

            foreach (var group in MyCubeGridGroups.Static.Physical.Groups)
            {
                int gridsWithRotorCount = CheckGroup(out MyCubeGrid biggestGrid, group);

                if (biggestGrid != null && gridsWithRotorCount >= Plugin.MinRotorGridCount)
                {
                    var gridOwnerList = biggestGrid.BigOwners;
                    var ownerCnt      = gridOwnerList.Count;
                    var gridOwner     = 0L;

                    if (ownerCnt > 0 && gridOwnerList[0] != 0)
                    {
                        gridOwner = gridOwnerList[0];
                    }
                    else if (ownerCnt > 1)
                    {
                        gridOwner = gridOwnerList[1];
                    }

                    var position = biggestGrid.PositionComp.GetPosition();

                    sb.AppendLine($"{biggestGrid.DisplayName}");
                    sb.AppendLine($"   Owned by {PlayerUtils.GetPlayerNameById(gridOwner)}");
                    sb.AppendLine($"   Location: X: {position.X.ToString("#,##0.00")}, Y: {position.Y.ToString("#,##0.00")}, Z: {position.Z.ToString("#,##0.00")}");

                    if (gps && Context.Player != null)
                    {
                        var gridGPS = MyAPIGateway.Session?.GPS.Create("--" + biggestGrid.DisplayName, ($"{biggestGrid.DisplayName} - {biggestGrid.GridSizeEnum} - {biggestGrid.BlocksCount} blocks"), position, true);

                        MyAPIGateway.Session?.GPS.AddGps(Context.Player.IdentityId, gridGPS);
                    }
                }
            }

            if (Context.Player == null)
            {
                Context.Respond($"Potential Rotorguns");
                Context.Respond(sb.ToString());
            }
            else
            {
                ModCommunication.SendMessageTo(new DialogMessage("Potential Rotorguns", $"At least " + Plugin.MinRotorGridCount + " rotors on different subgrids.", sb.ToString()), Context.Player.SteamUserId);
            }
        }
예제 #2
0
        private void LogGrid(MyCubeGrid grid)
        {
            try {
                long ownerId = OwnershipUtils.GetOwner(grid);

                string name = PlayerUtils.GetPlayerNameById(ownerId);

                IMyFaction faction = GetFactionForPlayer(ownerId);

                string factionString = "";
                if (faction != null)
                {
                    factionString = "[" + faction.Tag + "]";
                }

                string ownedString = "Owned by: " + name + " " + factionString;

                long   gridId   = grid.EntityId;
                string gridName = grid.DisplayName;

                Log.Info("Broadcasted " + gridId + " " + gridName + " " + ownedString);
            } catch (Exception e) {
                Log.Error(e);
            }
        }
        private void ListInternal(PurchaseMode mode, bool filterRandom = true)
        {
            var buyables = FindFilteredBuyables(mode, filterRandom);

            List <string> lines = new List <string>();

            foreach (var entry in buyables)
            {
                long identityId = entry.Key;

                List <PurchaseMode> modes = entry.Value.ToList();
                modes.Sort();

                IMyFaction faction = FactionUtils.GetPlayerFaction(identityId);

                string factionString = "";
                if (faction != null)
                {
                    factionString = "[" + faction.Tag + "]";
                }

                string name     = PlayerUtils.GetPlayerNameById(identityId) + " " + factionString;
                string modesStr = string.Join(", ", modes);

                lines.Add(name + " -- " + modesStr);
            }

            lines.Sort();

            StringBuilder sb = new StringBuilder();

            foreach (var line in lines)
            {
                sb.AppendLine(line);
            }

            if (Context.Player == null)
            {
                Context.Respond($"Buyable GPS for " + mode);
                Context.Respond(sb.ToString());
            }
            else
            {
                ModCommunication.SendMessageTo(new DialogMessage("Buyable GPS", "For " + mode, sb.ToString()), Context.Player.SteamUserId);
            }
        }
예제 #4
0
        private void ChangeCooldownOnFactionChange(long identityId)
        {
            var cooldownMs = Config.CooldownMinutesFactionChange * 60 * 1000L;

            ulong steamId    = MySession.Static.Players.TryGetSteamId(identityId);
            var   steamIdKey = new SteamIdCooldownKey(steamId);

            if (cooldownMs <= 0)
            {
                CooldownManagerFactionChange.StopCooldown(steamIdKey);
            }
            else
            {
                CooldownManagerFactionChange.StartCooldown(steamIdKey, COOLDOWN_COMMAND, cooldownMs);
            }

            Log.Info("Player " + PlayerUtils.GetPlayerNameById(identityId) + " was put into Cooldown for Faction Change");
        }
예제 #5
0
        public void NotifyPlayer(long identityId)
        {
            string message;

            if (Config.NotifyDelaySeconds <= 0)
            {
                message = "Watch out! Someone bought your current location. They will be here soon!";
            }
            else
            {
                message = "Watch out! Someone bought your current location within the last " + Config.NotifyDelaySeconds.ToString("#,##0") + " seconds. They will be here soon!";
            }

            MyVisualScriptLogicProvider.ShowNotification(
                message, 10000, MyFontEnum.White, identityId);

            MyVisualScriptLogicProvider.SendChatMessage(
                message, Torch.Config.ChatName, identityId, MyFontEnum.Red);

            Log.Info("Identity " + identityId + " (" + PlayerUtils.GetPlayerNameById(identityId) + ") was Notified about their GPS being bought!");
        }
예제 #6
0
        public string CreatePathForPlayer(string path, long playerId)
        {
            string folderName;

            if (Config.UseSteamId)
            {
                ulong steamId = MySession.Static.Players.TryGetSteamId(playerId);

                folderName = steamId.ToString();
            }
            else
            {
                folderName = playerId.ToString();
            }

            if (Config.PlayerNameOnFolders)
            {
                /*
                 * Usually all calling locations could deal with a MyIdentity instead.
                 * But I dont want to deal with NULL values to get Nobody Grids exported.
                 */
                string playerName = PlayerUtils.GetPlayerNameById(playerId);

                foreach (var c in Path.GetInvalidFileNameChars())
                {
                    playerName = playerName.Replace(c, '_');
                }

                folderName = playerName + "_" + folderName;
            }

            var folder = Path.Combine(path, folderName);

            Directory.CreateDirectory(folder);

            return(folder);
        }
        public static void PatchOnDestroyRequest(MyCubeBlock __instance)
        {
            MyCubeBlock block = __instance;

            if (block as MyTerminalBlock == null)
            {
                return;
            }

            MyCubeGrid grid = block.CubeGrid;

            string gridName = grid.DisplayName;

            string oldOwnerName = PlayerUtils.GetPlayerNameById(block.OwnerId);

            bool   isOnline     = PlayerUtils.isOnline(block.OwnerId);
            string onlineString = "[Off]";

            if (isOnline)
            {
                onlineString = "[On]";
            }

            string oldFactionTag = PlayerUtils.GetFactionTagStringForPlayer(block.OwnerId);
            string oldName       = oldOwnerName + " " + onlineString + oldFactionTag;
            string causeName     = "[Unknown]";

            ChangingEntity cause          = OwnershipLoggerPlugin.Instance.DamageCache.Get(block.EntityId);
            string         additionalInfo = null;

            if (cause != null)
            {
                additionalInfo = cause.AdditionalInfo;

                if (!cause.IsPlanet)
                {
                    long causeId;

                    if (cause.Controller != 0L)
                    {
                        causeId = cause.Controller;
                    }
                    else
                    {
                        causeId = cause.Owner;
                    }

                    /* Can be offline when weapons are the cause */
                    bool   isCauseOnline     = PlayerUtils.isOnline(causeId);
                    string causeOnlineString = "[Off]";
                    if (isCauseOnline)
                    {
                        causeOnlineString = "[On]";
                    }

                    string causePlayerName = PlayerUtils.GetPlayerNameById(causeId);
                    string causeFactionTag = PlayerUtils.GetFactionTagStringForPlayer(causeId);

                    causeName = (causePlayerName + " " + causeOnlineString + causeFactionTag).PadRight(25) + " with " + cause.ChangingCause;
                }
                else
                {
                    causeName = "Planet".PadRight(25) + " with " + cause.ChangingCause;
                }
            }

            string blockpairName = block.BlockDefinition.BlockPairName;

            blockpairName = ChangeName(additionalInfo, blockpairName);

            string location = GetLocationWhenNeeded(block);

            Log.Info(causeName.PadRight(45) + " destroyed block        " + blockpairName.PadRight(20) + " from " + oldName.PadRight(25) + "    " + "".PadRight(20) + " of grid: " + gridName + location);
        }
        public static bool PatchOnChangeOwnersRequest(List <MyCubeGrid.MySingleOwnershipRequest> requests, long requestingPlayer)
        {
            StringBuilder sb = new StringBuilder();

            /* No Requests nothing to do */
            if (requests == null)
            {
                return(true);
            }

            string resquesterName    = PlayerUtils.GetPlayerNameById(requestingPlayer);
            string requestFactionTag = PlayerUtils.GetFactionTagStringForPlayer(requestingPlayer);

            /* Dont want to print the grid information over and over again. */
            bool first = true;

            foreach (MyCubeGrid.MySingleOwnershipRequest request in requests)
            {
                MyCubeBlock block = MyEntities.GetEntityById(request.BlockId, false) as MyCubeBlock;

                /* No block found, or different ownership? */
                if (block == null)
                {
                    continue;
                }

                /* No Grid? unlikely but ignore */
                MyCubeGrid grid = block.CubeGrid;
                if (grid == null)
                {
                    continue;
                }

                string gridName = grid.DisplayName;

                string oldOwnerName = PlayerUtils.GetPlayerNameById(block.OwnerId);
                string newOwnerName = PlayerUtils.GetPlayerNameById(request.Owner);

                if (oldOwnerName == newOwnerName)
                {
                    return(true);
                }

                bool   isOnline     = PlayerUtils.isOnline(block.OwnerId);
                string onlineString = "[Off]";
                if (isOnline)
                {
                    onlineString = "[On]";
                }

                string oldFactionTag = PlayerUtils.GetFactionTagStringForPlayer(block.OwnerId);
                string newFactionTag = PlayerUtils.GetFactionTagStringForPlayer(request.Owner);

                string oldName = oldOwnerName + " " + onlineString + oldFactionTag;
                string newName = newOwnerName + " " + newFactionTag;

                string location = GetLocationWhenNeeded(block);

                /* Opening statement */
                if (first)
                {
                    sb.AppendLine("Player " + resquesterName + " " + requestFactionTag + " requested the following ownership changes on grid: '" + gridName + "'");

                    first = false;
                }

                sb.AppendLine("   block " + block.BlockDefinition.BlockPairName.PadRight(20) + " from " + oldName.PadRight(25) + " to " + newName.PadRight(20) + location);
            }

            Log.Info(sb);

            return(true);
        }
        public static bool PatchChangeOwnerRequest(
            MyCubeGrid grid,
            MyCubeBlock block,
            long playerId,
            MyOwnershipShareModeEnum shareMode)
        {
            string gridName = grid.DisplayName;

            string oldOwnerName = PlayerUtils.GetPlayerNameById(block.OwnerId);
            string newOwnerName = PlayerUtils.GetPlayerNameById(playerId);

            /* Only shared mode was changed */
            if (oldOwnerName == newOwnerName)
            {
                return(true);
            }

            bool   isOnline     = PlayerUtils.isOnline(block.OwnerId);
            string onlineString = "[Off]";

            if (isOnline)
            {
                onlineString = "[On]";
            }

            string oldFactionTag = PlayerUtils.GetFactionTagStringForPlayer(block.OwnerId);
            string newFactionTag = PlayerUtils.GetFactionTagStringForPlayer(playerId);

            string oldName = oldOwnerName + " " + onlineString + oldFactionTag;
            string newName = newOwnerName + " " + newFactionTag;

            string causeName = "[Unknown]";

            ChangingEntity cause = OwnershipLoggerPlugin.Instance.DamageCache.Get(block.EntityId);

            string additionalInfo = null;

            if (playerId == 0L && cause != null)
            {
                additionalInfo = cause.AdditionalInfo;

                if (!cause.IsPlanet)
                {
                    long causeId;

                    if (cause.Controller != 0L)
                    {
                        causeId = cause.Controller;
                    }
                    else
                    {
                        causeId = cause.Owner;
                    }

                    /* Can be offline when weapons are the cause */
                    bool   isCauseOnline     = PlayerUtils.isOnline(causeId);
                    string causeOnlineString = "[Off]";
                    if (isCauseOnline)
                    {
                        causeOnlineString = "[On]";
                    }

                    string causePlayerName = PlayerUtils.GetPlayerNameById(causeId);
                    string causeFactionTag = PlayerUtils.GetFactionTagStringForPlayer(causeId);

                    causeName = (causePlayerName + " " + causeOnlineString + causeFactionTag).PadRight(25) + " with " + cause.ChangingCause;
                }
                else
                {
                    causeName = "Planet".PadRight(25) + " with " + cause.ChangingCause;
                }
            }
            else if (playerId != 0L)
            {
                /* Can be offline when weapons are the cause */
                bool   isCauseOnline     = PlayerUtils.isOnline(playerId);
                string causeOnlineString = "[Off]";
                if (isCauseOnline)
                {
                    causeOnlineString = "[On]";
                }

                /* Must be Online then */
                causeName = newOwnerName + " " + causeOnlineString + newFactionTag;
            }

            string blockpairName = block.BlockDefinition.BlockPairName;

            blockpairName = ChangeName(additionalInfo, blockpairName);

            string location = GetLocationWhenNeeded(block);

            Log.Info(causeName.PadRight(45) + " changed owner on block " + blockpairName.PadRight(20) + " from " + oldName.PadRight(25) + " to " + newName.PadRight(20) + " on grid: " + gridName + location);

            return(true);
        }
예제 #10
0
        private static void DoLogging(EntityIdCooldownKey cooldownKey, MyCubeGrid grid)
        {
            RotorgunDetectorPlugin plugin = RotorgunDetectorPlugin.Instance;

            var cooldowns = plugin.LoggingCooldowns;

            if (!cooldowns.CheckCooldown(cooldownKey, "logging", out _))
            {
                return;
            }

            cooldowns.StartCooldown(cooldownKey, "logging", plugin.LoggingCooldown);

            grid = grid.GetBiggestGridInGroup();

            var gridOwnerList = grid.BigOwners;
            var ownerCnt      = gridOwnerList.Count;
            var gridOwner     = 0L;

            if (ownerCnt > 0 && gridOwnerList[0] != 0)
            {
                gridOwner = gridOwnerList[0];
            }
            else if (ownerCnt > 1)
            {
                gridOwner = gridOwnerList[1];
            }

            FILE_LOGGER.Warn("Possible Rotorgun found on grid " + grid.DisplayName + " owned by " + PlayerUtils.GetPlayerNameById(gridOwner));
        }