Skip to content

Commit

Permalink
Fix incorrect warnings about being in the wrong team
Browse files Browse the repository at this point in the history
  • Loading branch information
JensForstmann committed Nov 2, 2023
1 parent 883bde1 commit b8196ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions backend/src/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ export interface Match {
periodicTimerId?: NodeJS.Timeout;
logBuffer: string[];
log: (msg: string) => void;
warnAboutWrongTeam: boolean;
}

export const createFromData = async (data: IMatch) => {
const match: Match = {
data: data,
logBuffer: [],
log: () => {},
warnAboutWrongTeam: true,
};
match.data = addChangeListener(data, createOnDataChangeHandler(match));
match.log = createLogger(match);
Expand Down Expand Up @@ -468,6 +470,16 @@ const onLogLine = async (match: Match, line: string) => {
}
return;
}

// World triggered "Match_Start" on "de_dust2"
const matchStartPattern = /World triggered "Match_Start" on .*/;
const matchStartMatch = line.match(
new RegExp(dateTimePattern.source + matchStartPattern.source)
);
if (matchStartMatch) {
match.warnAboutWrongTeam = true;
return;
}
} catch (err) {
match.log('Error in onLogLine' + err);
}
Expand Down Expand Up @@ -682,6 +694,9 @@ const sayWrongTeamOrSide = async (
currentSite: 'CT' | 'TERRORIST',
currentTeamAB: TTeamAB
) => {
if (!match.warnAboutWrongTeam) {
return;
}
const currentTeam = getTeamByAB(match, currentTeamAB);
const otherTeam = getTeamByAB(match, getOtherTeamAB(currentTeamAB));
await say(
Expand Down
1 change: 1 addition & 0 deletions backend/src/matchMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ const onSwitchCommand: commands.CommandHandler = async (e) => {
await Match.say(match, `${escapeRconString(team.name)} WANTS TO SWITCH SIDES`);
match.log(`${teamAB} (${team.name} - ${player.name}) wants to switch sides`);
await Match.execRcon(match, 'mp_swapteams');
match.warnAboutWrongTeam = false; // temporarily disable warning about wrong team, will be set to true again after match start
matchMap.startAsCtTeam = getOtherTeamAB(matchMap.startAsCtTeam);
MatchService.scheduleSave(match);
await startMatch(match, matchMap);
Expand Down

0 comments on commit b8196ea

Please sign in to comment.