From: terencehill Date: Sun, 17 Mar 2024 17:11:45 +0000 (+0100) Subject: Fix #2903 "GUI voting: custom gametypes no longer take effect" X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8ffa64af651492393adbb5b757cd748f3e8eb6ef;p=xonotic%2Fxonotic-data.pk3dir.git Fix #2903 "GUI voting: custom gametypes no longer take effect" --- diff --git a/qcsrc/server/mapvoting.qc b/qcsrc/server/mapvoting.qc index d8ba13dcc..995fd6002 100644 --- a/qcsrc/server/mapvoting.qc +++ b/qcsrc/server/mapvoting.qc @@ -216,15 +216,21 @@ void MapVote_AddVotableMaps(int nmax, int smax) } bool GameTypeVote_SetGametype(Gametype type); -void GameTypeVote_ApplyGameType(Gametype type) + +// gametype_name can be the name of a custom gametype based on Gametype type +void GameTypeVote_ApplyGameType(Gametype type, string gametype_name) { + if (gametype_name == "") + gametype_name = MapInfo_Type_ToString(type); + localcmd("sv_vote_gametype_hook_all\n"); - localcmd("sv_vote_gametype_hook_", MapInfo_Type_ToString(type), "\n"); + localcmd("sv_vote_gametype_hook_", gametype_name, "\n"); if (!GameTypeVote_SetGametype(type)) LOG_TRACE("Selected gametype is not supported by any map"); } +string voted_gametype_string; Gametype voted_gametype; Gametype match_gametype; void MapVote_Init() @@ -272,7 +278,7 @@ void MapVote_Init() // properly restarts the map applying the current game type. // Applying voted_gametype before map vote start is needed to properly initialize map vote. if (match_gametype) - GameTypeVote_ApplyGameType(match_gametype); + GameTypeVote_ApplyGameType(match_gametype, gametype_custom_string); } void MapVote_SendPicture(entity to, int id) @@ -499,6 +505,7 @@ bool MapVote_Finished(int mappos) Map_Goto_SetStr(autocvar_nextmap); Map_Goto(0); alreadychangedlevel = true; + strfree(voted_gametype_string); return true; } else @@ -695,11 +702,12 @@ void MapVote_Think() // clear match_gametype so that GameTypeVote_ApplyGameType // prints the game type switch message match_gametype = NULL; - GameTypeVote_ApplyGameType(voted_gametype); + GameTypeVote_ApplyGameType(voted_gametype, voted_gametype_string); } Map_Goto_SetStr(mapvote_maps[mapvote_winner]); Map_Goto(0); + strfree(voted_gametype_string); } return; } @@ -793,9 +801,15 @@ bool GameTypeVote_Finished(int pos) return false; match_gametype = MapInfo_CurrentGametype(); - voted_gametype = MapInfo_Type_FromString(mapvote_maps[pos], false, false); + voted_gametype = GameTypeVote_Type_FromString(mapvote_maps[pos]); + strcpy(voted_gametype_string, mapvote_maps[pos]); + + GameTypeVote_ApplyGameType(voted_gametype, voted_gametype_string); - GameTypeVote_ApplyGameType(voted_gametype); + // save to a cvar so it can be applied back when gametype is temporary + // changed on gametype vote end of the next game + if (mapvote_maps_flags[pos] & GTV_CUSTOM) + cvar_set("_sv_vote_gametype_custom", voted_gametype_string); gametypevote_finished = true; diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index 90ddd1a99..ad40a3895 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -736,7 +736,8 @@ void InitGameplayMode() MapInfo_ClearTemps(); - gamemode_name = MapInfo_Type_ToText(MapInfo_LoadedGametype); + strcpy(gametype_custom_string, autocvar__sv_vote_gametype_custom); + cvar_set("_sv_vote_gametype_custom", ""); // clear it immediately so it can't get stuck cache_mutatormsg = strzone(""); cache_lastmutatormsg = strzone(""); @@ -2644,6 +2645,7 @@ void Shutdown() MapInfo_Shutdown(); strfree(sv_termsofservice_url_escaped); + strfree(gametype_custom_string); } else if(world_initialized == 0) { diff --git a/qcsrc/server/world.qh b/qcsrc/server/world.qh index 67adb0fab..a7301dc79 100644 --- a/qcsrc/server/world.qh +++ b/qcsrc/server/world.qh @@ -48,7 +48,8 @@ float cvar_purechanges_count; string modname; -string gamemode_name; +string autocvar__sv_vote_gametype_custom; +string gametype_custom_string; string record_type;