// admin nobeacon scan
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (words.Count() > 1)
            {
                return(false);
            }

            if (!words.Any())
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            long entityId = 0;

            if (!long.TryParse(words[0], out entityId))
            {
                Communication.SendPrivateInformation(userId, string.Format("The value '{0}' is not a valid entityId", words[0]));
                return(true);
            }

            CubeGridEntity entity = (CubeGridEntity)GameEntityManager.GetEntity(entityId);

            Communication.SendPrivateInformation(userId, string.Format("Entity {0} DisplayName: {1} FullName: {2}", entityId, entity.DisplayName, entity.Name));

            return(true);
        }
示例#2
0
        // /admin ownership change name gridId
        public override bool HandleCommand(ulong userId, string[] words)
        {
            string name     = words[0].ToLower();
            long   playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(PlayerMap.Instance.GetSteamIdFromPlayerName(name, true)).First();
            string gridId   = words[1].ToLower();

            long gridEntityId = 0;

            if (!long.TryParse(gridId, out gridEntityId))
            {
                Communication.SendPrivateInformation(userId, string.Format("Invalid EntityID entered: {0}", gridId));
                return(true);
            }

            CubeGridEntity grid = (CubeGridEntity)GameEntityManager.GetEntity(gridEntityId);

            for (int r = 0; r < grid.CubeBlocks.Count; r++)
            {
                CubeBlockEntity block = (CubeBlockEntity)grid.CubeBlocks[r];

                if (block is TerminalBlockEntity)
                {
                    if (block.Owner != playerId && block.Owner != 0)
                    {
                        Communication.SendPrivateInformation(userId, string.Format("Changing ownership of {0} - {1}", block.Name, playerId));
                        block.Owner = playerId;
                    }
                }
            }

            return(true);
        }
        public CharacterEntity GetPlayer(ulong steamID)
        {
            long            gameEntity   = PlayerMap.Instance.GetPlayerEntityId(steamID);
            CharacterEntity characEntity = (CharacterEntity)GameEntityManager.GetEntity(gameEntity);

            return(characEntity);
        }
        // admin nobeacon scan
        public override bool HandleCommand(ulong userId, string[] words)
        {
            try
            {
                HashSet <IMyEntity> entities          = new HashSet <IMyEntity>();
                HashSet <IMyEntity> entitiesToConfirm = new HashSet <IMyEntity>();
                HashSet <IMyEntity> entitiesConnected = new HashSet <IMyEntity>();
                HashSet <IMyEntity> entitiesFound     = new HashSet <IMyEntity>();
                Wrapper.GameAction(() =>
                {
                    MyAPIGateway.Entities.GetEntities(entities, x => x is IMyCubeGrid);
                });

                foreach (IMyEntity entity in entities)
                {
                    if (!(entity is IMyCubeGrid))
                    {
                        continue;
                    }

                    IMyCubeGrid grid = (IMyCubeGrid)entity;
                    MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(grid);
                    if (gridBuilder == null)
                    {
                        continue;
                    }

                    bool found = false;
                    foreach (MyObjectBuilder_CubeBlock block in gridBuilder.CubeBlocks)
                    {
                        if (block.TypeId == typeof(MyObjectBuilder_Beacon))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        entitiesToConfirm.Add(grid);
                    }
                }

                CubeGrids.GetGridsUnconnected(entitiesFound, entitiesToConfirm);

                foreach (IMyEntity entity in entitiesFound)
                {
                    CubeGridEntity gridEntity = (CubeGridEntity)GameEntityManager.GetEntity(entity.EntityId);
                    Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) at {2} with no beacon.", gridEntity.Name, gridEntity.EntityId, General.Vector3DToString(entity.GetPosition())));
                }

                Communication.SendPrivateInformation(userId, string.Format("Found {0} grids with no beacons", entitiesFound.Count));
            }
            catch (Exception ex)
            {
                Logging.WriteLineAndConsole(string.Format("Scan error: {0}", ex.ToString()));
            }

            return(true);
        }
示例#5
0
        protected static void ReceiveCurrentPowerPacket <T>(ref T packet, Object netManager) where T : struct
        {
            try
            {
                //object result = BaseObject.InvokeEntityMethod( packet, BatteryBlockNetManagerCurrentStoredPowerPacketGetIdMethod );
                //object result = BaseObject.GetEntityFieldValue(packet, BatteryBlockNetManagerCurrentStoredPowerPacketGetIdField);
                object result = null;
                if (result == null)
                {
                    return;
                }
                long       entityId      = (long)result;
                BaseObject matchedEntity = GameEntityManager.GetEntity(entityId);
                if (matchedEntity == null)
                {
                    return;
                }
                if (!(matchedEntity is BatteryBlockEntity))
                {
                    return;
                }
                BatteryBlockEntity battery = (BatteryBlockEntity)matchedEntity;

                result = BaseObject.GetEntityFieldValue(packet, BatteryBlockNetManagerCurrentStoredPowerPacketValueField);
                if (result == null)
                {
                    return;
                }
                float packetPowerLevel = (float)result;
                if (packetPowerLevel == 1.0f)
                {
                    return;
                }

                BaseObject.SetEntityFieldValue(packet, BatteryBlockNetManagerCurrentStoredPowerPacketValueField, battery.CurrentStoredPower);

                Type       refPacketType           = packet.GetType( ).MakeByRefType( );
                MethodInfo basePacketHandlerMethod = BaseObject.GetStaticMethod(InternalType, BatteryBlockNetManagerCurrentPowerPacketReceiver, new Type[] { refPacketType, netManager.GetType( ) });
                basePacketHandlerMethod.Invoke(null, new object[] { packet, netManager });
            }
            catch (Exception ex)
            {
                ApplicationLog.BaseLog.Error(ex);
            }
        }
        private void ProtectedEntity(IMyEntity entity, ProtectedItem item)
        {
            //Logging.WriteLineAndConsole(string.Format("Protecting: {0}", entity.EntityId));
            //CubeGridEntity gridEntity = new CubeGridEntity((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder(), entity);
            CubeGridEntity           gridEntity = (CubeGridEntity)GameEntityManager.GetEntity(entity.EntityId);
            MyObjectBuilder_CubeGrid grid       = (MyObjectBuilder_CubeGrid)entity.GetObjectBuilder();

            int count = 0;

            while (gridEntity.IsLoading)
            {
                if (count >= 20)
                {
                    return;
                }

                Thread.Sleep(100);
                count++;
            }

            bool found = false;

            /*
             * foreach(CubeBlockEntity block in gridEntity.CubeBlocks)
             * {
             *      if (block.IntegrityPercent != item.IntegrityIncrease || block.BuildPercent != item.IntegrityIncrease || block.BoneDamage > 0f)
             *      {
             *              found = true;
             *              block.FixBones(0, 100);
             *              block.IntegrityPercent = item.IntegrityIncrease;
             *              block.BuildPercent = item.IntegrityIncrease;
             *      }
             * }
             */
            if (found)
            {
                Logging.WriteLineAndConsole(string.Format("Repaired Grid: {0}", gridEntity.EntityId));
            }
        }
        // admin deletearea x y z radius
        public override bool HandleCommand(ulong userId, string command)
        {
            string[] words = command.Split(' ');
            if (words.Length > 3)
            {
                return(false);
            }

            if (!words.Any())
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            int days = -1;

            if (!int.TryParse(words[0], out days) || days < 0)
            {
                Communication.SendPrivateInformation(userId, string.Format("Invalid argument.  Days argument must be an integer that is 0 or greater."));
                return(true);
            }

            // Just assume that anything after the days is going to "ignorenologin"
            bool removeNoLoginInformation = true;
            bool removeOwnerless          = true;

            if (words.Count() > 1)
            {
                foreach (string word in words)
                {
                    if (word.ToLower() == "ignorenologin")
                    {
                        removeNoLoginInformation = false;
                    }
                    if (word.ToLower() == "ignoreownerless")
                    {
                        removeOwnerless = false;
                    }
                }
            }

            Communication.SendPrivateInformation(userId, string.Format("Scanning for grids with owners that haven't logged in {0} days.  (Must Have Login Info={1})", days, removeNoLoginInformation));

            HashSet <IMyEntity> entities = new HashSet <IMyEntity>();

            Wrapper.GameAction(() =>
            {
                MyAPIGateway.Entities.GetEntities(entities, x => x is IMyCubeGrid);
            });

            HashSet <IMyEntity> entitiesFound = new HashSet <IMyEntity>();

            foreach (IMyEntity entity in entities)
            {
                if (!(entity is IMyCubeGrid))
                {
                    continue;
                }

                IMyCubeGrid              grid        = (IMyCubeGrid)entity;
                CubeGridEntity           gridEntity  = (CubeGridEntity)GameEntityManager.GetEntity(grid.EntityId);
                MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(grid);
                if (gridBuilder == null)
                {
                    continue;
                }

                // This entity is protected by whitelist
                if (PluginSettings.Instance.LoginEntityWhitelist.Length > 0 && PluginSettings.Instance.LoginEntityWhitelist.Contains(grid.EntityId.ToString()))
                {
                    continue;
                }

                if (CubeGrids.GetAllOwners(gridBuilder).Count < 1 && removeOwnerless)
                {
                    Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) not owned by anyone.", gridEntity.Name, entity.EntityId));
                    entitiesFound.Add(entity);
                    continue;
                }

                foreach (long player in CubeGrids.GetBigOwners(gridBuilder))
                {
                    // This playerId is protected by whitelist
                    if (PluginSettings.Instance.LoginPlayerIdWhitelist.Length > 0 && PluginSettings.Instance.LoginPlayerIdWhitelist.Contains(player.ToString()))
                    {
                        continue;
                    }

                    MyObjectBuilder_Checkpoint.PlayerItem checkItem = PlayerMap.Instance.GetPlayerItemFromPlayerId(player);
                    if (checkItem.IsDead || checkItem.Name == "")
                    {
                        Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) owned by dead player - ID: {2}", gridEntity.Name, entity.EntityId, player));
                        entitiesFound.Add(entity);
                        continue;
                    }

                    PlayerItem item = Players.Instance.GetPlayerById(player);
                    if (item == null)
                    {
                        if (removeNoLoginInformation)
                        {
                            Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) owned by a player with no login info: {2}", gridEntity.Name, entity.EntityId, checkItem.Name));
                            entitiesFound.Add(entity);
                        }
                    }
                    else if (item.LastLogin < DateTime.Now.AddDays(days * -1))
                    {
                        Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) owned by inactive player: {2}", gridEntity.Name, entity.EntityId, PlayerMap.Instance.GetPlayerItemFromPlayerId(player).Name));
                        entitiesFound.Add(entity);
                    }
                }
            }

            Communication.SendPrivateInformation(userId, string.Format("Found {0} grids owned by inactive users", entitiesFound.Count));

            foreach (IMyEntity entity in entitiesFound)
            {
                if (!(entity is IMyCubeGrid))
                {
                    continue;
                }

                CubeGridEntity gridEntity = new CubeGridEntity((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder(), entity);
                gridEntity.Dispose();
            }

            Communication.SendPrivateInformation(userId, string.Format("Removed {0} grids owned by inactive users", entitiesFound.Count));
            return(true);
        }
        // admin deletearea x y z radius
        public override bool HandleCommand(ulong userId, string[] words)
        {
            HashSet <IMyEntity> entities          = new HashSet <IMyEntity>();
            HashSet <IMyEntity> entitiesToConfirm = new HashSet <IMyEntity>();
            HashSet <IMyEntity> entitiesConnected = new HashSet <IMyEntity>();
            HashSet <IMyEntity> entitiesFound     = new HashSet <IMyEntity>();

            Wrapper.GameAction(() =>
            {
                MyAPIGateway.Entities.GetEntities(entities, x => x is IMyCubeGrid);
            });

            foreach (IMyEntity entity in entities)
            {
                if (!(entity is IMyCubeGrid))
                {
                    continue;
                }

                IMyCubeGrid grid = (IMyCubeGrid)entity;
                MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(grid);
                if (gridBuilder == null)
                {
                    continue;
                }

                bool found = false;
                foreach (MyObjectBuilder_CubeBlock block in gridBuilder.CubeBlocks)
                {
                    if (block.TypeId == typeof(MyObjectBuilder_Beacon))
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    entitiesToConfirm.Add(grid);
                }
            }

            CubeGrids.GetGridsUnconnected(entitiesFound, entitiesToConfirm);

            foreach (IMyEntity entity in entitiesFound)
            {
                CubeGridEntity gridEntity = (CubeGridEntity)GameEntityManager.GetEntity(entity.EntityId);
                if (gridEntity == null)
                {
                    Log.Info("A found entity gridEntity was null!");
                    continue;
                }
                Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) at {2} with no beacon.", gridEntity.Name, entity.EntityId, General.Vector3DToString(entity.GetPosition())));
            }

            for (int r = entitiesFound.Count - 1; r >= 0; r--)
            {
                //MyAPIGateway.Entities.RemoveEntity(entity);
                IMyEntity      entity     = entitiesFound.ElementAt(r);
                CubeGridEntity gridEntity = new CubeGridEntity((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder(), entity);
                gridEntity.Dispose();
            }

            Communication.SendPrivateInformation(userId, string.Format("Removed {0} grids with no beacons", entitiesFound.Count));

            return(true);
        }