From f37aaad4df7666e98ff7bfed896b6cf236a779c1 Mon Sep 17 00:00:00 2001 From: Nicolai Cornelis Date: Sat, 8 Apr 2023 23:25:55 +0200 Subject: [PATCH] 0.14.1 (#1009) * Fix create match with current teams from menu (#1007) * Add option to disable formatting known map names (#1008) 0.14.1 --- CHANGELOG.md | 11 ++++++++++ documentation/docs/configuration.md | 3 +++ scripting/get5.sp | 4 +++- scripting/get5/get5menu.sp | 31 +++++++++++++++++++++-------- scripting/get5/maps.sp | 2 +- scripting/get5/mapveto.sp | 14 +++++++------ scripting/get5/matchconfig.sp | 31 +++++++++++++---------------- scripting/get5/version.sp | 2 +- 8 files changed, 64 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 801186aa1..2ca0b17ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,19 @@ Whenever you update your Get5 plugin, remember to **always** update the `transla Please see the [installation instructions](https://splewis.github.io/get5/latest/installation/#installation) for details. +# 0.14.1 + +#### 2023-04-08 + +Hotfix of stuff that should have been in 0.14.0. + +1. Fixed "create match with current teams" from the `!get5` menu. +2. Add option to disable formatting known map names via [`get5_format_map_names`](https://splewis.github.io/get5/latest/configuration/#get5_format_map_names). + # 0.14.0 +*Note: Removed from releases. Please use 0.14.1 instead.* + #### 2023-04-08 ### Breaking Changes 🛠 diff --git a/documentation/docs/configuration.md b/documentation/docs/configuration.md index cf58f0528..677c88059 100644 --- a/documentation/docs/configuration.md +++ b/documentation/docs/configuration.md @@ -551,6 +551,9 @@ value will be used for your [backup upload HTTP request](#get5_remote_backup_url ## Formats & Paths +####`get5_format_map_names` +: Whether to format known map names in chat and menus, i.e. `de_mirage` becomes `Mirage`.
**`Default: 1`** + ####`get5_time_format` : Date and time format string. This determines the [`{TIME}`](#tag-time) tag.
**`Default: "%Y-%m-%d_%H-%M-%S"`** diff --git a/scripting/get5.sp b/scripting/get5.sp index 513167737..8ee1902fd 100644 --- a/scripting/get5.sp +++ b/scripting/get5.sp @@ -63,6 +63,7 @@ ConVar g_DamagePrintExcessCvar; ConVar g_DamagePrintFormatCvar; ConVar g_DemoNameFormatCvar; ConVar g_DisplayGotvVetoCvar; +ConVar g_FormatMapNamesCvar; ConVar g_EventLogFormatCvar; ConVar g_EventLogRemoteURLCvar; ConVar g_EventLogRemoteHeaderKeyCvar; @@ -483,6 +484,7 @@ public void OnPluginStart() { g_MuteAllChatDuringMapSelectionCvar = CreateConVar("get5_mute_allchat_during_map_selection", "1", "If enabled, only the team captains can type in all-chat during map selection."); g_PauseOnVetoCvar = CreateConVar("get5_pause_on_veto", "1", "Whether the game pauses during map selection."); g_DisplayGotvVetoCvar = CreateConVar("get5_display_gotv_veto", "0", "Whether to wait for map selection to be broadcast to GOTV before changing map."); + g_FormatMapNamesCvar = CreateConVar("get5_format_map_names", "1", "Whether to format known map names."); // Server config g_AutoLoadConfigCvar = CreateConVar("get5_autoload_config", "", "The path/name of a match config file to automatically load when the server loads or when the first player joins."); @@ -1576,7 +1578,7 @@ static Action Event_MatchOver(Event event, const char[] name, bool dontBroadcast // state immediately while waiting for the restartDelay, we set it here also. g_MapChangePending = true; char nextMapFormatted[PLATFORM_MAX_PATH]; - FormatMapName(nextMap, nextMapFormatted, sizeof(nextMapFormatted), true, true); + FormatMapName(nextMap, nextMapFormatted, sizeof(nextMapFormatted), g_FormatMapNamesCvar.BoolValue, true); Get5_MessageToAll("%t", "NextSeriesMapInfoMessage", nextMapFormatted, timeToMapChangeFormatted); ChangeState(Get5State_PostGame); // Subtracting 4 seconds makes the map change 1 second before the timer expires, as there is a 3 diff --git a/scripting/get5/get5menu.sp b/scripting/get5/get5menu.sp index 39de9b999..a6deb1021 100644 --- a/scripting/get5/get5menu.sp +++ b/scripting/get5/get5menu.sp @@ -303,8 +303,8 @@ static int SetupMenuHandler(Menu menu, MenuAction action, int client, int param2 return 0; } else if (StrEqual(infoString, SETUP_MENU_START_MATCH, true)) { if (g_SetupMenuTeamSelection == Get5SetupMenu_TeamSelectionMode_Current && - (GetTeamPlayerCount(Get5Team_1) != g_SetupMenuPlayersPerTeam || - GetTeamPlayerCount(Get5Team_2) != g_SetupMenuPlayersPerTeam)) { + (GetSidePlayerCount(Get5Side_CT) != g_SetupMenuPlayersPerTeam || + GetSidePlayerCount(Get5Side_T) != g_SetupMenuPlayersPerTeam)) { Get5_Message(client, "Both teams must have %d player(s) when using current teams.", g_SetupMenuPlayersPerTeam); } else if (g_SetupMenuTeamSelection == Get5SetupMenu_TeamSelectionMode_Fixed && (strlen(g_SetupMenuTeamForTeam1) == 0 || strlen(g_SetupMenuTeamForTeam2) == 0)) { @@ -337,6 +337,16 @@ static int SetupMenuHandler(Menu menu, MenuAction action, int client, int param2 return 0; } +static int GetSidePlayerCount(Get5Side side) { + int playerCount = 0; + LOOP_CLIENTS(i) { + if (IsPlayer(i) && view_as(GetClientTeam(i)) == side) { + playerCount++; + } + } + return playerCount; +} + static void ShowSelectTeamsMenu(int client) { Menu menu = new Menu(SelectTeamsMenuHandler); menu.SetTitle("Select Teams"); @@ -555,14 +565,19 @@ static void ShowSelectMapMenu(int client) { sortedMaps.PushString(mapName); } - // Sorts maps based on their formatted name. - sortedMaps.SortCustom(SortMapsBasedOnFormattedName); + bool formatMapNames = g_FormatMapNamesCvar.BoolValue; + if (formatMapNames) { + // Sorts maps based on their formatted name. + sortedMaps.SortCustom(SortMapsBasedOnFormattedName); + } else { + sortedMaps.Sort(Sort_Ascending, Sort_String); + } char formattedMapName[PLATFORM_MAX_PATH]; l = sortedMaps.Length; for (int i = 0; i < l; i++) { sortedMaps.GetString(i, mapName, sizeof(mapName)); - FormatMapName(mapName, formattedMapName, sizeof(formattedMapName), true); + FormatMapName(mapName, formattedMapName, sizeof(formattedMapName), formatMapNames); menu.AddItem(mapName, formattedMapName); } delete sortedMaps; @@ -882,8 +897,8 @@ static void CreateMatch(int client) { if (g_SetupMenuTeamSelection == Get5SetupMenu_TeamSelectionMode_Current) { - match.SetObject("team1", GetTeamObjectFromCurrentPlayers(Get5Team_1, g_SetupMenuTeam1Captain)); - match.SetObject("team2", GetTeamObjectFromCurrentPlayers(Get5Team_2, g_SetupMenuTeam2Captain)); + match.SetObject("team1", GetTeamObjectFromCurrentPlayers(Get5Side_CT, g_SetupMenuTeam1Captain)); + match.SetObject("team2", GetTeamObjectFromCurrentPlayers(Get5Side_T, g_SetupMenuTeam2Captain)); } else if (g_SetupMenuTeamSelection == Get5SetupMenu_TeamSelectionMode_Fixed) { @@ -897,7 +912,7 @@ static void CreateMatch(int client) { match.SetObject("team1", g_SetupMenuAvailableTeams.GetObject(g_SetupMenuTeamForTeam1).DeepCopy()); } - JSON_Object spectators = GetTeamObjectFromCurrentPlayers(Get5Team_Spec); + JSON_Object spectators = GetTeamObjectFromCurrentPlayers(Get5Side_Spec); if (view_as(spectators.GetObject("players")).Length > 0) { match.SetObject("spectators", spectators); } else { diff --git a/scripting/get5/maps.sp b/scripting/get5/maps.sp index 7f28a43b7..9f8037d39 100644 --- a/scripting/get5/maps.sp +++ b/scripting/get5/maps.sp @@ -1,6 +1,6 @@ void ChangeMap(const char[] map, float delay = 3.0) { char formattedMapName[64]; - FormatMapName(map, formattedMapName, sizeof(formattedMapName), true, true); + FormatMapName(map, formattedMapName, sizeof(formattedMapName), g_FormatMapNamesCvar.BoolValue, true); Get5_MessageToAll("%t", "ChangingMapInfoMessage", formattedMapName); // pass the "true" name to a timer to changelevel diff --git a/scripting/get5/mapveto.sp b/scripting/get5/mapveto.sp index 6f68843f0..8068aef9d 100644 --- a/scripting/get5/mapveto.sp +++ b/scripting/get5/mapveto.sp @@ -82,10 +82,11 @@ static void FinishVeto() { // If a team has a map advantage, don't print that map. int mapNumber = Get5_GetMapNumber(); + bool formatMapNames = g_FormatMapNamesCvar.BoolValue; for (int i = mapNumber; i < g_MapsToPlay.Length; i++) { char map[PLATFORM_MAX_PATH]; g_MapsToPlay.GetString(i, map, sizeof(map)); - FormatMapName(map, map, sizeof(map), true, true); + FormatMapName(map, map, sizeof(map), formatMapNames, true); Get5_MessageToAll("%t", "MapIsInfoMessage", i + 1 - mapNumber, map); } @@ -309,7 +310,7 @@ static void PromptForSideSelectionInChat(const Get5Team team) { char mapName[PLATFORM_MAX_PATH]; g_MapsToPlay.GetString(g_MapsToPlay.Length - 1, mapName, sizeof(mapName)); char formattedMapName[PLATFORM_MAX_PATH]; - FormatMapName(mapName, formattedMapName, sizeof(formattedMapName), true, true); + FormatMapName(mapName, formattedMapName, sizeof(formattedMapName), g_FormatMapNamesCvar.BoolValue, true); Get5_MessageToAll("%t", "MapSelectionPickSide", g_FormattedTeamNames[team], formattedMapName); int client = g_VetoCaptains[team]; @@ -325,9 +326,10 @@ static void PromptForSideSelectionInChat(const Get5Team team) { void ImplodeMapArrayToString(const ArrayList mapPool, char[] buffer, const int bufferSize, bool sort) { char[][] mapsArray = new char[mapPool.Length][PLATFORM_MAX_PATH]; + bool formatMapNames = g_FormatMapNamesCvar.BoolValue; for (int i = 0; i < mapPool.Length; i++) { mapPool.GetString(i, mapsArray[i], PLATFORM_MAX_PATH); - FormatMapName(mapsArray[i], mapsArray[i], PLATFORM_MAX_PATH, true, false); + FormatMapName(mapsArray[i], mapsArray[i], PLATFORM_MAX_PATH, formatMapNames, false); } // Sort alphabetically. if (sort) { @@ -345,7 +347,7 @@ static bool BanMap(const char[] mapName, const Get5Team team) { return false; } char mapNameFormatted[PLATFORM_MAX_PATH]; - FormatMapName(mapNameFromArray, mapNameFormatted, sizeof(mapNameFormatted), true, false); + FormatMapName(mapNameFromArray, mapNameFormatted, sizeof(mapNameFormatted), g_FormatMapNamesCvar.BoolValue, false); // Add color here as FormatMapName would make the color green. Format(mapNameFormatted, sizeof(mapNameFormatted), "{LIGHT_RED}%s{NORMAL}", mapNameFormatted); Get5_MessageToAll("%t", "TeamBannedMap", g_FormattedTeamNames[team], mapNameFormatted); @@ -372,7 +374,7 @@ static bool PickMap(const char[] mapName, const Get5Team team) { } if (team != Get5Team_None) { char mapNameFormatted[PLATFORM_MAX_PATH]; - FormatMapName(mapNameFromArray, mapNameFormatted, sizeof(mapNameFormatted), true, true); + FormatMapName(mapNameFromArray, mapNameFormatted, sizeof(mapNameFormatted), g_FormatMapNamesCvar.BoolValue, true); Get5_MessageToAll("%t", "TeamPickedMap", g_FormattedTeamNames[team], mapNameFormatted, g_MapsToPlay.Length + 1); } @@ -404,7 +406,7 @@ static void PickSide(const Get5Side side, const Get5Team team) { char mapName[PLATFORM_MAX_PATH]; g_MapsToPlay.GetString(mapNumber, mapName, sizeof(mapName)); char mapNameFormatted[PLATFORM_MAX_PATH]; - FormatMapName(mapName, mapNameFormatted, sizeof(mapNameFormatted), true, true); + FormatMapName(mapName, mapNameFormatted, sizeof(mapNameFormatted), g_FormatMapNamesCvar.BoolValue, true); char sideFormatted[32]; FormatEx(sideFormatted, sizeof(sideFormatted), "{GREEN}%s{NORMAL}", side == Get5Side_CT ? "CT" : "T"); diff --git a/scripting/get5/matchconfig.sp b/scripting/get5/matchconfig.sp index 4e0a87011..5f2050b61 100644 --- a/scripting/get5/matchconfig.sp +++ b/scripting/get5/matchconfig.sp @@ -1829,8 +1829,8 @@ Action Command_CreateMatch(int client, int args) { // If neither team is provided, use current teams. if (!hasTeam1 && !hasTeam2) { - JSON_Object team1 = GetTeamObjectFromCurrentPlayers(Get5Team_1); - JSON_Object team2 = GetTeamObjectFromCurrentPlayers(Get5Team_2); + JSON_Object team1 = GetTeamObjectFromCurrentPlayers(Get5Side_CT); + JSON_Object team2 = GetTeamObjectFromCurrentPlayers(Get5Side_T); int team1PlayerLength = view_as(team1.GetObject("players")).Length; int team2PlayerLength = view_as(team2.GetObject("players")).Length; matchConfig.SetObject("team1", team1); @@ -2038,7 +2038,7 @@ Action Command_Ringer(int client, int args) { return Plugin_Handled; } -JSON_Object GetTeamObjectFromCurrentPlayers(const Get5Team team, int forcedCaptainClient = 0) { +JSON_Object GetTeamObjectFromCurrentPlayers(const Get5Side side, int forcedCaptainClient = 0) { JSON_Object teamObject = new JSON_Object(); JSON_Array players = new JSON_Array(); @@ -2050,7 +2050,7 @@ JSON_Object GetTeamObjectFromCurrentPlayers(const Get5Team team, int forcedCapta if (forcedCaptainClient > 0) { LOOP_CLIENTS(i) { if (i == forcedCaptainClient) { - if (CheckIfClientIsOnTeam(i, team, false) && GetAuth(i, auth, sizeof(auth))) { + if (CheckIfClientIsOnSide(i, side, false) && GetAuth(i, auth, sizeof(auth))) { SetTeamNameFromClient(i, teamName, sizeof(teamName)); players.PushString(auth); first = false; @@ -2064,9 +2064,9 @@ JSON_Object GetTeamObjectFromCurrentPlayers(const Get5Team team, int forcedCapta // Already added above. continue; } - if (CheckIfClientIsOnTeam(i, team, false) && GetAuth(i, auth, sizeof(auth))) { + if (CheckIfClientIsOnSide(i, side, false) && GetAuth(i, auth, sizeof(auth))) { players.PushString(auth); - if (first && team != Get5Team_Spec) { + if (first && side != Get5Side_Spec) { SetTeamNameFromClient(i, teamName, sizeof(teamName)); } first = false; @@ -2076,15 +2076,17 @@ JSON_Object GetTeamObjectFromCurrentPlayers(const Get5Team team, int forcedCapta teamObject.SetString("name", teamName); } teamObject.SetObject("players", players); - AddCoachesToAuthJSON(teamObject, team); + if (side != Get5Side_Spec) { + AddCoachesToAuthJSON(teamObject, side); + } return teamObject; } -void AddCoachesToAuthJSON(const JSON_Object json, const Get5Team team) { +static void AddCoachesToAuthJSON(const JSON_Object json, const Get5Side side) { JSON_Array coaches; char auth[AUTH_LENGTH]; LOOP_CLIENTS(i) { - if (CheckIfClientIsOnTeam(i, team, true) && GetAuth(i, auth, sizeof(auth))) { + if (CheckIfClientIsOnSide(i, side, true) && GetAuth(i, auth, sizeof(auth))) { if (coaches == null) { coaches = new JSON_Array(); } @@ -2100,17 +2102,12 @@ static void SetTeamNameFromClient(const int client, char[] teamName, const int t FormatEx(teamName, teamNameLength, "team_%N", client); } -static bool CheckIfClientIsOnTeam(const int client, const Get5Team team, const bool coaching) { +static bool CheckIfClientIsOnSide(const int client, const Get5Side side, const bool coaching) { if (!IsAuthedPlayer(client)) { return false; } - Get5Side side = coaching ? GetClientCoachingSide(client) : view_as(GetClientTeam(client)); - if (team == Get5Team_1 && side == Get5Side_CT) { - return true; - } else if (team == Get5Team_2 && side == Get5Side_T) { - return true; - } - return false; + Get5Side currentSide = coaching ? GetClientCoachingSide(client) : view_as(GetClientTeam(client)); + return currentSide == side; } // Adds the team logos to the download table. diff --git a/scripting/get5/version.sp b/scripting/get5/version.sp index 2cfcf6d6f..9c3a6dbe7 100644 --- a/scripting/get5/version.sp +++ b/scripting/get5/version.sp @@ -1,4 +1,4 @@ -#define PLUGIN_VERSION "0.14.0-dev" +#define PLUGIN_VERSION "0.14.1-dev" // This MUST be the latest version in x.y.z semver format followed by -dev. // If this is not consistently applied, the update-checker might malfunction. // In official releases, the CI flow will remove the -dev suffix when compiling the plugin.