Skip to content

Commit

Permalink
Consider value of mp_match_restart_delay when executing match end act…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
JensForstmann committed May 2, 2024
1 parent 95d47a2 commit b4bc3c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
29 changes: 25 additions & 4 deletions backend/src/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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<number> => {
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;
Expand Down
18 changes: 4 additions & 14 deletions backend/src/matchMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b4bc3c3

Please sign in to comment.