Skip to content

Commit

Permalink
Use automatic map reload logic to clear game state from previous matc…
Browse files Browse the repository at this point in the history
…hes (#1000)
  • Loading branch information
nickdnk committed Mar 20, 2023
1 parent 7b790f6 commit 08b235b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 13 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,14 @@ details.
immediately following the end of the series, but now waits until the restore timer fires. Get5 will be in `post_game`
until the timer runs out, similarly to when waiting for the next map. This means that GOTV broadcasts will have a
chance to finish before Get5 releases the server.
7. The map is now **always** reloaded when a match configuration is loaded, even if the server is already on the correct
7. The map is now always reloaded when a match configuration is loaded, even if the server is already on the correct
map. Similarly, if doing in-game map selection (veto), the map is always changed to the first map in the series, even
if the server is already on that map. This reverts this change
from [0.13](https://github.com/splewis/get5/blob/development/CHANGELOG.md#0130).
from [0.13](https://github.com/splewis/get5/blob/development/CHANGELOG.md#0130). You can disable this behavior
via [`get5_always_reload_map`](https://splewis.github.io/get5/dev/configuration/#get5_always_reload_map), but you
should only do this if you know your server is *always fresh*; if it was just rebooted or started as a container. The
reason we force-reload the map is to prevent various game state bugs caused by previous matches, such as [the warmup
countdown timer stopping at 0.01](https://github.com/splewis/get5/issues/976).

### New Features / Changes 🎉

Expand Down
6 changes: 5 additions & 1 deletion scripting/get5.sp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ ConVar g_CoachingEnabledCvar;
int g_MapsToWin = 1; // Maps needed to win the series.
bool g_SeriesCanClinch = true;
bool g_Wingman = false;
int g_RoundNumber = -1; // The round number, 0-indexed. -1 if the match is not live.
bool g_MapReloadRequired = false; // Gets set to true on match-win, so matches are always reloaded if a previous
// game was played on the same map with no reload in between.
int g_RoundNumber = -1; // The round number, 0-indexed. -1 if the match is not live.
// The active map number, used by stats. Required as the calculated round number changes immediately
// as a map ends, but before the map changes to the next.
int g_MapNumber = 0; // the current map number, starting at 0.
Expand Down Expand Up @@ -856,6 +858,7 @@ public void OnMapStart() {
g_ReadyTimeWaitingUsed = 0;
g_KnifeWinnerTeam = Get5Team_None;
g_HasKnifeRoundStarted = false;
g_MapReloadRequired = false;

LOOP_TEAMS(team) {
g_TeamGivenStopCommand[team] = false;
Expand Down Expand Up @@ -1413,6 +1416,7 @@ static Action Timer_ReplenishMoney(Handle timer, int client) {

static Action Event_MatchOver(Event event, const char[] name, bool dontBroadcast) {
LogDebug("Event_MatchOver");
g_MapReloadRequired = true; // Set even if Get5 is not running, so Get5 will know to reload the map.
if (g_GameState == Get5State_None) {
return Plugin_Continue;
}
Expand Down
2 changes: 1 addition & 1 deletion scripting/get5/backups.sp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ bool RestoreFromBackup(const char[] path, char[] error) {
}
delete kv;

if (backupIsForDifferentMap) {
if (backupIsForDifferentMap || (g_MapReloadRequired && backupIsForDifferentMatch)) {
// We don't need to assign players if changing map; this will be done when the players rejoin.
// If a map is to be changed, we want to suppress all stats events immediately, as the
// Get5_OnBackupRestore is called now and we don't want events firing after this until the game
Expand Down
2 changes: 1 addition & 1 deletion scripting/get5/debug.sp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static void AddGlobalStateInfo(File f) {
f.WriteLine("g_SeriesCanClinch = %d", g_SeriesCanClinch);
f.WriteLine("g_Wingman = %d", g_Wingman);
f.WriteLine("g_HasKnifeRoundStarted = %d", g_HasKnifeRoundStarted);

f.WriteLine("g_MapReloadRequired = %d", g_MapReloadRequired);
f.WriteLine("g_MapChangePending = %d", g_MapChangePending);
f.WriteLine("g_PendingSideSwap = %d", g_PendingSideSwap);
f.WriteLine("g_DoingBackupRestoreNow = %d", g_DoingBackupRestoreNow);
Expand Down
32 changes: 27 additions & 5 deletions scripting/get5/mapveto.sp
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,35 @@ static void FinishVeto() {
Get5_MessageToAll("%t", "MapIsInfoMessage", i + 1 - mapNumber, map);
}

float delay = 7.0;
g_MapChangePending = true;
if (g_DisplayGotvVetoCvar.BoolValue) {
delay = float(GetTvDelay()) + delay;
char currentMapName[PLATFORM_MAX_PATH];
GetCurrentMap(currentMapName, sizeof(currentMapName));

char mapToPlay[PLATFORM_MAX_PATH];
g_MapsToPlay.GetString(0, mapToPlay, sizeof(mapToPlay));

// In case the sides don't match after selection, we check it here before writing the backup.
// Also required if the map doesn't need to change.
SetStartingTeams();
SetMatchTeamCvars();

if (IsMapReloadRequiredForGameMode(g_Wingman) || g_MapReloadRequired || !StrEqual(currentMapName, mapToPlay)) {
ResetReadyStatus();
SetCorrectGameMode();
float delay = 7.0;
g_MapChangePending = true;
if (g_DisplayGotvVetoCvar.BoolValue) {
delay = float(GetTvDelay()) + delay;
}
g_PendingMapChangeTimer = CreateTimer(delay, Timer_NextMatchMap);
} else {
LOOP_CLIENTS(i) {
if (IsPlayer(i)) {
CheckClientTeam(i);
}
}
}
g_PendingMapChangeTimer = CreateTimer(delay, Timer_NextMatchMap);
ChangeState(Get5State_Warmup);
WriteBackup(); // Write first pre-live backup after veto.
}

// Main Veto Controller
Expand Down
12 changes: 9 additions & 3 deletions scripting/get5/matchconfig.sp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ bool LoadMatchConfig(const char[] config, char[] error, bool restoreBackup = fal
ServerCommand("mp_backup_round_file backup_%s", serverId);

if (!restoreBackup) {
SetCorrectGameMode();
StopRecording(); // Ensure no recording is running when starting a match, as that prevents Get5 from starting one.
ExecCfg(g_WarmupCfgCvar);
StartWarmup();
Expand Down Expand Up @@ -160,10 +159,17 @@ bool LoadMatchConfig(const char[] config, char[] error, bool restoreBackup = fal
LogError("Setting player auths in the \"players\" or \"coaches\" section has no impact with get5_check_auths 0");
}

// If we veto, the map will change after veto, otherwise we change it immediately.
// If we veto, the map and game mode will change after veto, otherwise we change it immediately.
// When restoring from backup, changelevel is called after loading the match config.
if (g_SkipVeto) {
g_MapsToPlay.GetString(0, mapName, sizeof(mapName));
ChangeMap(mapName, 3.0);
char currentMap[PLATFORM_MAX_PATH];
GetCurrentMap(currentMap, sizeof(currentMap));
if (g_MapReloadRequired || !StrEqual(mapName, currentMap) || IsMapReloadRequiredForGameMode(g_Wingman)) {
// If we do the veto, game mode and map change is done post-veto instead.
SetCorrectGameMode();
ChangeMap(mapName);
}
} else if (g_CheckAuthsCvar.BoolValue) {
// ExecuteMatchConfigCvars must be executed before we place players, as it might have
// get5_check_auths 1. We must also have called SetStartingTeams to get the sides right. When
Expand Down
3 changes: 3 additions & 0 deletions scripting/get5/tests.sp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ static void Get5_Test() {
return;
}

// This kind of messes with the test flow of backups.
FindConVar("get5_always_reload_map").SetBool(false);

// We reset these to default as tests need them to be consistent.
SetConVarStringSafe("mp_teamscore_max", "0");
SetConVarStringSafe("mp_teammatchstat_txt", "");
Expand Down

0 comments on commit 08b235b

Please sign in to comment.