]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix #2903 "GUI voting: custom gametypes no longer take effect"
authorterencehill <piuntn@gmail.com>
Sun, 17 Mar 2024 17:11:45 +0000 (18:11 +0100)
committerterencehill <piuntn@gmail.com>
Mon, 18 Mar 2024 21:46:38 +0000 (22:46 +0100)
qcsrc/server/mapvoting.qc
qcsrc/server/world.qc
qcsrc/server/world.qh

index d8ba13dcc2633ae0e0925143b9c145eea2d8530e..995fd60029afdaf7a524a9ad0f28b74825aee91c 100644 (file)
@@ -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;
 
index 90ddd1a9902f4d5a95b65ef640d04ae98244a622..ad40a389543bcb5698d2abc2a0ddd1068e1f0557 100644 (file)
@@ -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)
        {
index 67adb0fab77201a230537eff216c9790175ff656..a7301dc799b1fa96bc5a3102d95bc71faa3bd167 100644 (file)
@@ -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;