Skip to content

Commit

Permalink
Improve handling of stopped matches:
Browse files Browse the repository at this point in the history
- Enable to change game server of matches which are not live (to get them running again)
- Add possibility to stop dangling matches (matches which are not live but have not been stopped properly)
- UI: Add filter to match list for dangling matches
- UI: Show error messages at various places when the request to the backend fails (chat, rcon and others)
  • Loading branch information
JensForstmann committed Sep 20, 2024
1 parent 5e32da4 commit cf33c37
Show file tree
Hide file tree
Showing 12 changed files with 669 additions and 525 deletions.
10 changes: 10 additions & 0 deletions backend/src/matchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ export const remove = async (id: string) => {
}
};

export const removeStopped = async (id: string) => {
const matchFromStorage = await getFromStorage(id);
if (!matchFromStorage) {
return false;
}
matchFromStorage.isStopped = true;
await save(matchFromStorage);
return true;
};

export const revive = async (id: string) => {
const match = matches.get(id);
if (match) {
Expand Down
11 changes: 10 additions & 1 deletion backend/src/matchesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ export class MatchesController extends Controller {
const match = MatchService.get(id);
if (match) {
await Match.update(match, requestBody);
} else if (requestBody.gameServer) {
// for offline matches only allow to update game server to get match running again
const offlineMatch = await MatchService.getFromStorage(id);
if (offlineMatch) {
offlineMatch.gameServer = requestBody.gameServer;
await MatchService.save(offlineMatch);
}
} else {
this.setStatus(404);
}
Expand Down Expand Up @@ -209,7 +216,9 @@ export class MatchesController extends Controller {
@Delete('{id}')
async deleteMatch(id: string, @Request() req: ExpressRequest<IAuthResponse>): Promise<void> {
if (!(await MatchService.remove(id))) {
this.setStatus(404);
if (!(await MatchService.removeStopped(id))) {
this.setStatus(404);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion backend/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,8 @@
"description": "Match mode (single: stops when match is finished, loop: starts again after match is finished)"
},
"isLive": {
"type": "boolean"
"type": "boolean",
"description": "Match is currently supervised."
}
},
"required": [
Expand Down
1 change: 1 addition & 0 deletions common/types/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export interface IMatch {
}

export interface IMatchResponse extends IMatch {
/** Match is currently supervised. */
isLive: boolean;
}

Expand Down
21 changes: 15 additions & 6 deletions frontend/src/components/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Component } from 'solid-js';
import { Component, createSignal } from 'solid-js';
import { ChatEvent } from '../../../common';
import { t } from '../utils/locale';
import { onEnter } from '../utils/onEnter';
import { Card } from './Card';
import { ScrollArea } from './ScrollArea';
import { ErrorComponent } from './ErrorComponent';
import { TextInput } from './Inputs';
import { ScrollArea } from './ScrollArea';

export const Chat: Component<{
messages: ChatEvent[];
sendMessage: (msg: string) => void;
sendMessage: (msg: string) => Promise<any>;
}> = (props) => {
const [errorMessage, setErrorMessage] = createSignal('');
return (
<Card class="text-center">
<h2 class="text-lg font-bold">{t('Chat')}</h2>
Expand All @@ -18,14 +20,21 @@ export const Chat: Component<{
<TextInput
type="text"
onKeyDown={onEnter((e) => {
const msg = e.currentTarget.value.trim();
const input = e.currentTarget;
const msg = input.value.trim();
if (msg) {
props.sendMessage(msg);
e.currentTarget.value = '';
props
.sendMessage(msg)
.then(() => {
input.value = '';
setErrorMessage('');
})
.catch((err) => setErrorMessage(err + ''));
}
})}
placeholder={t('Send chat message...')}
/>
<ErrorComponent errorMessage={errorMessage()} />
</Card>
);
};
Expand Down
Loading

0 comments on commit cf33c37

Please sign in to comment.