Skip to content

Commit

Permalink
Move logging and chat messages for map end event.
Browse files Browse the repository at this point in the history
  • Loading branch information
JensForstmann committed Apr 4, 2024
1 parent 740acdd commit 1e47986
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
23 changes: 6 additions & 17 deletions backend/src/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ const onLogLine = async (match: Match, line: string) => {

// Game Over: competitive de_overpass score 13:0 after 3 min
// Game Over: scrimcomp2v2 de_overpass score 9:0 after 3 min
// Game Over: competitive mg_active fy_pool_day score 0:13 after 4 min
const mapEndPattern = /Game Over: .*? score (\d+):(\d+)/;
const mapEndMatch = line.match(new RegExp(dateTimePattern.source + mapEndPattern.source));
if (mapEndMatch) {
Expand Down Expand Up @@ -804,27 +805,13 @@ const onMapEnd = async (match: Match) => {

const currentMatchMap = getCurrentMatchMap(match);
if (currentMatchMap) {
const mapNumber = match.data.currentMap + 1;
await MatchMap.onMapEnd(match, currentMatchMap);

const winnerTeamAB = MatchMap.getWinner(currentMatchMap);
if (!winnerTeamAB) {
await say(match, `${mapNumber}. MAP FINISHED (DRAW)`);
match.log(`${mapNumber}. map finished (draw)`);
} else {
const winnerTeam = getTeamByAB(match, winnerTeamAB);
await say(
match,
`${mapNumber}. MAP FINISHED (WINNER: ${escapeRconString(winnerTeam.name)})`
);
match.log(`${mapNumber}. map finished (winner: ${winnerTeam.name})`);
}

if (isMatchEnd(match)) {
match.log('Match finished');
await onMatchEnd(match);
} else {
match.data.currentMap++;
MatchService.scheduleSave(match);
const nextMap = getCurrentMatchMap(match);
if (nextMap) {
await MatchMap.loadMap(match, nextMap);
Expand Down Expand Up @@ -878,14 +865,16 @@ const onMatchEnd = async (match: Match) => {
const wonMapsTeamB = getTeamWins(match, 'TEAM_B');
Events.onMatchEnd(match, wonMapsTeamA, wonMapsTeamB);

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

// 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`);
await say(match, `IN ${seconds} SECONDS ALL PLAYERS GET KICKED`);
break;
case 'QUIT_SERVER':
say(match, `IN ${seconds} SECONDS THE SERVER SHUTS DOWN`);
await say(match, `IN ${seconds} SECONDS THE SERVER SHUTS DOWN`);
break;
}

Expand Down
26 changes: 20 additions & 6 deletions backend/src/matchMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const loadMap = async (match: Match.Match, matchMap: IMatchMap) => {
match.log(`Change map to ${matchMap.name} (in 15 seconds)`);
match.data.state = 'MATCH_MAP';
matchMap.state = 'MAP_CHANGE';
MatchService.scheduleSave(match);
await sleep(15000);

await Match.setTeamNames(match);
Expand Down Expand Up @@ -261,12 +262,25 @@ const refreshOvertimeAndMaxRoundsSettings = async (match: Match.Match, matchMap:
};

export const onMapEnd = async (match: Match.Match, matchMap: IMatchMap) => {
if (matchMap.state === 'IN_PROGRESS' || matchMap.state === 'PAUSED') {
matchMap.state = 'FINISHED';
MatchService.scheduleSave(match);
await Match.say(match, 'MAP FINISHED');
Events.onMapEnd(match, matchMap);
match.log('Map finished');
if (matchMap.state !== 'IN_PROGRESS' && matchMap.state !== 'PAUSED') {
return;
}

matchMap.state = 'FINISHED';
MatchService.scheduleSave(match);
Events.onMapEnd(match, matchMap);
const mapNumber = match.data.currentMap + 1;
const winnerTeamAB = getWinner(matchMap);
if (!winnerTeamAB) {
await Match.say(match, `${mapNumber}. MAP FINISHED (DRAW)`);
match.log(`${mapNumber}. map finished (draw)`);
} else {
const winnerTeam = Match.getTeamByAB(match, winnerTeamAB);
await Match.say(
match,
`${mapNumber}. MAP FINISHED (WINNER: ${escapeRconString(winnerTeam.name)})`
);
match.log(`${mapNumber}. map finished (winner: ${winnerTeam.name})`);
}
};

Expand Down

0 comments on commit 1e47986

Please sign in to comment.