Skip to content

Commit

Permalink
Add docs to endpoints and types.
Browse files Browse the repository at this point in the history
  • Loading branch information
JensForstmann committed Nov 6, 2023
1 parent 679ef08 commit 6cecc96
Show file tree
Hide file tree
Showing 18 changed files with 348 additions and 76 deletions.
3 changes: 3 additions & 0 deletions backend/src/configController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { TMT_LOG_ADDRESS } from '.';
@Route('/api/config')
@Security('bearer_token')
export class ConfigController extends Controller {
/**
* Get some internal config variables. Currently only the set TMT_LOG_ADDRESS.
*/
@Get()
@NoSecurity()
async getConfig(): Promise<{
Expand Down
3 changes: 3 additions & 0 deletions backend/src/debugController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { STORAGE_FOLDER } from './storage';
@Route('/api/debug')
@Security('bearer_token')
export class DebugController extends Controller {
/**
* Get all connected web socket clients.
*/
@Get('webSockets')
async getWebSocketClients() {
return WebSocket.getClients();
Expand Down
16 changes: 15 additions & 1 deletion backend/src/gameServersController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import * as ManagedGameServers from './managedGameServers';
@Route('/api/gameservers')
@Security('bearer_token')
export class GameServersController extends Controller {
/**
* Get all managed game servers.
*/
@Get()
async getGameServers(): Promise<IManagedGameServer[]> {
return ManagedGameServers.getAll();
}

/**
* Add a new managed game server.
*/
@Post()
async createGameServer(
@Body() requestBody: IManagedGameServerCreateDto
Expand All @@ -30,13 +36,21 @@ export class GameServersController extends Controller {
return managedGameServer;
}

/**
* Change an existing managed game server.
*/
@Patch('{ip}/{port}')
async updateGameServer(
@Body() requestBody: IManagedGameServerUpdateDto
@Body() requestBody: IManagedGameServerUpdateDto,
ip: string,
port: number
): Promise<IManagedGameServer> {
return await ManagedGameServers.update(requestBody);
}

/**
* Delete an existing managed game server.
*/
@Delete('{ip}/{port}')
async deleteGameServer(ip: string, port: number): Promise<void> {
await ManagedGameServers.remove({
Expand Down
3 changes: 3 additions & 0 deletions backend/src/loginController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { Controller, Post, Route, Security } from '@tsoa/runtime';
@Route('/api/login')
@Security('bearer_token')
export class LoginController extends Controller {
/**
* Dummy endpoint to check if given token is valid without executing anything.
*/
@Post()
async login() {}
}
45 changes: 45 additions & 0 deletions backend/src/matchesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import * as MatchService from './matchService';
@Route('/api/matches')
@Security('bearer_token')
export class MatchesController extends Controller {
/**
* Create and supervise a new match.
*/
@Post()
@SuccessResponse(201)
@Security('bearer_token_optional')
Expand All @@ -42,6 +45,13 @@ export class MatchesController extends Controller {
return match.data;
}

/**
* Get all matches.
* @param state State filter
* @param passthrough Passthrough filter
* @param isStopped Get only stopped or not stopped matches.
* @param isLive Filter for only live (currently active) matches, or the opposite.
*/
@Get()
async getAllMatches(
@Request() { user }: { user: IAuthResponse },
Expand All @@ -66,6 +76,9 @@ export class MatchesController extends Controller {
.map((m) => MatchService.hideRconPassword(m));
}

/**
* Get a specific match by id.
*/
@Get('{id}')
async getMatch(
id: string,
Expand All @@ -91,16 +104,26 @@ export class MatchesController extends Controller {
return;
}

/**
* Get the last 1000 log lines from a specific match.
*/
@Get('{id}/logs')
async getLogs(id: string, @Request() { user }: { user: IAuthResponse }): Promise<string[]> {
return await Match.getLogsTail(id);
}

/**
* Get the last 1000 events from a specific match.
*/
@Get('{id}/events')
async getEvents(id: string, @Request() { user }: { user: IAuthResponse }): Promise<Event[]> {
return await Events.getEventsTail(id);
}

/**
* Get the last known round backups for a specific match.
* @param count The max. number of round backups to be returned.
*/
@Get('{id}/server/round_backups')
async getRoundBackups(
id: string,
Expand All @@ -116,6 +139,10 @@ export class MatchesController extends Controller {
}
}

/**
* Load a round backup file for a specific match.
* @param file Name of the round backup file.
*/
@Post('{id}/server/round_backups/{file}')
async loadRoundBackup(
id: string,
Expand All @@ -136,6 +163,9 @@ export class MatchesController extends Controller {
}
}

/**
* Update a specific match.
*/
@Patch('{id}')
async updateMatch(
id: string,
Expand All @@ -150,6 +180,9 @@ export class MatchesController extends Controller {
}
}

/**
* Update a specific match map. First map has the map number 0.
*/
@Patch('{id}/matchMap/{mapNumber}')
async updateMatchMap(
id: string,
Expand All @@ -170,20 +203,29 @@ export class MatchesController extends Controller {
await MatchMap.update(match, matchMap, requestBody, mapNumber);
}

/**
* Stop supervising a specific match. TMT will no longer listen to the game server and will not execute any rcon commands.
*/
@Delete('{id}')
async deleteMatch(id: string, @Request() { user }: { user: IAuthResponse }): Promise<void> {
if (!(await MatchService.remove(id))) {
this.setStatus(404);
}
}

/**
* Revive a specific match. TMT will start supervising a (stopped) match again (listen to the game sever and execute rcon commands).
*/
@Patch('{id}/revive')
async reviveMatch(id: string, @Request() { user }: { user: IAuthResponse }): Promise<void> {
if (!(await MatchService.revive(id))) {
this.setStatus(404);
}
}

/**
* Execute a rcon command on the game server.
*/
@Post('{id}/server/rcon')
async rcon(
id: string,
Expand All @@ -202,6 +244,9 @@ export class MatchesController extends Controller {
return await Match.execManyRcon(match, requestBody);
}

/**
* Endpoint the game server sends its log file to. Not meant for direct use!
*/
@NoSecurity()
@Post('{id}/server/log/{secret}')
receiveLog(id: string, secret: string, @Body() requestBody: any): void {
Expand Down
12 changes: 12 additions & 0 deletions backend/src/presetsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ import * as Presets from './presets';
@Route('/api/presets')
@Security('bearer_token')
export class PresetsController extends Controller {
/**
* Get all configured presets.
*/
@Get()
async getPresets(@Request() { user }: { user: IAuthResponse }): Promise<IPreset[]> {
return Presets.getAll();
}

/**
* Create a new preset.
*/
@Post()
@SuccessResponse(201)
async createPreset(
Expand All @@ -33,13 +39,19 @@ export class PresetsController extends Controller {
return preset;
}

/**
* Update an existing preset.
*/
@Put()
async updatePreset(@Body() requestBody: IPreset, @Request() { user }: { user: IAuthResponse }) {
if (!(await Presets.update(requestBody))) {
this.setStatus(404);
}
}

/**
* Delete an existing preset.
*/
@Delete('{id}')
async deletePreset(id: string, @Request() { user }: { user: IAuthResponse }): Promise<void> {
if (!(await Presets.remove(id))) {
Expand Down
10 changes: 6 additions & 4 deletions backend/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type { RequestHandler, Router } from 'express';
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa

const models: TsoaRoute.Models = {
TMatchSate: {
TMatchState: {
dataType: 'refAlias',
type: {
dataType: 'union',
Expand Down Expand Up @@ -472,7 +472,7 @@ const models: TsoaRoute.Models = {
dataType: 'refObject',
properties: {
id: { dataType: 'string', required: true },
state: { ref: 'TMatchSate', required: true },
state: { ref: 'TMatchState', required: true },
passthrough: { dataType: 'string' },
mapPool: { dataType: 'array', array: { dataType: 'string' }, required: true },
teamA: { ref: 'ITeam', required: true },
Expand Down Expand Up @@ -584,7 +584,7 @@ const models: TsoaRoute.Models = {
dataType: 'refObject',
properties: {
id: { dataType: 'string', required: true },
state: { ref: 'TMatchSate', required: true },
state: { ref: 'TMatchState', required: true },
passthrough: { dataType: 'string' },
mapPool: { dataType: 'array', array: { dataType: 'string' }, required: true },
teamA: { ref: 'ITeam', required: true },
Expand Down Expand Up @@ -1007,7 +1007,7 @@ const models: TsoaRoute.Models = {
matchEndAction: { ref: 'TMatchEndAction' },
tmtLogAddress: { dataType: 'string' },
mode: { ref: 'TMatchMode' },
state: { ref: 'TMatchSate' },
state: { ref: 'TMatchState' },
logSecret: { dataType: 'string' },
currentMap: { dataType: 'double' },
_restartElection: { dataType: 'boolean' },
Expand Down Expand Up @@ -1632,6 +1632,8 @@ export function RegisterRoutes(app: Router) {
required: true,
ref: 'IManagedGameServerUpdateDto',
},
ip: { in: 'path', name: 'ip', required: true, dataType: 'string' },
port: { in: 'path', name: 'port', required: true, dataType: 'double' },
};

// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
Expand Down
Loading

0 comments on commit 6cecc96

Please sign in to comment.