// 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); }
public GridGroup(MyCubeGrid grid, GridLinkTypeEnum linkType = GridLinkTypeEnum.Logical) { _linkType = linkType; if (grid.InScene) { List <MyCubeGrid> tmpList = new List <MyCubeGrid>( ); //find the group containing this grid with the given link type Wrapper.GameAction(() => tmpList = MyCubeGridGroups.Static.GetGroups(linkType).GetGroupNodes(grid)); _grids.UnionWith(tmpList); } //manually create a group for out of scene grids because they have a null group (yay Dusan fixed the crash) else { //use the old method to filter out grids with pistons or rotors, for safety HashSet <IMyEntity> thisEntity = new HashSet <IMyEntity>(); HashSet <IMyEntity> returnSet = new HashSet <IMyEntity>(); thisEntity.Add((IMyEntity)grid); CubeGrids.GetGridsUnconnected(returnSet, thisEntity); if (returnSet.Count > 0) { _grids.Add(grid); } else { return; } } //populate our internal lists ComputeParent( ); ComputeCubeBlocks( ); ComputeFatBlocks( ); ComputeSmallOwners( ); ComputeBigOwners( ); }
public static bool ToggleMedbayGrids(ulong steamId) { if (_checkConceal || _checkReveal) { Communication.SendPrivateInformation(steamId, "Server busy"); return(false); } _checkConceal = true; _checkReveal = true; try { DateTime start = DateTime.Now; // Toggle off HashSet <IMyEntity> entities = new HashSet <IMyEntity>(); HashSet <IMyEntity> entitiesFound = new HashSet <IMyEntity>(); try { MyAPIGateway.Entities.GetEntities(entities); } catch { Logging.WriteLineAndConsole("CheckAndConcealEntities(): Error getting entity list, skipping check"); return(false); } CubeGrids.GetGridsUnconnected(entitiesFound, entities); HashSet <IMyEntity> entitiesToConceal = new HashSet <IMyEntity>(); foreach (IMyEntity entity in entitiesFound) { if (!(entity is IMyCubeGrid)) { continue; } if (entity.DisplayName.Contains("CommRelay")) { continue; } if (!entity.InScene) { continue; } if (((IMyCubeGrid)entity).GridSizeEnum != MyCubeSize.Small && !PluginSettings.Instance.ConcealIncludeLargeGrids) { continue; } IMyCubeGrid grid = (IMyCubeGrid)entity; long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(steamId); if (!grid.BigOwners.Contains(playerId) && !grid.SmallOwners.Contains(playerId)) { continue; } bool found = false; // Check to see if grid is close to dock / shipyard foreach (IMyCubeGrid checkGrid in ProcessDockingZone.ZoneCache) { try { if (Vector3D.Distance(checkGrid.GetPosition(), grid.GetPosition()) < 100d) { found = true; break; } } catch { continue; } } if (!found) { // Check for block type rules } if (!found) { entitiesToConceal.Add(entity); } } if (entitiesToConceal.Count > 0) { //if (PluginSettings.Instance.DynamicClientConcealEnabled) //{ //ClientEntityManagement.Refresh(steamId); //} Communication.SendClientMessage(steamId, string.Format("/conceal {0}", string.Join(",", entitiesToConceal.Select(x => x.EntityId.ToString() + ":" + ((MyObjectBuilder_CubeGrid)x.GetObjectBuilder()).CubeBlocks.Count.ToString() + ":" + x.DisplayName).ToArray()))); Thread.Sleep(1500); ConcealEntities(entitiesToConceal); //CheckAndRevealEntities(); } if ((DateTime.Now - start).TotalMilliseconds > 2000) { Logging.WriteLineAndConsole(string.Format("Completed Toggle: {0}ms", (DateTime.Now - start).TotalMilliseconds)); } } catch (Exception ex) { Logging.WriteLineAndConsole(string.Format("CheckAndConceal(): {0}", ex.ToString())); } finally { _checkConceal = false; _checkReveal = false; } return(true); }
public static void CheckAndConcealEntities() { if (_checkConceal) { return; } _checkConceal = true; try { DateTime start = DateTime.Now; double distCheck = 0d; double blockRules = 0d; double getGrids = 0d; double co = 0f; ProcessedGrids.Clear(); List <IMyPlayer> players = new List <IMyPlayer>(); HashSet <IMyEntity> entities = new HashSet <IMyEntity>(); HashSet <IMyEntity> entitiesFiltered = new HashSet <IMyEntity>(); HashSet <IMyEntity> entitiesFound = new HashSet <IMyEntity>(); try { MyAPIGateway.Players.GetPlayers(players); } catch (Exception ex) { Logging.WriteLineAndConsole(string.Format("Error getting players list. Check and Conceal failed: {0}", ex.ToString())); return; } try { MyAPIGateway.Entities.GetEntities(entities); } catch { Logging.WriteLineAndConsole("CheckAndConcealEntities(): Error getting entity list, skipping check"); return; } foreach (IMyEntity entity in entities) { if (!(entity is IMyCubeGrid)) { continue; } if (!entity.InScene) { continue; } entitiesFiltered.Add(entity); } DateTime getGridsStart = DateTime.Now; CubeGrids.GetGridsUnconnected(entitiesFound, entitiesFiltered); getGrids += (DateTime.Now - getGridsStart).TotalMilliseconds; HashSet <IMyEntity> entitiesToConceal = new HashSet <IMyEntity>(); foreach (IMyEntity entity in entitiesFound) { if (!(entity is IMyCubeGrid)) { continue; } if (entity.DisplayName.Contains("CommRelay")) { continue; } if (entity.Physics == null) // Projection { continue; } if (!entity.InScene) { continue; } if (((IMyCubeGrid)entity).GridSizeEnum != MyCubeSize.Small && !PluginSettings.Instance.ConcealIncludeLargeGrids) { continue; } IMyCubeGrid grid = (IMyCubeGrid)entity; bool found = false; DateTime distStart = DateTime.Now; foreach (IMyPlayer player in players) { double distance = 0f; if (Entity.GetDistanceBetweenGridAndPlayer(grid, player, out distance)) { if (distance < PluginSettings.Instance.DynamicConcealDistance) { found = true; } } } distCheck += (DateTime.Now - distStart).TotalMilliseconds; if (!found) { // Check to see if grid is close to dock / shipyard foreach (IMyCubeGrid checkGrid in ProcessDockingZone.ZoneCache) { try { if (Vector3D.Distance(checkGrid.GetPosition(), grid.GetPosition()) < 100d) { found = true; break; } } catch { continue; } } } if (!found) { // Check for block type rules DateTime blockStart = DateTime.Now; if (CheckConcealBlockRules(grid, players)) { found = true; } blockRules += (DateTime.Now - blockStart).TotalMilliseconds; } if (!found) { entitiesToConceal.Add(entity); } } DateTime coStart = DateTime.Now; if (entitiesToConceal.Count > 0) { ConcealEntities(entitiesToConceal); } co += (DateTime.Now - coStart).TotalMilliseconds; if ((DateTime.Now - start).TotalMilliseconds > 2000) { Logging.WriteLineAndConsole(string.Format("Completed Conceal Check: {0}ms (gg: {3}, dc: {2} ms, br: {1}ms, co: {4}ms)", (DateTime.Now - start).TotalMilliseconds, blockRules, distCheck, getGrids, co)); } } catch (Exception ex) { Logging.WriteLineAndConsole(string.Format("CheckAndConceal(): {0}", ex.ToString())); } finally { _checkConceal = false; } }
public override bool HandleCommand(ulong userId, string[] words) { bool showConcealed = true; if (words.Length > 0 && words[0].ToLower() == "revealed") { showConcealed = false; } if (showConcealed) { HashSet <IMyEntity> entities = new HashSet <IMyEntity>(); Wrapper.GameAction(() => { MyAPIGateway.Entities.GetEntities(entities); }); Communication.SendPrivateInformation(userId, "==== Concealed Entities ==="); int count = 0; foreach (IMyEntity entity in entities) { if (!(entity is IMyCubeGrid)) { continue; } if (entity.InScene) { continue; } IMyCubeGrid grid = (IMyCubeGrid)entity; long ownerId = 0; string ownerName = ""; if (grid.BigOwners.Count > 0) { ownerId = grid.BigOwners.First(); ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name; } if (ownerName == "") { ownerName = "No one"; } Communication.SendPrivateInformation(userId, string.Format("Id: {0} Display: {1} OwnerId: {2} OwnerName: {3} Position: {4}", entity.EntityId, entity.DisplayName, ownerId, ownerName, General.Vector3DToString(entity.GetPosition()))); count++; } Communication.SendPrivateInformation(userId, string.Format("Total concealed entities: {0}", count)); } else { HashSet <IMyEntity> entities = new HashSet <IMyEntity>(); Wrapper.GameAction(() => { MyAPIGateway.Entities.GetEntities(entities); }); Communication.SendPrivateInformation(userId, "==== Revealed Entities ==="); Communication.SendPrivateInformation(userId, "==== Unconnected Entities ==="); HashSet <IMyEntity> entitiesFound = new HashSet <IMyEntity>(); CubeGrids.GetGridsUnconnected(entitiesFound, entities); int count = 0; List <IMySlimBlock> slimBlocks = new List <IMySlimBlock>(); foreach (IMyEntity entity in entitiesFound) { if (!(entity is IMyCubeGrid)) { continue; } if (!entity.InScene) { continue; } IMyCubeGrid grid = (IMyCubeGrid)entity; long ownerId = 0; string ownerName = ""; if (grid.BigOwners.Count > 0) { ownerId = grid.BigOwners.First(); ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name; } if (ownerName == "") { ownerName = "No one"; } grid.GetBlocks(slimBlocks, null); Communication.SendPrivateInformation(userId, string.Format("Id: {0} Display: {1} OwnerId: {2} OwnerName: {3} Position: {4} BlockCount: {5}", entity.EntityId, entity.DisplayName, ownerId, ownerName, General.Vector3DToString(entity.GetPosition()), slimBlocks.Count)); slimBlocks.Clear(); count++; } Communication.SendPrivateInformation(userId, string.Format("Total unconnected revealed entities: {0}", count)); Communication.SendPrivateInformation(userId, "==== Connected Entities ==="); HashSet <IMyEntity> connectedFound = new HashSet <IMyEntity>(); CubeGrids.GetConnectedGrids(connectedFound); Console.WriteLine("Here: {0} : {1} {2}", connectedFound.Intersect(entitiesFound).Count(), entitiesFound.Count, connectedFound.Count); count = 0; slimBlocks.Clear(); foreach (IMyEntity entity in connectedFound) { if (!(entity is IMyCubeGrid)) { continue; } if (entitiesFound.Contains(entity)) { continue; } if (!entity.InScene) { continue; } if (CubeGrids.GetRecursiveGridList((IMyCubeGrid)entity).Count < 2) { continue; } IMyCubeGrid grid = (IMyCubeGrid)entity; long ownerId = 0; string ownerName = ""; if (grid.BigOwners.Count > 0) { ownerId = grid.BigOwners.First(); ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name; } if (ownerName == "") { ownerName = "No one"; } grid.GetBlocks(slimBlocks, null); Communication.SendPrivateInformation(userId, string.Format("Id: {0} Display: {1} OwnerId: {2} OwnerName: {3} Position: {4} BlockCount: {5} Connections: {6}", entity.EntityId, entity.DisplayName, ownerId, ownerName, General.Vector3DToString(entity.GetPosition()), slimBlocks.Count, CubeGrids.GetRecursiveGridList(grid).Count)); //Communication.SendPrivateInformation(userId, string.Format("Id: {0} Display: {1} OwnerId: {2} OwnerName: {3} Position: {4} BlockCount: {5} Connections: {6}", entity.EntityId, entity.DisplayName, ownerId, ownerName, General.Vector3DToString(entity.GetPosition()), slimBlocks.Count)); slimBlocks.Clear(); count++; } Communication.SendPrivateInformation(userId, string.Format("Total connected revealed entities: {0}", 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); }
public static bool ToggleMedbayGrids(ulong steamId) { if (_checkConceal || _checkReveal) { Communication.SendPrivateInformation(steamId, "Server busy"); return(false); } _checkConceal = true; _checkReveal = true; try { DateTime start = DateTime.Now; // Toggle off HashSet <IMyEntity> entities = new HashSet <IMyEntity>( ); HashSet <IMyEntity> entitiesFound = new HashSet <IMyEntity>( ); try { MyAPIGateway.Entities.GetEntities(entities); } catch { Essentials.Log.Info("Error getting entity list, skipping check"); return(false); } CubeGrids.GetGridsUnconnected(entitiesFound, entities); HashSet <IMyEntity> entitiesToConceal = new HashSet <IMyEntity>( ); FilterEntitiesForMedbayCheck(steamId, entitiesFound, entitiesToConceal); if (entitiesToConceal.Count > 0) { //if (PluginSettings.Instance.DynamicClientConcealEnabled) //{ //ClientEntityManagement.Refresh(steamId); //} Communication.SendClientMessage(steamId, string.Format("/conceal {0}", string.Join(",", entitiesToConceal.Select(x => x.EntityId.ToString( ) + ":" + ((MyObjectBuilder_CubeGrid)x.GetObjectBuilder( )).CubeBlocks.Count.ToString( ) + ":" + x.DisplayName).ToArray( )))); Thread.Sleep(1500); ConcealEntities(entitiesToConceal); //CheckAndRevealEntities(); } if ((DateTime.Now - start).TotalMilliseconds > 2000 && PluginSettings.Instance.DynamicShowMessages) { Essentials.Log.Info("Completed Toggle: {0}ms", (DateTime.Now - start).TotalMilliseconds); } } catch (Exception ex) { Essentials.Log.Error(ex); } finally { _checkConceal = false; _checkReveal = false; } return(true); }
// admin nobeacon scan public override bool HandleCommand(ulong userId, string[] words) { if (words.Count() != 2) { Communication.SendPrivateInformation(userId, GetHelp()); return(true); } string blockType = words[0].ToLower(); int blockCount = 0; if (!int.TryParse(words[1], out blockCount)) { Communication.SendPrivateInformation(userId, string.Format("Invalid block count: {0}", words[1])); return(true); } blockCount = Math.Max(blockCount, 1); Communication.SendPrivateInformation(userId, string.Format("Looking for grids that contain more than {0} of type {1}", blockCount, blockType)); HashSet <IMyEntity> entities = new HashSet <IMyEntity>(); Wrapper.GameAction(() => { MyAPIGateway.Entities.GetEntities(entities, x => x is IMyCubeGrid); }); HashSet <IMyEntity> entitiesToConfirm = new HashSet <IMyEntity>(); HashSet <IMyEntity> entitiesUnconnected = new HashSet <IMyEntity>(); HashSet <IMyEntity> entitiesFound = new HashSet <IMyEntity>(); foreach (IMyEntity entity in entities) { if (!(entity is IMyCubeGrid)) { continue; } IMyCubeGrid grid = (IMyCubeGrid)entity; MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(grid); if (gridBuilder == null) { continue; } if (PluginSettings.Instance.LoginEntityWhitelist.Contains(entity.EntityId.ToString())) { continue; } entitiesToConfirm.Add(entity); } CubeGrids.GetGridsUnconnected(entitiesUnconnected, entitiesToConfirm); foreach (IMyEntity entity in entitiesUnconnected) { IMyCubeGrid grid = (IMyCubeGrid)entity; MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity); if (gridBuilder == null) { continue; } int count = 0; foreach (MyObjectBuilder_CubeBlock block in gridBuilder.CubeBlocks) { if (block.GetId().SubtypeName.ToLower().Contains(blockType)) { count++; } } if (count >= blockCount) { Communication.SendPrivateInformation(userId, string.Format("Found grid '{0}' ({1}) owned by '{5}' which has more than {3} blocks of type {4}. BlockCount={2}", entity.DisplayName, entity.EntityId, ((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder()).CubeBlocks.Count, blockCount, blockType, grid.BigOwners.Count > 0 ? PlayerMap.Instance.GetPlayerItemFromPlayerId(grid.BigOwners.First()).Name : "No one")); entitiesFound.Add(entity); continue; } } /* * foreach(IMyEntity entity in entitiesFound) * { * IMyCubeGrid grid = (IMyCubeGrid)entity; * } */ Communication.SendPrivateInformation(userId, string.Format("Found {0} grids considered to be overlimit", entitiesFound.Count)); return(true); }