Skip to content

Commit

Permalink
command to print config (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonilerner authored Apr 29, 2024
1 parent afae2d2 commit 4e65b4b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
22 changes: 20 additions & 2 deletions RetakesAllocator/RetakesAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public override void Load(bool hotReload)
RegisterListener<Listeners.OnMapStart>(mapName =>
{
ResetState();
Log.Debug($"Setting map name {mapName}");
RoundTypeManager.Instance.SetMap(mapName);
});

Expand Down Expand Up @@ -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: "<config>", 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
Expand Down Expand Up @@ -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<VoteMenu>(MenuType.NextRoundVote);
Expand Down Expand Up @@ -950,4 +968,4 @@ private void GiveDefuseKit(CCSPlayerController player)
}

#endregion
}
}
15 changes: 15 additions & 0 deletions RetakesAllocatorCore/Config/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion RetakesAllocatorCore/Managers/RoundTypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private RoundTypeManager()

public void Initialize()
{
_map = null;
_nextRoundTypeOverride = null;
_currentRoundType = null;
_roundTypeSelection = Configs.GetConfigData().RoundTypeSelection;
Expand Down
2 changes: 1 addition & 1 deletion RetakesAllocatorCore/NadeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static Stack<CsItem> 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<CsItem>
Expand Down
2 changes: 1 addition & 1 deletion RetakesAllocatorCore/PluginInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}] ";

Expand Down

0 comments on commit 4e65b4b

Please sign in to comment.