Skip to content

Commit

Permalink
Add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
JensForstmann committed Nov 2, 2023
1 parent 5178280 commit 2308160
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions backend/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Commands = [
'SWITCH',
'TEAM',
'RESTART',
'VERSION',
'*',
] as const;
export type TCommand = typeof Commands[number];
Expand All @@ -38,6 +39,7 @@ commandMapping.set('switch', 'SWITCH');
commandMapping.set('swap', 'SWITCH');
commandMapping.set('team', 'TEAM');
commandMapping.set('restart', 'RESTART');
commandMapping.set('version', 'VERSION');

export const getInternalCommandByUserCommand = (userCommand: string) => {
return commandMapping.get(userCommand);
Expand Down
7 changes: 6 additions & 1 deletion backend/src/match.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ValidateError } from '@tsoa/runtime';
import { generate as shortUuid } from 'short-uuid';
import { TMT_LOG_ADDRESS } from '.';
import { TMT_LOG_ADDRESS, VERSION } from '.';
import {
escapeRconSayString,
escapeRconString,
Expand Down Expand Up @@ -652,9 +652,14 @@ const onConsoleSay = async (match: Match, message: string) => {

export const registerCommandHandlers = () => {
commands.registerHandler('TEAM', onTeamCommand);
commands.registerHandler('VERSION', onVersionCommand);
commands.registerHandler('*', onEveryCommand);
};

const onVersionCommand: commands.CommandHandler = async (e) => {
await say(e.match, `TMT version: ${VERSION ?? 'unknown'}`);
};

const onEveryCommand: commands.CommandHandler = async (e) => {
if (!e.player.team) {
return;
Expand Down

0 comments on commit 2308160

Please sign in to comment.