Skip to content

Commit

Permalink
Clean up pause time counter logic:
Browse files Browse the repository at this point in the history
Remove g_PauseTimeUsed
Only fire necessary timers
Ensure fixed pause configuration takes precedence over combined max pause time
Don't allow unpausing fixed pauses (doesn't work)
Redirect sm_tech to admin pause if used in console
Prevent direct calls to mp_pause_match and mp_unpause_match, force sm_pause/sm_unpause
Fix "0 / x" pauses used on first pause
Adjusted translations for above changes

Remove g_TeamGivenTechPauseCommand array
Add g_PausingTeam and g_PauseType to debug output
Prevent multiple pauses from being triggered at the same time
Prevent spectators and team none from ever calling pause or unpause

Only allow pause in live mode
Add more translations
Renamed g_MaxTechPauseTime to g_MaxTechPauseDurationCvar for consistency
Renamed g_MaxPausesCvar to g_MaxTacticalPausesCvar for consistency
Renamed g_TechPausedTimeOverride to g_TechnicalPauseTimeUsed, as that's what it is
Got rid of a lot of code duplication
Renamed g_TeamPauseTimeUsed to g_TacticalPauseTimeUsed
Renamed g_TechPauseTimeUsed to g_TechnicalPauseTimeUsed
Renamed g_TeamPausesUsed to g_TacticalPausesUsed
Renamed g_TeamTechPausesUsed to g_TechnicalPausesUsed

Add print-to-all localized hint for timed pauses not using the fixed ingame pause timer
Adjusted Fixed-time unpause timer to only fire event + reset g_PauseType; avoids RequestFrame hacks
Add util function for converting seconds to minutes:seconds
Fix missing Danish translations, because, well, I speak it.
  • Loading branch information
nickdnk committed Jul 23, 2022
1 parent f18b336 commit 4595e3e
Show file tree
Hide file tree
Showing 15 changed files with 467 additions and 328 deletions.
13 changes: 9 additions & 4 deletions documentation/docs/event_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,11 @@ paths:
schema:
title: Get5MatchPausedEvent
allOf:
- "$ref": "#/components/schemas/Get5MapTeamEvent"
- "$ref": "#/components/schemas/Get5MatchPauseEvent"
properties:
event:
enum:
- game_paused
pause_type:
$ref: "#/components/schemas/Get5PauseType"
responses: { }
"/Get5_OnMatchUnpaused":
post:
Expand All @@ -196,7 +194,7 @@ paths:
schema:
title: Get5MatchUnpausedEvent
allOf:
- "$ref": "#/components/schemas/Get5MapTeamEvent"
- "$ref": "#/components/schemas/Get5MatchPauseEvent"
properties:
event:
enum:
Expand Down Expand Up @@ -962,6 +960,13 @@ components:
- technical
- admin
- backup
Get5MatchPauseEvent:
allOf:
- "$ref": "#/components/schemas/Get5MapTeamEvent"
- type: object
properties:
pause_type:
$ref: "#/components/schemas/Get5PauseType"
Get5Player:
type: object
properties:
Expand Down
57 changes: 35 additions & 22 deletions scripting/get5.sp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@

/** ConVar handles **/
ConVar g_AllowTechPauseCvar;
ConVar g_MaxTechPauseTime;
ConVar g_MaxTechPauseCvar;
ConVar g_MaxTechPauseDurationCvar;
ConVar g_MaxTechPausesCvar;
ConVar g_AutoLoadConfigCvar;
ConVar g_AutoReadyActivePlayersCvar;
ConVar g_BackupSystemEnabledCvar;
Expand All @@ -70,7 +70,7 @@ ConVar g_KickClientsWithNoMatchCvar;
ConVar g_LiveCfgCvar;
ConVar g_LiveCountdownTimeCvar;
ConVar g_MaxBackupAgeCvar;
ConVar g_MaxPausesCvar;
ConVar g_MaxTacticalPausesCvar;
ConVar g_MaxPauseTimeCvar;
ConVar g_MessagePrefixCvar;
ConVar g_PauseOnVetoCvar;
Expand Down Expand Up @@ -134,6 +134,9 @@ ArrayList g_CvarNames = null;
ArrayList g_CvarValues = null;
bool g_InScrimMode = false;
bool g_HasKnifeRoundStarted = false;
bool g_IsChangingPauseState = false; // Used to prevent mp_pause_match and mp_unpause_match from being called directly.
float g_FixedPauseUnpauseTimerTime = 0.0; // on round start, this creates the unpause hook if the game has fixed-duration pause.
Get5Team g_PausingTeam = Get5Team_None; // The team that last called for a pause.

/** Other state **/
Get5State g_GameState = Get5State_None;
Expand Down Expand Up @@ -185,12 +188,10 @@ int g_TeamStartingSide[MATCHTEAM_COUNT];
bool g_TeamReadyForUnpause[MATCHTEAM_COUNT];
bool g_TeamGivenStopCommand[MATCHTEAM_COUNT];
Get5PauseType g_PauseType = Get5PauseType_None;
int g_TeamPauseTimeUsed[MATCHTEAM_COUNT];
int g_TeamPausesUsed[MATCHTEAM_COUNT];
int g_TeamTechPausesUsed[MATCHTEAM_COUNT];
int g_TechPausedTimeOverride[MATCHTEAM_COUNT];
int g_TeamGivenTechPauseCommand[MATCHTEAM_COUNT];
int g_PauseTimeUsed = 0;
int g_TacticalPauseTimeUsed[MATCHTEAM_COUNT];
int g_TacticalPausesUsed[MATCHTEAM_COUNT];
int g_TechnicalPausesUsed[MATCHTEAM_COUNT];
int g_TechnicalPauseTimeUsed[MATCHTEAM_COUNT];
int g_ReadyTimeWaitingUsed = 0;
char g_DefaultTeamColors[][] = {
TEAM1_COLOR,
Expand Down Expand Up @@ -258,6 +259,7 @@ Handle g_OnRoundStatsUpdated = INVALID_HANDLE;
Handle g_OnSeriesInit = INVALID_HANDLE;
Handle g_OnSeriesResult = INVALID_HANDLE;
Handle g_OnSidePicked = INVALID_HANDLE;
Handle g_FixedPauseTimer = INVALID_HANDLE;

#include "get5/util.sp"
#include "get5/version.sp"
Expand Down Expand Up @@ -304,10 +306,10 @@ public void OnPluginStart() {
/** ConVars **/
g_AllowTechPauseCvar = CreateConVar("get5_allow_technical_pause", "1",
"Whether or not technical pauses are allowed");
g_MaxTechPauseTime = CreateConVar(
g_MaxTechPauseDurationCvar = CreateConVar(
"get5_tech_pause_time", "0",
"Number of seconds before anyone can call unpause on a technical timeout, 0=unlimited");
g_MaxTechPauseCvar =
g_MaxTechPausesCvar =
CreateConVar("get5_max_tech_pauses", "0",
"Number of technical pauses a team is allowed to have, 0=unlimited");
g_AutoLoadConfigCvar =
Expand Down Expand Up @@ -358,7 +360,7 @@ public void OnPluginStart() {
g_MaxBackupAgeCvar =
CreateConVar("get5_max_backup_age", "160000",
"Number of seconds before a backup file is automatically deleted, 0 to disable");
g_MaxPausesCvar =
g_MaxTacticalPausesCvar =
CreateConVar("get5_max_pauses", "0", "Maximum number of pauses a team can use, 0=unlimited");
g_MaxPauseTimeCvar =
CreateConVar("get5_max_pause_time", "300",
Expand Down Expand Up @@ -516,6 +518,8 @@ public void OnPluginStart() {
AddCommandListener(Command_Coach, "coach");
AddCommandListener(Command_JoinTeam, "jointeam");
AddCommandListener(Command_JoinGame, "joingame");
AddCommandListener(Command_PauseOrUnpauseMatch, "mp_pause_match");
AddCommandListener(Command_PauseOrUnpauseMatch, "mp_unpause_match");

/** Setup data structures **/
g_MapPoolList = new ArrayList(PLATFORM_MAX_PATH);
Expand Down Expand Up @@ -765,12 +769,11 @@ public void OnMapStart() {
LOOP_TEAMS(team) {
g_TeamGivenStopCommand[team] = false;
g_TeamReadyForUnpause[team] = false;
g_TeamPauseTimeUsed[team] = 0;
g_TeamPausesUsed[team] = 0;
g_TacticalPauseTimeUsed[team] = 0;
g_TacticalPausesUsed[team] = 0;
g_ReadyTimeWaitingUsed = 0;
g_TeamTechPausesUsed[team] = 0;
g_TechPausedTimeOverride[team] = 0;
g_TeamGivenTechPauseCommand[team] = false;
g_TechnicalPausesUsed[team] = 0;
g_TechnicalPauseTimeUsed[team] = 0;
}

if (g_WaitingForRoundBackup) {
Expand Down Expand Up @@ -1301,6 +1304,12 @@ public Action Event_RoundPreStart(Event event, const char[] name, bool dontBroad

public Action Event_FreezeEnd(Event event, const char[] name, bool dontBroadcast) {
LogDebug("Event_FreezeEnd");
// If there's a changelevel command during a pause, we need to ensure that this
// handle gets reset. FreezeEnd is called immediately as the map loads, and the timer is always set with
// TIMER_FLAG_NO_MAPCHANGE, so its callback will not fire.
g_FixedPauseTimer = INVALID_HANDLE;
g_PausingTeam = Get5Team_None;

// We always want this to be correct, regardless of game state.
g_RoundStartedTime = GetEngineTime();
if (g_GameState == Get5State_Live) {
Expand Down Expand Up @@ -1346,6 +1355,10 @@ public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcas
g_BombPlantedTime = 0.0;
g_BombSiteLastPlanted = Get5BombSite_Unknown;

// If a pause was pending with a fixed timer, begin counting down as the round starts.
// This function does nothing if no pending timer value was set.
StartFixedPauseUnpauseEventTimer();

if (g_GameState != Get5State_Live) {
g_RoundNumber = -1; // Round number always -1 if not yet live.
return;
Expand Down Expand Up @@ -1494,13 +1507,13 @@ public void SwapSides() {

if (g_ResetPausesEachHalfCvar.BoolValue) {
LOOP_TEAMS(team) {
g_TeamPauseTimeUsed[team] = 0;
g_TeamPausesUsed[team] = 0;
g_TacticalPauseTimeUsed[team] = 0;
g_TacticalPausesUsed[team] = 0;
}
// Reset the built-in timeout counter of the game
if (g_MaxPausesCvar.IntValue > 0) {
GameRules_SetProp("m_nTerroristTimeOuts", g_MaxPausesCvar.IntValue);
GameRules_SetProp("m_nCTTimeOuts", g_MaxPausesCvar.IntValue);
if (g_MaxTacticalPausesCvar.IntValue > 0) {
GameRules_SetProp("m_nTerroristTimeOuts", g_MaxTacticalPausesCvar.IntValue);
GameRules_SetProp("m_nCTTimeOuts", g_MaxTacticalPausesCvar.IntValue);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions scripting/get5/backups.sp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public void RestoreGet5Backup() {
EndWarmup();
EndWarmup();
ServerCommand("mp_restartgame 5");
PauseGame(Get5Team_None, Get5PauseType_Backup, 1);
PauseGame(Get5Team_None, Get5PauseType_Backup);
if (g_CoachingEnabledCvar.BoolValue) {
CreateTimer(6.0, Timer_SwapCoaches);
}
Expand All @@ -377,7 +377,7 @@ public Action Timer_SwapCoaches(Handle timer) {
}

public Action Time_StartRestore(Handle timer) {
PauseGame(Get5Team_None, Get5PauseType_Backup, 1);
PauseGame(Get5Team_None, Get5PauseType_Backup);

char tempValveBackup[PLATFORM_MAX_PATH];
GetTempFilePath(tempValveBackup, sizeof(tempValveBackup), TEMP_VALVE_BACKUP_PATTERN);
Expand Down
13 changes: 8 additions & 5 deletions scripting/get5/debug.sp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ static void AddGlobalStateInfo(File f) {
f.WriteLine("g_SavedValveBackup = %d", g_SavedValveBackup);
f.WriteLine("g_DoingBackupRestoreNow = %d", g_DoingBackupRestoreNow);
f.WriteLine("g_ReadyTimeWaitingUsed = %d", g_ReadyTimeWaitingUsed);
f.WriteLine("g_PausingTeam = %d", g_PausingTeam);
f.WriteLine("g_PauseType = %d", g_PauseType);

LOOP_TEAMS(team) {
GetTeamString(team, buffer, sizeof(buffer));
Expand All @@ -134,11 +136,10 @@ static void AddGlobalStateInfo(File f) {
f.WriteLine("g_TeamSeriesScores = %d", g_TeamSeriesScores[team]);
f.WriteLine("g_TeamReadyOverride = %d", g_TeamReadyOverride[team]);
f.WriteLine("g_TeamStartingSide = %d", g_TeamStartingSide[team]);
f.WriteLine("g_TeamPauseTimeUsed = %d", g_TeamPauseTimeUsed[team]);
f.WriteLine("g_TechPausedTimeOverride = %d", g_TechPausedTimeOverride[team]);
f.WriteLine("g_TeamPausesUsed = %d", g_TeamPausesUsed[team]);
f.WriteLine("g_TeamTechPausesUsed = %d", g_TeamTechPausesUsed[team]);
f.WriteLine("g_TeamGivenTechPauseCommand = %d", g_TeamGivenTechPauseCommand[team]);
f.WriteLine("g_TacticalPauseTimeUsed = %d", g_TacticalPauseTimeUsed[team]);
f.WriteLine("g_TechnicalPauseTimeUsed = %d", g_TechnicalPauseTimeUsed[team]);
f.WriteLine("g_TacticalPausesUsed = %d", g_TacticalPausesUsed[team]);
f.WriteLine("g_TechnicalPausesUsed = %d", g_TechnicalPausesUsed[team]);
f.WriteLine("g_TeamGivenStopCommand = %d", g_TeamGivenStopCommand[team]);
WriteArrayList(f, "g_TeamCoaches", g_TeamCoaches[team]);
}
Expand All @@ -153,8 +154,10 @@ static void AddInterestingCvars(File f) {
WriteCvarString(f, "get5_fixed_pause_time");
WriteCvarString(f, "get5_kick_when_no_match_loaded");
WriteCvarString(f, "get5_live_cfg");
WriteCvarString(f, "get5_tech_pause_time");
WriteCvarString(f, "get5_max_pause_time");
WriteCvarString(f, "get5_max_pauses");
WriteCvarString(f, "get5_max_tech_pauses");
WriteCvarString(f, "get5_pause_on_veto");
WriteCvarString(f, "get5_pausing_enabled");
WriteCvarString(f, "get5_print_damage");
Expand Down
10 changes: 5 additions & 5 deletions scripting/get5/goinglive.sp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public Action MatchLive(Handle timer) {

// If there is a set amount of timeouts available update the built-in convar and game rule
// properties to show the correct amount of timeouts remaining in gsi and in-game
if (g_MaxPausesCvar.IntValue > 0) {
ServerCommand("mp_team_timeout_max %d", g_MaxPausesCvar.IntValue);
GameRules_SetProp("m_nTerroristTimeOuts", g_MaxPausesCvar.IntValue);
GameRules_SetProp("m_nCTTimeOuts", g_MaxPausesCvar.IntValue);
if (g_MaxTacticalPausesCvar.IntValue > 0) {
ServerCommand("mp_team_timeout_max %d", g_MaxTacticalPausesCvar.IntValue);
GameRules_SetProp("m_nTerroristTimeOuts", g_MaxTacticalPausesCvar.IntValue);
GameRules_SetProp("m_nCTTimeOuts", g_MaxTacticalPausesCvar.IntValue);
}

// We force the match end-delay to extend for the duration of the GOTV broadcast here.
Expand All @@ -76,4 +76,4 @@ public void SetMatchRestartDelay() {
ConVar mp_match_restart_delay = FindConVar("mp_match_restart_delay");
int delay = GetTvDelay() + MATCH_END_DELAY_AFTER_TV + 5;
SetConVarInt(mp_match_restart_delay, delay);
}
}
8 changes: 2 additions & 6 deletions scripting/get5/mapveto.sp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ public void CreateVeto() {
g_VetoCaptains[Get5Team_2] = GetTeamCaptain(Get5Team_2);
ResetReadyStatus();
if (g_PauseOnVetoCvar.BoolValue) {
if (g_PausingEnabledCvar.BoolValue) {
PauseGame(Get5Team_None, Get5PauseType_Admin, 1);
} else {
ServerCommand("mp_pause_match");
}
PauseGame(Get5Team_None, Get5PauseType_Admin);
}
CreateTimer(1.0, Timer_VetoCountdown, _, TIMER_REPEAT);
}
Expand Down Expand Up @@ -50,7 +46,7 @@ public void VetoFinished() {
Get5_MessageToAll("%t", "MapDecidedInfoMessage");

if (IsPaused()) {
ServerCommand("mp_unpause_match");
UnpauseGame(Get5Team_None);
}

// Use total series score as starting point, to not print skipped maps
Expand Down
9 changes: 4 additions & 5 deletions scripting/get5/matchconfig.sp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ stock bool LoadMatchConfig(const char[] config, bool restoreBackup = false) {
// During restore we want to keep our
// current pauses used.
if (!restoreBackup) {
g_TeamPauseTimeUsed[team] = 0;
g_TeamPausesUsed[team] = 0;
g_TeamTechPausesUsed[team] = 0;
g_TacticalPauseTimeUsed[team] = 0;
g_TacticalPausesUsed[team] = 0;
g_TechnicalPausesUsed[team] = 0;
}
g_TechPausedTimeOverride[team] = 0;
g_TeamGivenTechPauseCommand[team] = false;
g_TechnicalPauseTimeUsed[team] = 0;
ClearArray(GetTeamCoaches(team));
ClearArray(GetTeamAuths(team));
}
Expand Down
Loading

0 comments on commit 4595e3e

Please sign in to comment.