diff --git a/backend/src/match.ts b/backend/src/match.ts index 8852d55..56ce571 100644 --- a/backend/src/match.ts +++ b/backend/src/match.ts @@ -883,18 +883,20 @@ const onMatchEnd = async (match: Match) => { await say(match, 'MATCH IS FINISHED'); - // tell players what will happen next const seconds = Math.round(Settings.MATCH_END_ACTION_DELAY / 1000); + const delayInSeconds = Math.max(seconds, await getMapEndDelayInSeconds(match, seconds)); + + // tell players what will happen next switch (match.data.matchEndAction) { case 'KICK_ALL': - await say(match, `IN ${seconds} SECONDS ALL PLAYERS GET KICKED`); + await say(match, `IN ${delayInSeconds} SECONDS ALL PLAYERS GET KICKED`); break; case 'QUIT_SERVER': - await say(match, `IN ${seconds} SECONDS THE SERVER SHUTS DOWN`); + await say(match, `IN ${delayInSeconds} SECONDS THE SERVER SHUTS DOWN`); break; } - await sleep(Settings.MATCH_END_ACTION_DELAY); + await sleep(delayInSeconds * 1000); switch (match.data.matchEndAction) { case 'KICK_ALL': @@ -972,6 +974,25 @@ const loopMatch = async (match: Match) => { }); }; +/** + * Returns the number of seconds it should delay actions after a map ends (before changelevel or match end actions) + * @param match Match + * @param fallback + */ +export const getMapEndDelayInSeconds = async (match: Match, fallback: number): Promise => { + let delayInSeconds: number | undefined; + const cVar = await getConfigVar(match, 'mp_match_restart_delay'); + if (/^\d+$/.test(cVar)) { + delayInSeconds = parseInt(cVar); + } else { + match.log('Config var mp_match_restart_delay cannot be parsed to number: ' + cVar); + } + if (!delayInSeconds || isNaN(delayInSeconds)) { + delayInSeconds = fallback; + } + return delayInSeconds; +}; + export const update = async (match: Match, dto: IMatchUpdateDto) => { if (dto.state) { match.data.state = dto.state; diff --git a/backend/src/matchMap.ts b/backend/src/matchMap.ts index 17f89ee..ea37df0 100644 --- a/backend/src/matchMap.ts +++ b/backend/src/matchMap.ts @@ -170,20 +170,10 @@ export const onRoundEnd = async ( export const loadMap = async (match: Match.Match, matchMap: IMatchMap, useDefaultDelay = false) => { const internalMapName = parseMapParts(matchMap.name).internal; - let delayInSeconds: number | undefined; - if (useDefaultDelay || match.data.currentMap === 0) { - delayInSeconds = 15; - } else { - const cVar = await Match.getConfigVar(match, 'mp_match_restart_delay'); - if (/^\d+$/.test(cVar)) { - delayInSeconds = parseInt(cVar); - } else { - match.log('Config var mp_match_restart_delay cannot be parsed to number: ' + cVar); - } - } - if (!delayInSeconds || isNaN(delayInSeconds) || delayInSeconds < 15) { - delayInSeconds = 15; - } + const delayInSeconds = + useDefaultDelay || match.data.currentMap === 0 + ? 15 + : Math.max(15, await Match.getMapEndDelayInSeconds(match, 15)); await Match.say( match,