Skip to content

Commit

Permalink
Clear player list after match in loop mode
Browse files Browse the repository at this point in the history
  • Loading branch information
JensForstmann committed Nov 6, 2023
1 parent 30f1d9f commit 679ef08
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions backend/src/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ const onPlayerLogLine = async (
if (match.data.mode === 'LOOP') {
const players = await GameServer.getPlayers(match);
if (players.length === 0) {
await restartElection(match);
await loopMatch(match);
}
}
return;
Expand Down Expand Up @@ -825,7 +825,20 @@ const onMatchEnd = async (match: Match) => {
const wonMapsTeamA = getTeamWins(match, 'TEAM_A');
const wonMapsTeamB = getTeamWins(match, 'TEAM_B');
Events.onMatchEnd(match, wonMapsTeamA, wonMapsTeamB);

// tell players what will happen next
const seconds = Math.round(Settings.MATCH_END_ACTION_DELAY / 1000);
switch (match.data.matchEndAction) {
case 'KICK_ALL':
say(match, `IN ${seconds} SECONDS ALL PLAYERS GET KICKED`);
break;
case 'QUIT_SERVER':
say(match, `IN ${seconds} SECONDS THE SERVER SHUTS DOWN`);
break;
}

await sleep(Settings.MATCH_END_ACTION_DELAY);

switch (match.data.matchEndAction) {
case 'KICK_ALL':
await GameServer.kickAll(match);
Expand All @@ -836,7 +849,7 @@ const onMatchEnd = async (match: Match) => {
}

if (match.data.mode === 'LOOP') {
await restartElection(match);
await loopMatch(match);
} else {
await MatchService.remove(match.data.id); // this will call Match.stop()
}
Expand Down Expand Up @@ -888,6 +901,20 @@ const restartElection = async (match: Match) => {
await Election.auto(match);
};

const loopMatch = async (match: Match) => {
match.log('Loop mode is set, restart match');
await restartElection(match);
sleep(1000)
.then(() => {
// delay, because there might still be events left
match.log('Clear player list');
match.data.players = [];
})
.catch(() => {
// shouldn't throw
});
};

export const update = async (match: Match, dto: IMatchUpdateDto) => {
if (dto.state) {
match.data.state = dto.state;
Expand Down

0 comments on commit 679ef08

Please sign in to comment.