public void Reload() { var time = DateTime.Now - _lastRun; if (time.TotalMinutes < 1) { var timeRemaining = TimeSpan.FromMinutes(1) - time; Context.Respond($"Cooldown in effect. Try again in {timeRemaining.TotalSeconds:N0} seconds"); return; } if (!_doCheck) { Context.Respond("Warning: This command will drop sim speed for few seconds/minutes while recalculating limits. Run command again to proceed"); _doCheck = true; Task.Run(() => { Thread.Sleep(30000); _doCheck = false; }); return; } _doCheck = false; BlockLimiterConfig.Instance.Load(); BlockLimiterConfig.Instance.Save(); BlockLimiter.ResetLimits(); _lastRun = DateTime.Now; Context.Respond("Limits reloaded from config file"); }
public void UpdateLimits() { var time = DateTime.Now - _lastRun; if (time.TotalSeconds < 60) { var timeRemaining = TimeSpan.FromMinutes(1) - time; Context.Respond($"Cooldown in effect. Try again in {timeRemaining.TotalSeconds:N0} seconds"); return; } var args = Context.Args; if (args.Count == 0) { if (!_doCheck) { Context.Respond("Warning: This command will drop sim speed for few seconds/minutes while recalculating limits. Run command again to proceed"); _doCheck = true; Task.Run(() => { Thread.Sleep(30000); _doCheck = false; }); return; } _doCheck = false; BlockLimiterConfig.Instance.Save(); GridCache.Update(); BlockLimiter.ResetLimits(); _lastRun = DateTime.Now; Context.Respond("Limits updated"); return; } foreach (var arg in args) { if (arg.StartsWith("-player")) { var name = arg.Replace("-player=", ""); if (!Utilities.TryGetPlayerByNameOrId(name, out var identity)) { Context.Respond($"Player {name} not found"); continue; } Context.Respond($"Updated {identity.DisplayName} limits"); Utility.UpdateLimits.PlayerLimit(identity.IdentityId); continue; } if (arg.StartsWith("-grid")) { var gridName = arg.Replace("-grid=", ""); if (!Utilities.TryGetEntityByNameOrId(gridName, out var entity)) { Context.Respond($"No entity with the name {gridName} found"); continue; } if (!(entity is MyCubeGrid grid)) { Context.Respond("No grid found"); continue; } Context.Respond($"{grid.DisplayName} limits updated"); Utility.UpdateLimits.GridLimit(grid); continue; } if (arg.StartsWith("-faction")) { var factionTag = arg.Replace("-faction=", ""); var faction = MySession.Static.Factions.TryGetFactionByTag(factionTag); if (faction == null) { Context.Respond($"{factionTag} was not found in factions. Check spelling and case."); continue; } Context.Respond($"{faction.Tag} limits updated"); Utility.UpdateLimits.FactionLimit(faction.FactionId); } } }