Skip to content

Commit

Permalink
Don't throw if there are no online players or maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Tripperful committed May 6, 2024
1 parent 385c581 commit ab9a6d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions packages/server/src/srcdsApi/WsSrcdsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ export class WsSrcdsApi implements SrcdsApi {
...cvars: TCvars[]
): Promise<{ [cvar in TCvars]: string }> {
return (
await this.request<TCvars[], { [cvar in TCvars]: string }>(
'get_cvars_request',
cvars,
)
).data;
(
await this.request<TCvars[], { [cvar in TCvars]: string }>(
'get_cvars_request',
cvars,
)
).data ?? ({} as { [cvar in TCvars]: string })
);
}

setCvar(cvar: Cvar, value: string): void {
Expand All @@ -52,7 +54,7 @@ export class WsSrcdsApi implements SrcdsApi {
}

async getMaps(): Promise<string[]> {
return (await this.request<never, string[]>('get_maps_request')).data;
return (await this.request<never, string[]>('get_maps_request')).data ?? [];
}

changelevel(token: string, mapName: string): void {
Expand All @@ -61,8 +63,9 @@ export class WsSrcdsApi implements SrcdsApi {

async getOnlinePlayers(): Promise<OnlinePlayerInfo[]> {
return (
await this.request<never, OnlinePlayerInfo[]>('get_players_request')
).data;
(await this.request<never, OnlinePlayerInfo[]>('get_players_request'))
.data ?? []
);
}

startMatch(
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/ws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class WsApi {
data?: TData,
guid?: string,
) {
const { ws } = this.remotesBySessionId[sessionId];
const ws = this.remotesBySessionId[sessionId]?.ws;

if (!ws?.OPEN) {
throw new Error(
Expand Down

0 comments on commit ab9a6d6

Please sign in to comment.