Skip to content

Commit

Permalink
Add MATCH_STOP webhook (sent when TMT stops supervising a match)
Browse files Browse the repository at this point in the history
  • Loading branch information
JensForstmann committed Sep 22, 2024
1 parent b9a92ee commit 668b3e3
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
6 changes: 6 additions & 0 deletions backend/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
MapStartEvent,
MatchCreateEvent,
MatchEndEvent,
MatchStopEvent,
MatchUpdateEvent,
RoundEndEvent,
TMapMode,
Expand Down Expand Up @@ -250,3 +251,8 @@ export const onMatchUpdate = (match: Match.Match, path: Array<string | number>,
const sendAsSysEvent = match.data.createdAt + 10000 > Date.now();
send(match, data, sendAsSysEvent);
};

export const onMatchStop = (match: Match.Match) => {
const data: MatchStopEvent = getBaseEvent(match, 'MATCH_STOP');
send(match, data);
};
1 change: 1 addition & 0 deletions backend/src/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ export const stop = async (match: Match) => {
await say(match, `TMT IS OFFLINE`).catch(() => {});
await GameServer.disconnect(match);
await ManagedGameServers.free(match.data.gameServer, match.data.id);
Events.onMatchStop(match);
};

export const onElectionFinished = async (match: Match) => {
Expand Down
17 changes: 17 additions & 0 deletions backend/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ const models: TsoaRoute.Models = {
{ dataType: 'enum', enums: ['LOG'] },
{ dataType: 'enum', enums: ['MATCH_CREATE'] },
{ dataType: 'enum', enums: ['MATCH_UPDATE'] },
{ dataType: 'enum', enums: ['MATCH_STOP'] },
],
validators: {},
},
Expand Down Expand Up @@ -1004,6 +1005,21 @@ const models: TsoaRoute.Models = {
additionalProperties: false,
},
// 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
MatchStopEvent: {
dataType: 'refObject',
properties: {
timestamp: { dataType: 'string', required: true },
matchId: { dataType: 'string', required: true },
matchPassthrough: {
dataType: 'union',
subSchemas: [{ dataType: 'string' }, { dataType: 'enum', enums: [null] }],
required: true,
},
type: { dataType: 'enum', enums: ['MATCH_STOP'], required: true },
},
additionalProperties: false,
},
// 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
Event: {
dataType: 'refAlias',
type: {
Expand All @@ -1021,6 +1037,7 @@ const models: TsoaRoute.Models = {
{ ref: 'ElectionSideStep' },
{ ref: 'MatchCreateEvent' },
{ ref: 'MatchUpdateEvent' },
{ ref: 'MatchStopEvent' },
],
validators: {},
},
Expand Down
3 changes: 2 additions & 1 deletion backend/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const Settings = {
'MAP_END',
'MAP_START',
'MATCH_END',
'MATCH_STOP',
'ROUND_END',
] as EventType[],
] satisfies EventType[] as EventType[],
};
36 changes: 35 additions & 1 deletion backend/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,8 @@
"MATCH_END",
"LOG",
"MATCH_CREATE",
"MATCH_UPDATE"
"MATCH_UPDATE",
"MATCH_STOP"
]
},
"ChatEvent": {
Expand Down Expand Up @@ -1863,6 +1864,36 @@
"type": "object",
"additionalProperties": false
},
"MatchStopEvent": {
"properties": {
"timestamp": {
"type": "string",
"description": "ISO"
},
"matchId": {
"type": "string"
},
"matchPassthrough": {
"type": "string",
"nullable": true
},
"type": {
"type": "string",
"enum": [
"MATCH_STOP"
],
"nullable": false
}
},
"required": [
"timestamp",
"matchId",
"matchPassthrough",
"type"
],
"type": "object",
"additionalProperties": false
},
"Event": {
"anyOf": [
{
Expand Down Expand Up @@ -1900,6 +1931,9 @@
},
{
"$ref": "#/components/schemas/MatchUpdateEvent"
},
{
"$ref": "#/components/schemas/MatchStopEvent"
}
]
},
Expand Down
10 changes: 8 additions & 2 deletions common/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export type EventType =
| 'MATCH_END'
| 'LOG'
| 'MATCH_CREATE'
| 'MATCH_UPDATE';
| 'MATCH_UPDATE'
| 'MATCH_STOP';

export interface BaseEvent {
/** ISO */
Expand Down Expand Up @@ -136,6 +137,10 @@ export interface MatchUpdateEvent extends BaseEvent {
value: any;
}

export interface MatchStopEvent extends BaseEvent {
type: 'MATCH_STOP';
}

export type Event =
| ChatEvent
| ElectionEndEvent
Expand All @@ -148,4 +153,5 @@ export type Event =
| ElectionMapStep
| ElectionSideStep
| MatchCreateEvent
| MatchUpdateEvent;
| MatchUpdateEvent
| MatchStopEvent;

0 comments on commit 668b3e3

Please sign in to comment.