Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command to print config #124

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading