// admin nobeacon scan public override bool HandleCommand(ulong userId, string[] words) { HashSet <IMyEntity> grids = CubeGrids.ScanGrids(userId, words); bool confirm = true; /* * if (words.FirstOrDefault(x => x.ToLower() == "confirm") != null) * { * confirm = true; * } */ int count = 0; foreach (IMyEntity entity in grids) { if (!(entity is IMyCubeGrid)) { continue; } IMyCubeGrid grid = (IMyCubeGrid)entity; MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(grid); if (confirm) { BaseEntityNetworkManager.BroadcastRemoveEntity(entity, true); } long ownerId = 0; string ownerName = ""; if (CubeGrids.GetBigOwners(gridBuilder).Count > 0) { ownerId = CubeGrids.GetBigOwners(gridBuilder).First(); ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name; } if (confirm) { Logging.WriteLineAndConsole("Cleanup", string.Format("Cleanup Removed Grid - Id: {0} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName)); } count++; } Communication.SendPrivateInformation(userId, string.Format("Operation deletes {0} grids", count)); return(true); }
static public void RevealAll() { HashSet <IMyEntity> entities = new HashSet <IMyEntity>(); Wrapper.GameAction(() => { MyAPIGateway.Entities.GetEntities(entities); }); List <MyObjectBuilder_EntityBase> addList = new List <MyObjectBuilder_EntityBase>(); int count = 0; Wrapper.GameAction(() => { foreach (IMyEntity entity in entities) { if (entity.InScene) { continue; } if (!(entity is IMyCubeGrid)) { continue; } MyObjectBuilder_CubeGrid builder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity); if (builder == null) { continue; } count++; IMyCubeGrid grid = (IMyCubeGrid)entity; long ownerId = 0; string ownerName = ""; if (CubeGrids.GetBigOwners(builder).Count > 0) { ownerId = CubeGrids.GetBigOwners(builder).First(); ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name; } //grid.PersistentFlags = (MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.CastShadows); //grid.InScene = true; //grid.CastShadows = true; builder.PersistentFlags = (MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.CastShadows); MyAPIGateway.Entities.RemapObjectBuilder(builder); Logging.WriteLineAndConsole("Conceal", string.Format("Force Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, builder.EntityId)); IMyEntity newEntity = MyAPIGateway.Entities.CreateFromObjectBuilder(builder); if (newEntity == null) { Logging.WriteLineAndConsole("Conceal", string.Format("Issue - CreateFromObjectBuilder failed: {0}", newEntity.EntityId)); continue; } BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false); MyAPIGateway.Entities.AddEntity(newEntity, true); addList.Add(newEntity.GetObjectBuilder()); MyAPIGateway.Multiplayer.SendEntitiesCreated(addList); addList.Clear(); } }); Logging.WriteLineAndConsole(string.Format("Revealed {0} grids", count)); }
private static void RevealEntity(KeyValuePair <IMyEntity, string> item) { IMyEntity entity = item.Key; string reason = item.Value; //Wrapper.GameAction(() => //{ MyObjectBuilder_CubeGrid builder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity); if (builder == null) { return; } IMyCubeGrid grid = (IMyCubeGrid)entity; long ownerId = 0; string ownerName = ""; if (CubeGrids.GetBigOwners(builder).Count > 0) { ownerId = CubeGrids.GetBigOwners(builder).First(); ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name; } /* * entity.InScene = true; * entity.CastShadows = true; * entity.Visible = true; */ builder.PersistentFlags = (MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.CastShadows); MyAPIGateway.Entities.RemapObjectBuilder(builder); //builder.EntityId = 0; if (RemovedGrids.Contains(entity.EntityId)) { Logging.WriteLineAndConsole("Conceal", string.Format("Revealing - Id: {0} DUPE FOUND Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, reason)); BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false); } else { if (!PluginSettings.Instance.DynamicConcealServerOnly) { IMyEntity newEntity = MyAPIGateway.Entities.CreateFromObjectBuilder(builder); Logging.WriteLineAndConsole("Conceal", string.Format("Start Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3} Reason: {5}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, newEntity.EntityId, reason)); if (newEntity == null) { Logging.WriteLineAndConsole("Conceal", string.Format("Issue - CreateFromObjectBuilder failed: {0}", newEntity.EntityId)); return; } RemovedGrids.Add(entity.EntityId); BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false); MyAPIGateway.Entities.AddEntity(newEntity, true); /*CC * if (PluginSettings.Instance.DynamicClientConcealEnabled) * { * ClientEntityManagement.AddEntityState(newEntity.EntityId); * } */ builder.EntityId = newEntity.EntityId; List <MyObjectBuilder_EntityBase> addList = new List <MyObjectBuilder_EntityBase>(); addList.Add(newEntity.GetObjectBuilder()); MyAPIGateway.Multiplayer.SendEntitiesCreated(addList); Logging.WriteLineAndConsole("Conceal", string.Format("End Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3} Reason: {5}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, newEntity.EntityId, reason)); } else { Logging.WriteLineAndConsole("Conceal", string.Format("Start Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, reason)); entity.InScene = true; // Send to users, client will remove if doesn't need - this solves login problem /*CC * if (PluginSettings.Instance.DynamicClientConcealEnabled) * { * ClientEntityManagement.AddEntityState(entity.EntityId); * List<MyObjectBuilder_EntityBase> addList = new List<MyObjectBuilder_EntityBase>(); * addList.Add(entity.GetObjectBuilder()); * MyAPIGateway.Multiplayer.SendEntitiesCreated(addList); * } */ Logging.WriteLineAndConsole("Conceal", string.Format("End Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, reason)); } } //}); }
// 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); }
static public void RevealAll( ) { HashSet <IMyEntity> entities = new HashSet <IMyEntity>( ); Wrapper.GameAction(() => { MyAPIGateway.Entities.GetEntities(entities); }); List <MyObjectBuilder_EntityBase> addList = new List <MyObjectBuilder_EntityBase>( ); int count = 0; Wrapper.GameAction(() => { foreach (IMyEntity entity in entities) { if (entity.InScene) { continue; } if (!(entity is IMyCubeGrid)) { continue; } MyObjectBuilder_CubeGrid builder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity); if (builder == null) { continue; } count++; IMyCubeGrid grid = (IMyCubeGrid)entity; long ownerId = 0; string ownerName = ""; if (CubeGrids.GetBigOwners(builder).Count > 0) { ownerId = CubeGrids.GetBigOwners(builder).First( ); ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name; } //grid.PersistentFlags = (MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.CastShadows); //grid.InScene = true; //grid.CastShadows = true; builder.PersistentFlags = (MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.CastShadows); MyAPIGateway.Entities.RemapObjectBuilder(builder); if (PluginSettings.Instance.DynamicShowMessages) { Essentials.Log.Info("Force Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, builder.EntityId); } IMyEntity newEntity = MyAPIGateway.Entities.CreateFromObjectBuilder(builder); if (newEntity == null) { Essentials.Log.Warn("CreateFromObjectBuilder failed: {0}", builder.EntityId); continue; } //these methods no longer exist. //KEEEEEEEEN! //BaseEntityNetworkManager.BroadcastRemoveEntity( entity, false ); /* * MyAPIGateway.Entities.AddEntity( newEntity ); * addList.Add( newEntity.GetObjectBuilder( ) ); * MyAPIGateway.Multiplayer.SendEntitiesCreated( addList ); * addList.Clear( ); */ MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(newEntity.GetObjectBuilder()); } }); if (PluginSettings.Instance.DynamicShowMessages) { Essentials.Log.Info("Revealed {0} grids", count); } }