From fc9b5d3adda11b4257c393fac012d6b5e47b6ecd Mon Sep 17 00:00:00 2001 From: MasterWise Date: Mon, 6 Oct 2014 14:55:11 -0300 Subject: [PATCH] New ChatCommands /off turrets - turrets off all of the server to improve the performance of the UPS /delete all noname [name] - deletes all objects that do not have a block with a given name. helps remove garbage from server requiring all entities not abandoned maintain at least one block with a specific name that can be changed eventually. --- SEModAPIExtensions/API/ChatManager.cs | 104 ++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/SEModAPIExtensions/API/ChatManager.cs b/SEModAPIExtensions/API/ChatManager.cs index 72f4acba..87bd1014 100644 --- a/SEModAPIExtensions/API/ChatManager.cs +++ b/SEModAPIExtensions/API/ChatManager.cs @@ -688,6 +688,105 @@ protected void Command_Delete(ChatEvent chatEvent) SendPrivateChatMessage(remoteUserId, entitiesToDispose.Count.ToString() + " cube grids have been removed"); } + + + //All cube grids that have no beacon or only a beacon with no name + else if ((commandParts[2].ToLower().Equals("noname")) && (commandParts[3]!="")) + { + List entities = SectorObjectManager.Instance.GetTypedInternalData(); + List entitiesToDispose = new List(); + SortedList entitiesToDisposeParent = new SortedList(); + List entitiesToNotDispose = new List(); + foreach (CubeGridEntity entity in entities) + { + string deletedName = entity.Name; + while (entity.CubeBlocks.Count == 0) + { + Thread.Sleep(20); + } + List blocks = entity.CubeBlocks; + if (blocks.Count > 0) + { + bool foundName = false; + foreach (CubeBlockEntity cubeBlock in blocks) + { + if (String.Equals(cubeBlock.Name, commandParts[3])) + { + foundName = true; + break; + } + } + if (!foundName) + { + entitiesToDispose.Add(entity); + } + else + { + foreach (CubeBlockEntity cubeBlock in blocks) + { + if (cubeBlock is MergeBlockEntity) + { + MergeBlockEntity block = (MergeBlockEntity)cubeBlock; + if (block.IsAttached) + { + if (block.AttachedCubeGrid.EntityId > 0) + { + entitiesToNotDispose.Add(block.AttachedCubeGrid.EntityId); + } + } + } + + if (cubeBlock is PistonEntity) + { + PistonEntity block = (PistonEntity)cubeBlock; + if (block.TopBlockId > 0) + { + entitiesToNotDispose.Add(block.TopBlockId); + } + } + + if (cubeBlock is RotorEntity) + { + RotorEntity block = (RotorEntity)cubeBlock; + CubeBlockEntity topBlock = block.TopBlock; + if (block.TopBlockId > 0) + { + entitiesToNotDispose.Add(block.TopBlockId); + } + } + + + + } + } + } + } + + int countDispose=0; + foreach (CubeGridEntity entity in entitiesToDispose) + { + bool isLinkedShip = false; + List blocks = entity.CubeBlocks; + foreach (CubeBlockEntity cubeBlock in blocks) + { + if (entitiesToNotDispose.Contains(cubeBlock.EntityId)) + { + isLinkedShip = true; + break; + } + } + if (isLinkedShip) + continue; + + countDispose++; + SendPrivateChatMessage(remoteUserId, "Removed: " + entity.Name); + entity.Dispose(); + } + + SendPrivateChatMessage(remoteUserId, countDispose + " NoName cube grids have been removed"); + } + + //All cube grids that have no power else if (commandParts[2].ToLower().Equals("nopower")) { @@ -1412,6 +1511,11 @@ protected void Command_Off(ChatEvent chatEvent) functionalBlock.Enabled = false; poweredOffCount++; } + if (commandParts[1].ToLower().Equals("turrets") && cubeBlock is TurretBaseEntity) + { + functionalBlock.Enabled = false; + poweredOffCount++; + } if (commandParts[1].ToLower().Equals("beacon") && cubeBlock is BeaconEntity) { functionalBlock.Enabled = false;