From 0d2e840c666f0ab17317bb35c3e03fb8672fa036 Mon Sep 17 00:00:00 2001 From: B3none Date: Fri, 26 Jul 2024 18:47:35 +0100 Subject: [PATCH 1/8] Added initial mapconfig command to allow server owners to load a different map config --- RetakesPlugin/Modules/Configs/MapConfig.cs | 10 +++++++--- RetakesPlugin/RetakesPlugin.cs | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/RetakesPlugin/Modules/Configs/MapConfig.cs b/RetakesPlugin/Modules/Configs/MapConfig.cs index 540b0d5..49bcafd 100644 --- a/RetakesPlugin/Modules/Configs/MapConfig.cs +++ b/RetakesPlugin/Modules/Configs/MapConfig.cs @@ -17,7 +17,7 @@ public MapConfig(string moduleDirectory, string mapName) _mapConfigData = null; } - public void Load() + public void Load(bool isViaCommand = false) { Helpers.Debug($"Attempting to load map data from {_mapConfigPath}"); @@ -42,8 +42,12 @@ public void Load() catch (FileNotFoundException) { Helpers.Debug($"No config for map {_mapName}"); - _mapConfigData = new MapConfigData(); - Save(); + + if (!isViaCommand) + { + _mapConfigData = new MapConfigData(); + Save(); + } } catch (Exception ex) { diff --git a/RetakesPlugin/RetakesPlugin.cs b/RetakesPlugin/RetakesPlugin.cs index d42d469..1b3abbe 100644 --- a/RetakesPlugin/RetakesPlugin.cs +++ b/RetakesPlugin/RetakesPlugin.cs @@ -135,6 +135,24 @@ public void OnCommandForceBombsite(CCSPlayerController? player, CommandInfo comm commandInfo.ReplyToCommand($"{MessagePrefix}The bombsite will now be forced to {_forcedBombsite}."); } + [ConsoleCommand("css_mapconfig", "Forces a specific map config file to load.")] + [CommandHelper(minArgs: 1, usage: "[filename]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + [RequiresPermissions("@css/root")] + public void OnCommandMapConfig(CCSPlayerController? player, CommandInfo commandInfo) + { + if (!Helpers.IsValidPlayer(player)) + { + return; + } + + var mapConfigFileName = commandInfo.GetArg(1).Trim().Replace(".json", ""); + + _mapConfig = new MapConfig(ModuleDirectory, mapConfigFileName); + _mapConfig.Load(true); + + commandInfo.ReplyToCommand($"{MessagePrefix}There is likely additional output above as to whether it was successful or not..."); + } + [ConsoleCommand("css_showspawns", "Show the spawns for the specified bombsite.")] [ConsoleCommand("css_spawns", "Show the spawns for the specified bombsite.")] [ConsoleCommand("css_edit", "Show the spawns for the specified bombsite.")] @@ -629,7 +647,7 @@ public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) if (_mapConfig != null) { - var numSpawns = Helpers.ShowSpawns(_mapConfig.GetSpawnsClone(), _showingSpawnsForBombsite); + Helpers.ShowSpawns(_mapConfig.GetSpawnsClone(), _showingSpawnsForBombsite); } return HookResult.Continue; From e205488396095e44e2ff5c3ccf36951383566668 Mon Sep 17 00:00:00 2001 From: B3none Date: Sat, 27 Jul 2024 18:15:50 +0100 Subject: [PATCH 2/8] Fixed overwriting of map config --- RetakesPlugin/RetakesPlugin.cs | 40 ++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/RetakesPlugin/RetakesPlugin.cs b/RetakesPlugin/RetakesPlugin.cs index 1b3abbe..b13ec78 100644 --- a/RetakesPlugin/RetakesPlugin.cs +++ b/RetakesPlugin/RetakesPlugin.cs @@ -82,8 +82,11 @@ public override void Load(bool hotReload) MessagePrefix = _translator["retakes.prefix"]; Helpers.Debug($"Plugin loaded!"); - - RegisterListener(OnMapStart); + + RegisterListener(mapName => + { + OnMapStart(mapName); + }); AddCommandListener("jointeam", OnCommandJoinTeam); @@ -98,19 +101,21 @@ public override void Load(bool hotReload) } #region Commands - [ConsoleCommand("css_forcebombsitestop", "Clear the forced bombsite and return back to normal.")] - [CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + [ConsoleCommand("css_mapconfig", "Forces a specific map config file to load.")] + [CommandHelper(minArgs: 1, usage: "[filename]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [RequiresPermissions("@css/root")] - public void OnCommandForceBombsiteStop(CCSPlayerController? player, CommandInfo commandInfo) + public void OnCommandMapConfig(CCSPlayerController? player, CommandInfo commandInfo) { if (!Helpers.IsValidPlayer(player)) { return; } - _forcedBombsite = null; + var mapConfigFileName = commandInfo.GetArg(1).Trim().Replace(".json", ""); - commandInfo.ReplyToCommand($"{MessagePrefix}The bombsite will no longer be forced."); + OnMapStart(Server.MapName, mapConfigFileName); + + commandInfo.ReplyToCommand($"{MessagePrefix}There is likely additional output above as to whether it was successful or not..."); } [ConsoleCommand("css_forcebombsite", "Force the retakes to occur from a single bombsite.")] @@ -135,22 +140,19 @@ public void OnCommandForceBombsite(CCSPlayerController? player, CommandInfo comm commandInfo.ReplyToCommand($"{MessagePrefix}The bombsite will now be forced to {_forcedBombsite}."); } - [ConsoleCommand("css_mapconfig", "Forces a specific map config file to load.")] - [CommandHelper(minArgs: 1, usage: "[filename]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + [ConsoleCommand("css_forcebombsitestop", "Clear the forced bombsite and return back to normal.")] + [CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [RequiresPermissions("@css/root")] - public void OnCommandMapConfig(CCSPlayerController? player, CommandInfo commandInfo) + public void OnCommandForceBombsiteStop(CCSPlayerController? player, CommandInfo commandInfo) { if (!Helpers.IsValidPlayer(player)) { return; } - var mapConfigFileName = commandInfo.GetArg(1).Trim().Replace(".json", ""); - - _mapConfig = new MapConfig(ModuleDirectory, mapConfigFileName); - _mapConfig.Load(true); + _forcedBombsite = null; - commandInfo.ReplyToCommand($"{MessagePrefix}There is likely additional output above as to whether it was successful or not..."); + commandInfo.ReplyToCommand($"{MessagePrefix}The bombsite will no longer be forced."); } [ConsoleCommand("css_showspawns", "Show the spawns for the specified bombsite.")] @@ -501,9 +503,9 @@ public void OnCommandVoices(CCSPlayerController? player, CommandInfo commandInfo #endregion #region Listeners - private void OnMapStart(string mapName) + private void OnMapStart(string mapName, string? customMapConfig = null) { - Helpers.Debug($"OnMapStart listener triggered!"); + Helpers.Debug("OnMapStart listener triggered!"); ResetState(); @@ -514,9 +516,9 @@ private void OnMapStart(string mapName) }); // If we don't have a map config loaded, load it. - if (!MapConfig.IsLoaded(_mapConfig, Server.MapName)) + if (!MapConfig.IsLoaded(_mapConfig, customMapConfig ?? mapName)) { - _mapConfig = new MapConfig(ModuleDirectory, Server.MapName); + _mapConfig = new MapConfig(ModuleDirectory, customMapConfig ?? mapName); _mapConfig.Load(); } From 3cbf63c23ec23959cc740d70619f1a3130839b51 Mon Sep 17 00:00:00 2001 From: B3none Date: Sat, 27 Jul 2024 18:18:22 +0100 Subject: [PATCH 3/8] Updated replytocommand for css_mapconfig --- RetakesPlugin/RetakesPlugin.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RetakesPlugin/RetakesPlugin.cs b/RetakesPlugin/RetakesPlugin.cs index b13ec78..9f3ffee 100644 --- a/RetakesPlugin/RetakesPlugin.cs +++ b/RetakesPlugin/RetakesPlugin.cs @@ -115,7 +115,7 @@ public void OnCommandMapConfig(CCSPlayerController? player, CommandInfo commandI OnMapStart(Server.MapName, mapConfigFileName); - commandInfo.ReplyToCommand($"{MessagePrefix}There is likely additional output above as to whether it was successful or not..."); + commandInfo.ReplyToCommand($"{MessagePrefix}If this file exists, then the map config has been forced to load."); } [ConsoleCommand("css_forcebombsite", "Force the retakes to occur from a single bombsite.")] From 7444d47663d5d4d5fd4abf1203c2d8c23743488e Mon Sep 17 00:00:00 2001 From: B3none Date: Sat, 27 Jul 2024 18:22:40 +0100 Subject: [PATCH 4/8] Added !mapconfigs command to output a list of the map configs --- RetakesPlugin/RetakesPlugin.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/RetakesPlugin/RetakesPlugin.cs b/RetakesPlugin/RetakesPlugin.cs index 9f3ffee..d39a18d 100644 --- a/RetakesPlugin/RetakesPlugin.cs +++ b/RetakesPlugin/RetakesPlugin.cs @@ -118,6 +118,28 @@ public void OnCommandMapConfig(CCSPlayerController? player, CommandInfo commandI commandInfo.ReplyToCommand($"{MessagePrefix}If this file exists, then the map config has been forced to load."); } + [ConsoleCommand("css_mapconfigs", "Displays a list of available map configs.")] + [CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + [RequiresPermissions("@css/root")] + public void OnCommandMapConfigs(CCSPlayerController? player, CommandInfo commandInfo) + { + if (player == null || !Helpers.IsValidPlayer(player)) + { + return; + } + + var mapConfigDirectory = Path.Combine(ModuleDirectory, "map_config"); + + // output each of the files in the directory above + foreach (var file in Directory.GetFiles(mapConfigDirectory)) + { + commandInfo.ReplyToCommand($"{MessagePrefix}{file}"); + player.PrintToConsole($"{MessagePrefix}{file}"); + } + + commandInfo.ReplyToCommand($"{MessagePrefix}A list of available map configs has been outputted above."); + } + [ConsoleCommand("css_forcebombsite", "Force the retakes to occur from a single bombsite.")] [CommandHelper(minArgs: 1, usage: "[A/B]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [RequiresPermissions("@css/root")] From 39fad70e6bab26775b37fee9af1e4d61c97185c0 Mon Sep 17 00:00:00 2001 From: B3none Date: Sat, 27 Jul 2024 18:27:26 +0100 Subject: [PATCH 5/8] Improved output of the mapconfigs command --- RetakesPlugin/RetakesPlugin.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/RetakesPlugin/RetakesPlugin.cs b/RetakesPlugin/RetakesPlugin.cs index d39a18d..1957e92 100644 --- a/RetakesPlugin/RetakesPlugin.cs +++ b/RetakesPlugin/RetakesPlugin.cs @@ -130,11 +130,23 @@ public void OnCommandMapConfigs(CCSPlayerController? player, CommandInfo command var mapConfigDirectory = Path.Combine(ModuleDirectory, "map_config"); - // output each of the files in the directory above - foreach (var file in Directory.GetFiles(mapConfigDirectory)) + var files = Directory.GetFiles(mapConfigDirectory); + + if (!Directory.Exists(mapConfigDirectory) || files.Length == 0) { - commandInfo.ReplyToCommand($"{MessagePrefix}{file}"); - player.PrintToConsole($"{MessagePrefix}{file}"); + commandInfo.ReplyToCommand($"{MessagePrefix}No map configs found."); + return; + } + + foreach (var file in files) + { + var transformedFile = file + .Replace(mapConfigDirectory, "") + .Replace("\\", "") + .Replace(".json", ""); + + commandInfo.ReplyToCommand($"{MessagePrefix}{transformedFile}"); + player.PrintToConsole($"{MessagePrefix}{transformedFile}"); } commandInfo.ReplyToCommand($"{MessagePrefix}A list of available map configs has been outputted above."); From 5bbcad9989ddddb44f0ca6e60bc34f49c5f72a9c Mon Sep 17 00:00:00 2001 From: B3none Date: Sat, 27 Jul 2024 18:37:21 +0100 Subject: [PATCH 6/8] Added latest update to mapconfig command --- RetakesPlugin/RetakesPlugin.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/RetakesPlugin/RetakesPlugin.cs b/RetakesPlugin/RetakesPlugin.cs index 1957e92..fa45e55 100644 --- a/RetakesPlugin/RetakesPlugin.cs +++ b/RetakesPlugin/RetakesPlugin.cs @@ -111,11 +111,27 @@ public void OnCommandMapConfig(CCSPlayerController? player, CommandInfo commandI return; } + var mapConfigDirectory = Path.Combine(ModuleDirectory, "map_config"); + + if (!Directory.Exists(mapConfigDirectory)) + { + commandInfo.ReplyToCommand($"{MessagePrefix}No map configs found."); + return; + } + var mapConfigFileName = commandInfo.GetArg(1).Trim().Replace(".json", ""); + var mapConfigFilePath = Path.Combine(mapConfigDirectory, $"{mapConfigFileName}.json"); + + if (!File.Exists(mapConfigFilePath)) + { + commandInfo.ReplyToCommand($"{MessagePrefix}Map config file not found."); + return; + } + OnMapStart(Server.MapName, mapConfigFileName); - commandInfo.ReplyToCommand($"{MessagePrefix}If this file exists, then the map config has been forced to load."); + commandInfo.ReplyToCommand($"{MessagePrefix}The new map config has been successfully loaded."); } [ConsoleCommand("css_mapconfigs", "Displays a list of available map configs.")] @@ -141,8 +157,7 @@ public void OnCommandMapConfigs(CCSPlayerController? player, CommandInfo command foreach (var file in files) { var transformedFile = file - .Replace(mapConfigDirectory, "") - .Replace("\\", "") + .Replace($"{mapConfigDirectory}/", "") .Replace(".json", ""); commandInfo.ReplyToCommand($"{MessagePrefix}{transformedFile}"); From 0824a82f0e375412ab2715ef2388b02c624df5ba Mon Sep 17 00:00:00 2001 From: B3none Date: Sat, 27 Jul 2024 18:47:16 +0100 Subject: [PATCH 7/8] Added alternative commands to view, and load map configs --- RetakesPlugin/RetakesPlugin.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RetakesPlugin/RetakesPlugin.cs b/RetakesPlugin/RetakesPlugin.cs index fa45e55..a7ae6c7 100644 --- a/RetakesPlugin/RetakesPlugin.cs +++ b/RetakesPlugin/RetakesPlugin.cs @@ -102,6 +102,8 @@ public override void Load(bool hotReload) #region Commands [ConsoleCommand("css_mapconfig", "Forces a specific map config file to load.")] + [ConsoleCommand("css_setmapconfig", "Forces a specific map config file to load.")] + [ConsoleCommand("css_loadmapconfig", "Forces a specific map config file to load.")] [CommandHelper(minArgs: 1, usage: "[filename]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [RequiresPermissions("@css/root")] public void OnCommandMapConfig(CCSPlayerController? player, CommandInfo commandInfo) @@ -135,6 +137,8 @@ public void OnCommandMapConfig(CCSPlayerController? player, CommandInfo commandI } [ConsoleCommand("css_mapconfigs", "Displays a list of available map configs.")] + [ConsoleCommand("css_viewmapconfigs", "Displays a list of available map configs.")] + [ConsoleCommand("css_listmapconfigs", "Displays a list of available map configs.")] [CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [RequiresPermissions("@css/root")] public void OnCommandMapConfigs(CCSPlayerController? player, CommandInfo commandInfo) From c2554a023c22641b981efe2694ae96db0e07089f Mon Sep 17 00:00:00 2001 From: B3none Date: Sat, 27 Jul 2024 18:49:29 +0100 Subject: [PATCH 8/8] Updated README.md to add the two new commands --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 06164d6..8466ff3 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ When the plugin is first loaded it will create a `retakes_config.json` file in t | IsDebugMode | Whether to enable debug output to the server console or not. | false | false | true | | ShouldForceEvenTeamsWhenPlayerCountIsMultipleOf10 | Whether to force even teams when the active players is a multiple of 10 or not. (this means you will get 5v5 @ 10 players / 10v10 @ 20 players) | true | false | true | | EnableFallbackBombsiteAnnouncement | Whether to enable the fallback bombsite announcement. | true | false | true | -| ShouldRemoveSpectators | When a player is moved to spectators, remove them from all retake queues. Ensures that AFK plugins work as expected. | false | false | true | +| ShouldRemoveSpectators | When a player is moved to spectators, remove them from all retake queues. Ensures that AFK plugins work as expected. | false | false | true | ## Commands | Command | Arguments | Description | Permissions | @@ -76,6 +76,8 @@ When the plugin is first loaded it will create a `retakes_config.json` file in t | !removespawn | | Removes the nearest spawn point for the bombsite currently shown. | @css/root | | !nearestspawn | | Teleports the player to the nearest spawn. | @css/root | | !hidespawns | | Exits the spawn editing mode. | @css/root | +| !mapconfig | | Forces a specific map config file to load. | @css/root | +| !mapconfigs | | Displays a list of available map configs. | @css/root | | !scramble | | Scrambles the teams next round. | @css/admin | | !voices | | Toggles whether or not to hear the bombsite voice announcements. | | | css_debugqueues | | **SERVER ONLY** Shows the current queue state in the server console. | |