Skip to content

Commit b4bc3c3

Browse files
committed
Consider value of mp_match_restart_delay when executing match end actions
1 parent 95d47a2 commit b4bc3c3

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

backend/src/match.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -883,18 +883,20 @@ const onMatchEnd = async (match: Match) => {
883883

884884
await say(match, 'MATCH IS FINISHED');
885885

886-
// tell players what will happen next
887886
const seconds = Math.round(Settings.MATCH_END_ACTION_DELAY / 1000);
887+
const delayInSeconds = Math.max(seconds, await getMapEndDelayInSeconds(match, seconds));
888+
889+
// tell players what will happen next
888890
switch (match.data.matchEndAction) {
889891
case 'KICK_ALL':
890-
await say(match, `IN ${seconds} SECONDS ALL PLAYERS GET KICKED`);
892+
await say(match, `IN ${delayInSeconds} SECONDS ALL PLAYERS GET KICKED`);
891893
break;
892894
case 'QUIT_SERVER':
893-
await say(match, `IN ${seconds} SECONDS THE SERVER SHUTS DOWN`);
895+
await say(match, `IN ${delayInSeconds} SECONDS THE SERVER SHUTS DOWN`);
894896
break;
895897
}
896898

897-
await sleep(Settings.MATCH_END_ACTION_DELAY);
899+
await sleep(delayInSeconds * 1000);
898900

899901
switch (match.data.matchEndAction) {
900902
case 'KICK_ALL':
@@ -972,6 +974,25 @@ const loopMatch = async (match: Match) => {
972974
});
973975
};
974976

977+
/**
978+
* Returns the number of seconds it should delay actions after a map ends (before changelevel or match end actions)
979+
* @param match Match
980+
* @param fallback
981+
*/
982+
export const getMapEndDelayInSeconds = async (match: Match, fallback: number): Promise<number> => {
983+
let delayInSeconds: number | undefined;
984+
const cVar = await getConfigVar(match, 'mp_match_restart_delay');
985+
if (/^\d+$/.test(cVar)) {
986+
delayInSeconds = parseInt(cVar);
987+
} else {
988+
match.log('Config var mp_match_restart_delay cannot be parsed to number: ' + cVar);
989+
}
990+
if (!delayInSeconds || isNaN(delayInSeconds)) {
991+
delayInSeconds = fallback;
992+
}
993+
return delayInSeconds;
994+
};
995+
975996
export const update = async (match: Match, dto: IMatchUpdateDto) => {
976997
if (dto.state) {
977998
match.data.state = dto.state;

backend/src/matchMap.ts

+4-14
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,10 @@ export const onRoundEnd = async (
170170
export const loadMap = async (match: Match.Match, matchMap: IMatchMap, useDefaultDelay = false) => {
171171
const internalMapName = parseMapParts(matchMap.name).internal;
172172

173-
let delayInSeconds: number | undefined;
174-
if (useDefaultDelay || match.data.currentMap === 0) {
175-
delayInSeconds = 15;
176-
} else {
177-
const cVar = await Match.getConfigVar(match, 'mp_match_restart_delay');
178-
if (/^\d+$/.test(cVar)) {
179-
delayInSeconds = parseInt(cVar);
180-
} else {
181-
match.log('Config var mp_match_restart_delay cannot be parsed to number: ' + cVar);
182-
}
183-
}
184-
if (!delayInSeconds || isNaN(delayInSeconds) || delayInSeconds < 15) {
185-
delayInSeconds = 15;
186-
}
173+
const delayInSeconds =
174+
useDefaultDelay || match.data.currentMap === 0
175+
? 15
176+
: Math.max(15, await Match.getMapEndDelayInSeconds(match, 15));
187177

188178
await Match.say(
189179
match,

0 commit comments

Comments
 (0)