From 4e65b4b6fd6e2c5283464d9e53d3a557adaa3e37 Mon Sep 17 00:00:00 2001 From: Yoni Lerner Date: Sun, 28 Apr 2024 23:23:04 -0400 Subject: [PATCH] command to print config (#124) --- RetakesAllocator/RetakesAllocator.cs | 22 +++++++++++++++++-- RetakesAllocatorCore/Config/Configs.cs | 15 +++++++++++++ .../Managers/RoundTypeManager.cs | 1 - RetakesAllocatorCore/NadeHelpers.cs | 2 +- RetakesAllocatorCore/PluginInfo.cs | 2 +- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/RetakesAllocator/RetakesAllocator.cs b/RetakesAllocator/RetakesAllocator.cs index 0356a7f..e6d032c 100644 --- a/RetakesAllocator/RetakesAllocator.cs +++ b/RetakesAllocator/RetakesAllocator.cs @@ -56,6 +56,7 @@ public override void Load(bool hotReload) RegisterListener(mapName => { ResetState(); + Log.Debug($"Setting map name {mapName}"); RoundTypeManager.Instance.SetMap(mapName); }); @@ -321,6 +322,23 @@ public void OnReloadAllocatorConfigCommand(CCSPlayerController? player, CommandI RoundTypeManager.Instance.Initialize(); } + [ConsoleCommand("css_print_config", "Print the entire config or a specific config.")] + [CommandHelper(usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + [RequiresPermissions("@css/root")] + public void OnPrintConfigCommand(CCSPlayerController? player, CommandInfo commandInfo) + { + var configName = commandInfo.ArgCount > 1 ? commandInfo.GetArg(1) : null; + var response = Configs.StringifyConfig(configName); + if (response is null) + { + commandInfo.ReplyToCommand($"{MessagePrefix}Invalid config name."); + return; + } + + commandInfo.ReplyToCommand($"{MessagePrefix}{response}"); + Log.Info(response); + } + #endregion #region Events @@ -592,7 +610,7 @@ out _ private void HandleAllocateEvent() { IsAllocatingForRound = true; - Log.Debug("Handling allocate event"); + Log.Debug($"Handling allocate event"); Server.ExecuteCommand("mp_max_armor 0"); var menu = _allocatorMenuManager.GetMenu(MenuType.NextRoundVote); @@ -950,4 +968,4 @@ private void GiveDefuseKit(CCSPlayerController player) } #endregion -} +} \ No newline at end of file diff --git a/RetakesAllocatorCore/Config/Configs.cs b/RetakesAllocatorCore/Config/Configs.cs index a8b22fd..f40ce2f 100644 --- a/RetakesAllocatorCore/Config/Configs.cs +++ b/RetakesAllocatorCore/Config/Configs.cs @@ -89,6 +89,21 @@ private static void SaveConfigData(ConfigData configData) File.WriteAllText(_configFilePath, JsonSerializer.Serialize(configData, SerializationOptions)); } + + public static string? StringifyConfig(string? configName) + { + var configData = GetConfigData(); + if (configName is null) + { + return JsonSerializer.Serialize(configData, SerializationOptions); + } + var property = configData.GetType().GetProperty(configName); + if (property is null) + { + return null; + } + return JsonSerializer.Serialize(property.GetValue(configData), SerializationOptions); + } } public enum WeaponSelectionType diff --git a/RetakesAllocatorCore/Managers/RoundTypeManager.cs b/RetakesAllocatorCore/Managers/RoundTypeManager.cs index b1e9775..215681b 100644 --- a/RetakesAllocatorCore/Managers/RoundTypeManager.cs +++ b/RetakesAllocatorCore/Managers/RoundTypeManager.cs @@ -28,7 +28,6 @@ private RoundTypeManager() public void Initialize() { - _map = null; _nextRoundTypeOverride = null; _currentRoundType = null; _roundTypeSelection = Configs.GetConfigData().RoundTypeSelection; diff --git a/RetakesAllocatorCore/NadeHelpers.cs b/RetakesAllocatorCore/NadeHelpers.cs index 8ec4878..c9cc9e2 100644 --- a/RetakesAllocatorCore/NadeHelpers.cs +++ b/RetakesAllocatorCore/NadeHelpers.cs @@ -61,7 +61,7 @@ public static Stack GetUtilForTeam(string? map, RoundType roundType, CsT _ => (int) Math.Ceiling(numPlayers * multiplier) }; - Log.Debug($"Nade setting: {maxNadesSetting}. Total: {maxTotalNades}"); + Log.Debug($"Nade setting: {maxNadesSetting}. Total: {maxTotalNades}. Map: {map}"); var molly = team == CsTeam.Terrorist ? CsItem.Molotov : CsItem.Incendiary; var nadeDistribution = new List diff --git a/RetakesAllocatorCore/PluginInfo.cs b/RetakesAllocatorCore/PluginInfo.cs index 8128b34..8cfdfe3 100644 --- a/RetakesAllocatorCore/PluginInfo.cs +++ b/RetakesAllocatorCore/PluginInfo.cs @@ -5,7 +5,7 @@ namespace RetakesAllocatorCore; public static class PluginInfo { - public const string Version = "2.3.9"; + public const string Version = "2.3.10"; public static readonly string LogPrefix = $"[RetakesAllocator {Version}] ";