diff --git a/backend/src/commands.ts b/backend/src/commands.ts index e89ff33..31e2a41 100644 --- a/backend/src/commands.ts +++ b/backend/src/commands.ts @@ -1,5 +1,7 @@ import { IPlayer, TTeamString } from '../../common'; +import { colors } from './gameServer'; import { Match } from './match'; +import { Settings } from './settings'; const Commands = [ 'BAN', @@ -80,3 +82,21 @@ export const onCommand = async (e: CommandEvent) => { const handlers = commandHandlers.get(e.command) ?? []; await Promise.all(handlers.map((h) => h(e))); }; + +export const formatIngameCommand = (command: string, parameters?: string) => { + return ( + colors.lightOrange + + Settings.COMMAND_PREFIXES[0] + + command + + (parameters ? ' ' + parameters : '') + + colors.white + ); +}; + +export const formatFirstIngameCommand = (command: TCommand, parameters?: string) => { + const firstUserCommand = getUserCommandsByInternalCommand(command)[0]; + if (!firstUserCommand) { + return ''; + } + return formatIngameCommand(firstUserCommand, parameters); +}; diff --git a/backend/src/election.ts b/backend/src/election.ts index 5e3dfb7..78e5478 100644 --- a/backend/src/election.ts +++ b/backend/src/election.ts @@ -11,8 +11,8 @@ import { TWho, } from '../../common'; import * as commands from './commands'; -import { getUserCommandsByInternalCommand } from './commands'; import * as Events from './events'; +import { colors } from './gameServer'; import * as Match from './match'; import * as MatchMap from './matchMap'; import * as MatchService from './matchService'; @@ -120,11 +120,11 @@ const getAvailableCommands = (match: Match.Match, currentElectionStep: IElection }; const sayAvailableCommands = async (match: Match.Match, currentElectionStep: IElectionStep) => { - const commands = getAvailableCommands(match, currentElectionStep); - if (commands.length > 0) { + const cmds = getAvailableCommands(match, currentElectionStep); + if (cmds.length > 0) { await Match.say( match, - `COMMANDS: ${commands.map((c) => Settings.COMMAND_PREFIXES[0] + c).join(', ')}` + `COMMANDS: ${cmds.map((cmd) => commands.formatIngameCommand(cmd)).join(', ')}` ); } }; @@ -161,9 +161,7 @@ const sayWhatIsUp = async (match: Match.Match) => { if (currentElectionStep.map.mode === 'AGREE') { await Match.say( match, - `BOTH TEAMS MUST ${Settings.COMMAND_PREFIXES[0]}${ - getUserCommandsByInternalCommand('AGREE')[0] - } ON THE SAME MAP` + `BOTH TEAMS MUST ${commands.formatFirstIngameCommand('AGREE')} ON THE SAME MAP` ); if (match.data.election.currentAgree.teamA) await Match.say( @@ -185,16 +183,14 @@ const sayWhatIsUp = async (match: Match.Match) => { if (validTeam) await Match.say( match, - `TEAM ${escapeRconString(Match.getTeamByAB(match, validTeam).name)} MUST ${ - Settings.COMMAND_PREFIXES[0] - }${getUserCommandsByInternalCommand('BAN')[0]} A MAP` + `TEAM ${escapeRconString( + Match.getTeamByAB(match, validTeam).name + )} MUST ${commands.formatFirstIngameCommand('BAN')} A MAP` ); if (!validTeam) await Match.say( match, - `BOTH TEAMS CAN START TO ${Settings.COMMAND_PREFIXES[0]}${ - getUserCommandsByInternalCommand('BAN')[0] - } A MAP` + `BOTH TEAMS CAN START TO ${commands.formatFirstIngameCommand('BAN')} A MAP` ); await sayAvailableMaps(match); } else if (currentElectionStep.map.mode === 'PICK') { @@ -202,16 +198,14 @@ const sayWhatIsUp = async (match: Match.Match) => { if (validTeam) await Match.say( match, - `TEAM ${escapeRconString(Match.getTeamByAB(match, validTeam).name)} MUST ${ - Settings.COMMAND_PREFIXES[0] - }${getUserCommandsByInternalCommand('PICK')[0]} A MAP` + `TEAM ${escapeRconString( + Match.getTeamByAB(match, validTeam).name + )} MUST ${commands.formatFirstIngameCommand('PICK')} A MAP` ); if (!validTeam) await Match.say( match, - `BOTH TEAMS CAN START TO ${Settings.COMMAND_PREFIXES[0]}${ - getUserCommandsByInternalCommand('PICK')[0] - } A MAP` + `BOTH TEAMS CAN START TO ${commands.formatFirstIngameCommand('PICK')} A MAP` ); await sayAvailableMaps(match); } @@ -223,27 +217,32 @@ const sayWhatIsUp = async (match: Match.Match) => { match, `TEAM ${escapeRconString( Match.getTeamByAB(match, validTeam).name - )} MUST CHOOSE A SIDE FOR MAP ${match.data.election.currentStepMap} (${ - Settings.COMMAND_PREFIXES[0] - }${getUserCommandsByInternalCommand('CT')[0]}, ${Settings.COMMAND_PREFIXES[0]}${ - getUserCommandsByInternalCommand('T')[0] - })` + )} MUST CHOOSE A SIDE FOR MAP ${ + match.data.election.currentStepMap + } (${commands.formatFirstIngameCommand( + 'CT' + )}, ${commands.formatFirstIngameCommand('T')})` ); if (!validTeam) await Match.say( match, `BOTH TEAMS CAN START TO CHOOSE A SIDE FOR MAP ${ match.data.election.currentStepMap - } (${Settings.COMMAND_PREFIXES[0]}${ - getUserCommandsByInternalCommand('CT')[0] - }, ${Settings.COMMAND_PREFIXES[0]}${getUserCommandsByInternalCommand('T')[0]})` + } (${commands.formatFirstIngameCommand( + 'CT' + )}, ${commands.formatFirstIngameCommand('T')})` ); } } }; const sayAvailableMaps = async (match: Match.Match) => { - await Match.say(match, `AVAILABLE MAPS: ${match.data.election.remainingMaps.join(', ')}`); + await Match.say( + match, + `AVAILABLE MAPS: ${match.data.election.remainingMaps + .map((map) => colors.purple + map + colors.white) + .join(', ')}` + ); }; export const registerCommandHandlers = () => { @@ -351,12 +350,7 @@ const onAgreeCommand: commands.CommandHandler = async (e) => { await next(match); } else { await Match.say(match, `MAP ${map} SUGGESTED BY ${escapeRconString(team.name)}`); - await Match.say( - match, - `AGREE WITH ${Settings.COMMAND_PREFIXES[0]}${ - getUserCommandsByInternalCommand('AGREE')[0] - }` - ); + await Match.say(match, `AGREE WITH ${commands.formatFirstIngameCommand('AGREE')}`); match.log(`${teamAB} (${team.name} - ${player.name}) suggests map ${map}`); } MatchService.scheduleSave(match); @@ -550,6 +544,7 @@ const onRestartCommand: commands.CommandHandler = async (e) => { match.data.election = create(match.data.mapPool, match.data.electionSteps); match.data.matchMaps = []; await Match.say(match, `ELECTION PROCESS RESTARTED`); + await sayWhatIsUp(match); } catch (err) { match.log(`Error restarting the election process: ${err}`); await Match.say(match, `ERROR RESTARTING THE ELECTION`); @@ -562,9 +557,7 @@ const onRestartCommand: commands.CommandHandler = async (e) => { await Match.say( match, - `TYPE ${Settings.COMMAND_PREFIXES[0]}${ - getUserCommandsByInternalCommand('RESTART')[0] - } TO CONFIRM AND RESTART` + `TYPE ${commands.formatFirstIngameCommand('RESTART')} TO CONFIRM AND RESTART` ); } MatchService.scheduleSave(match); diff --git a/backend/src/match.ts b/backend/src/match.ts index 0dbfd6f..9367713 100644 --- a/backend/src/match.ts +++ b/backend/src/match.ts @@ -681,13 +681,13 @@ export const sayNotAssigned = async (match: Match, player: IPlayer) => { await say(match, `PLAYER ${escapeRconString(player.name)} NOT ASSIGNED!`); await say( match, - `TYPE "${Settings.COMMAND_PREFIXES[0]}team a" TO JOIN ${escapeRconString( + `TYPE ${commands.formatFirstIngameCommand('TEAM', 'a')} TO JOIN ${escapeRconString( match.data.teamA.name )}` ); await say( match, - `TYPE "${Settings.COMMAND_PREFIXES[0]}team b" TO JOIN ${escapeRconString( + `TYPE ${commands.formatFirstIngameCommand('TEAM', 'b')} TO JOIN ${escapeRconString( match.data.teamB.name )}` ); @@ -712,9 +712,10 @@ const sayWrongTeamOrSide = async ( ); await say( match, - `CHECK SCOREBOARD AND CHANGE TEAM OR TYPE "${Settings.COMMAND_PREFIXES[0]}team ${ + `CHECK SCOREBOARD AND CHANGE TEAM OR TYPE ${commands.formatFirstIngameCommand( + 'TEAM', currentTeamAB === 'TEAM_A' ? 'b' : 'a' - }" TO CHANGE REGISTRATION` + )} TO CHANGE REGISTRATION` ); }; diff --git a/backend/src/matchMap.ts b/backend/src/matchMap.ts index 9a2dc79..87fbdc9 100644 --- a/backend/src/matchMap.ts +++ b/backend/src/matchMap.ts @@ -113,11 +113,11 @@ const getAvailableCommands = (state: TMatchMapSate): string[] => { }; const sayAvailableCommands = async (match: Match.Match, matchMap: IMatchMap) => { - const commands = getAvailableCommands(matchMap.state); - if (commands.length > 0) { + const cmds = getAvailableCommands(matchMap.state); + if (cmds.length > 0) { await Match.say( match, - `COMMANDS: ${commands.map((c) => Settings.COMMAND_PREFIXES[0] + c).join(', ')}` + `COMMANDS: ${cmds.map((cmd) => commands.formatIngameCommand(cmd)).join(', ')}` ); } }; @@ -303,10 +303,7 @@ const onRestartCommand: commands.CommandHandler = async (e) => { } else { await Match.say(match, `${escapeRconString(team.name)} WANTS TO RESTART THE KNIFE ROUND`); match.log(`${teamAB} (${team.name} - ${player.name}) wants to restart the knife round`); - await Match.say( - match, - `AGREE WITH ${commands.getUserCommandsByInternalCommand('RESTART')[0]}` - ); + await Match.say(match, `AGREE WITH ${commands.formatFirstIngameCommand('RESTART')}`); } MatchService.scheduleSave(match);