// admin nobeacon scan public override bool HandleCommand(ulong userId, string[] words) { string linkType = ""; if (words.Length > 0 && words[0].ToLower( ) == "physical") { linkType = " physical"; } try { string command = $"excludesblocksubtype:beacon quiet{linkType}"; HashSet <GridGroup> groups = CubeGrids.ScanGrids(0, CommandParser.GetCommandParts(command).ToArray()); int groupsCount = groups.Count; int gridsCount = 0; foreach (var group in groups) { //if ( group.GetFatBlocks( ).Any( x => x is IMyBeacon ) ) // continue; //groupsCount++; gridsCount += group.Grids.Count; Communication.SendPrivateInformation(userId, $"Found group with parent {group.Parent.DisplayName} ({group.Parent.EntityId}) at {group.Parent.PositionComp.GetPosition( )} with no beacon."); } Communication.SendPrivateInformation(userId, $"Found {gridsCount} grids in {groupsCount} groups with no beacon."); } catch (Exception ex) { Log.Info(string.Format("Scan error: {0}", ex.ToString( ))); } return(true); }
/// <exception cref="OverflowException"></exception> private void ProcessTriggerItem(SettingsCleanupTriggerItem item) { if (_triggerdItem != null && _triggerdItem != item) { return; } if (_triggerdItem == null) { // Increase to 5 minutes if (DateTime.Now - item.LastRan > TimeSpan.FromMinutes(5)) { item.LastRan = DateTime.Now; string command = string.Format("{0} quiet", item.ScanCommand); HashSet <IMyEntity> entities = CubeGrids.ScanGrids(0, command); if (entities.Count >= item.MaxCapacity) { Communication.SendPublicInformation(string.Format("[NOTICE]: Cleanup triggered. ({0} of {1}) triggered grids found. Cleanup will run in {2} minutes. Reason: {3}", entities.Count, item.MaxCapacity, item.MinutesAfterCapacity, item.Reason)); item.NotificationItemsRan.Clear( ); _triggerdItem = item; return; } } } else { if (DateTime.Now - item.LastRan > TimeSpan.FromMinutes(item.MinutesAfterCapacity)) { string command = string.Format("{0} quiet", item.ScanCommand); HashSet <IMyEntity> entities = CubeGrids.ScanGrids(0, command); CubeGrids.DeleteGrids(entities); Communication.SendPublicInformation(string.Format("[NOTICE]: Triggered cleanup has run. {0} entities removed. Have a nice day.", entities.Count)); _triggerdItem = null; return; } foreach (SettingsCleanupNotificationItem notifyItem in PluginSettings.Instance.CleanupNotificationItems) { if (item.NotificationItemsRan.Contains(notifyItem)) { continue; } if (notifyItem.MinutesBeforeCleanup > item.MinutesAfterCapacity) { continue; } if (DateTime.Now - item.LastRan > TimeSpan.FromMinutes(item.MinutesAfterCapacity - notifyItem.MinutesBeforeCleanup)) { item.NotificationItemsRan.Add(notifyItem); string notification = notifyItem.Message.Replace("%cleanup_reason%", item.Reason); Communication.SendPublicInformation(notification); } } } }
// admin nobeacon scan public override bool HandleCommand(ulong userId, string[] words) { try { CubeGrids.ScanGrids(userId, words); } catch (Exception ex) { Log.Info(ex, "scan grid"); return(false); } return(true); }
// 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); }
/// <exception cref="OverflowException"></exception> private void ProcessTimedItem(SettingsCleanupTimedItem item) { _start = DateTime.Now; // this needs to be updated for each run so multi-day runtimes are handled properly DateTime itemTime = new DateTime(_start.Year, _start.Month, _start.Day, item.Restart.Hour, item.Restart.Minute, 0); if (DateTime.Now - itemTime > _twentySeconds) { itemTime = itemTime.AddDays(1); } if (DateTime.Now - item.LastRan < _oneMinute) { return; } if (itemTime - DateTime.Now < _oneSecond && DateTime.Now - item.LastRan > _oneMinute) { string command = string.Format("{0} quiet", item.ScanCommand); HashSet <IMyEntity> entities = CubeGrids.ScanGrids(0, CommandParser.GetCommandParts(command).ToArray( )); CubeGrids.DeleteGrids(entities); Communication.SendPublicInformation(string.Format("[NOTICE]: Timed cleanup has run. {0} entities removed. Have a nice day.", entities.Count)); item.LastRan = DateTime.Now; item.NotificationItemsRan.Clear( ); return; } foreach (SettingsCleanupNotificationItem notifyItem in PluginSettings.Instance.CleanupNotificationItems) { if (item.NotificationItemsRan.Contains(notifyItem)) { continue; } if (itemTime - DateTime.Now < TimeSpan.FromMinutes(notifyItem.MinutesBeforeCleanup)) { item.NotificationItemsRan.Add(notifyItem); if (DateTime.Now - notifyItem.lastRan > _oneMinute) { notifyItem.lastRan = DateTime.Now; string notification = notifyItem.Message.Replace("%cleanup_reason%", item.Reason); Communication.SendPublicInformation(notification); } } } }
/// <exception cref="OverflowException"></exception> private void ProcessTimedItem(SettingsCleanupTimedItem item) { DateTime time = new DateTime(_start.Year, _start.Month, _start.Day, item.Restart.Hour, item.Restart.Minute, 0); if (time - DateTime.Now < TimeSpan.FromSeconds(-20)) { time = new DateTime(_start.Year, _start.Month, _start.Day + 1, item.Restart.Hour, item.Restart.Minute, 0); } if (DateTime.Now - item.LastRan < TimeSpan.FromMinutes(1)) { return; } if (time - DateTime.Now < TimeSpan.FromSeconds(1) && DateTime.Now - item.LastRan > TimeSpan.FromMinutes(1)) { string command = string.Format("{0} quiet", item.ScanCommand); HashSet <IMyEntity> entities = CubeGrids.ScanGrids(0, command); CubeGrids.DeleteGrids(entities); Communication.SendPublicInformation(string.Format("[NOTICE]: Timed cleanup has run. {0} entities removed. Have a nice day.", entities.Count)); item.LastRan = DateTime.Now; item.NotificationItemsRan.Clear( ); return; } foreach (SettingsCleanupNotificationItem notifyItem in PluginSettings.Instance.CleanupNotificationItems) { if (item.NotificationItemsRan.Contains(notifyItem)) { continue; } if (time - DateTime.Now < TimeSpan.FromMinutes(notifyItem.MinutesBeforeCleanup)) { item.NotificationItemsRan.Add(notifyItem); if (DateTime.Now - notifyItem.lastRan > TimeSpan.FromMinutes(1)) { notifyItem.lastRan = DateTime.Now; string notification = notifyItem.Message.Replace("%cleanup_reason%", item.Reason); Communication.SendPublicInformation(notification); } } } }
// admin nobeacon scan public override bool HandleCommand(ulong userId, string[] words) { HashSet <GridGroup> groups = CubeGrids.ScanGrids(userId, words); bool confirm = true; /* * if (words.FirstOrDefault(x => x.ToLower() == "confirm") != null) * { * confirm = true; * } */ int gridCount = 0; int groupCount = 0; foreach (GridGroup group in groups) { long ownerId = 0; string ownerName = ""; if (group.BigOwners.Count > 0) { ownerId = group.BigOwners.First( ); ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name; } if (confirm) { Log.Info("Cleanup removed group with parent - Id: {0} Display: {1} OwnerId: {2} OwnerName: {3}", group.Parent.EntityId, group.Parent.DisplayName, ownerId, ownerName); } gridCount += group.Grids.Count; groupCount++; if (confirm) { group.Close( ); } } Communication.SendPrivateInformation(userId, $"Operation deletes {gridCount} grids in {groupCount} groups."); return(true); }
// admin nobeacon scan public override bool HandleCommand(ulong userId, string command) { CubeGrids.ScanGrids(userId, command); return(true); }
/// <exception cref="OverflowException"></exception> private void ProcessTimedItem(SettingsCleanupTimedItem item) { _start = DateTime.Now; // this needs to be updated for each run so multi-day runtimes are handled properly DateTime itemTime; if (!item.Interval) { itemTime = new DateTime(_start.Year, _start.Month, _start.Day, item.Restart.Hour, item.Restart.Minute, 0); } else { itemTime = new DateTime(_start.Year, _start.Month, _start.Day, _start.Hour, item.Restart.Minute, 0); } if (DateTime.Now - itemTime > _twentySeconds) { itemTime = itemTime.AddDays(1); } if (DateTime.Now - item.LastRan < _oneMinute) { return; } if (itemTime - DateTime.Now < _oneSecond && DateTime.Now - item.LastRan > _oneMinute) { string command = $"{item.ScanCommand} quiet"; HashSet <GridGroup> groups = CubeGrids.ScanGrids(0, CommandParser.GetCommandParts(command).ToArray( )); int groupCount = groups.Count; int gridCount = 0; foreach (var group in groups) { gridCount += group.Grids.Count; group.Close( ); } Communication.SendPublicInformation($"[NOTICE]: Timed cleanup has run. {gridCount} grids in {groupCount} groups removed."); item.LastRan = DateTime.Now; item.NotificationItemsRan.Clear( ); return; } foreach (SettingsCleanupNotificationItem notifyItem in PluginSettings.Instance.CleanupNotificationItems) { if (item.NotificationItemsRan.Contains(notifyItem)) { continue; } if (itemTime - DateTime.Now < TimeSpan.FromMinutes(notifyItem.MinutesBeforeCleanup)) { item.NotificationItemsRan.Add(notifyItem); if (DateTime.Now - notifyItem.lastRan > _oneMinute) { notifyItem.lastRan = DateTime.Now; string notification = notifyItem.Message.Replace("%cleanup_reason%", item.Reason); Communication.SendPublicInformation(notification); } } } }
/// <exception cref="OverflowException"></exception> private void ProcessTriggerItem(SettingsCleanupTriggerItem item) { if (_triggeredItem != null && _triggeredItem != item) { return; } if (_triggeredItem == null) { // Increase to 5 minutes if (DateTime.Now - item.LastRan > _fiveMinutes) { item.LastRan = DateTime.Now; string command = item.ScanCommand + " quiet"; HashSet <GridGroup> groups = CubeGrids.ScanGrids(0, CommandParser.GetCommandParts(command).ToArray( )); int gridsCount = 0; foreach (var group in groups) { gridsCount += group.Grids.Count; } if (gridsCount >= item.MaxCapacity) { Communication.SendPublicInformation($"[NOTICE]: Cleanup triggered. ({gridsCount} of {item.MaxCapacity}) triggered grids found. Cleanup will run in {item.MinutesAfterCapacity} minutes.{(item.Reason == string.Empty ? "" : $" Reason: {item.Reason}")}"); item.NotificationItemsRan.Clear( ); _triggeredItem = item; } } } else { if (DateTime.Now - item.LastRan > TimeSpan.FromMinutes(item.MinutesAfterCapacity)) { string command = item.ScanCommand + " quiet"; HashSet <GridGroup> groups = CubeGrids.ScanGrids(0, CommandParser.GetCommandParts(command).ToArray( )); int groupCount = groups.Count; int gridCount = 0; foreach (var group in groups) { gridCount += group.Grids.Count; group.Close(); } Communication.SendPublicInformation($"[NOTICE]: Triggered cleanup has run. {gridCount} grids in {groupCount} groups removed."); _triggeredItem = null; return; } foreach (SettingsCleanupNotificationItem notifyItem in PluginSettings.Instance.CleanupNotificationItems) { if (item.NotificationItemsRan.Contains(notifyItem)) { continue; } if (notifyItem.MinutesBeforeCleanup > item.MinutesAfterCapacity) { continue; } if (DateTime.Now - item.LastRan > TimeSpan.FromMinutes(item.MinutesAfterCapacity - notifyItem.MinutesBeforeCleanup)) { item.NotificationItemsRan.Add(notifyItem); string notification = notifyItem.Message.Replace("%cleanup_reason%", item.Reason); Communication.SendPublicInformation(notification); } } } }
// admin nobeacon scan public override bool HandleCommand(ulong userId, string[] words) { CubeGrids.ScanGrids(userId, words); return(true); }