Skip to content

Commit

Permalink
feat(lobbies): return region with find lobby
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Sep 30, 2024
1 parent ed8f262 commit 7a74f3c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 45 deletions.
11 changes: 10 additions & 1 deletion modules/lobbies/actors/lobby_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { LobbyBackendServerPortResponse } from "../utils/lobby/backend/server.ts
import { regionsForBackend } from "../utils/region.ts";
import * as State from "../utils/lobby_manager/state/mod.ts";
import * as Rpc from "../utils/lobby_manager/rpc.ts";
import { assertExists } from "jsr:@std/assert";

const MANAGER_SERVER_TAG = "manager";
const MANAGER_SERVER_TAG_VALUE = "opengb/lobbies";
Expand Down Expand Up @@ -413,11 +414,13 @@ export class Actor extends ActorBase<undefined, State.StateVersioned> {
}

private buildLobbyResponse(
_ctx: ActorContext,
ctx: ActorContext,
lobbyId: string,
): LobbyResponse {
const lobby = this.getLobby(lobbyId);
const lobbyConfig = getLobbyConfig(ctx.config, lobby.tags);

// Build backend
let backend: LobbyBackendResponse;
if ("test" in lobby.backend) {
backend = { test: {} };
Expand Down Expand Up @@ -462,10 +465,16 @@ export class Actor extends ActorBase<undefined, State.StateVersioned> {
throw new UnreachableError(lobby.backend);
}

// Get region
const allRegions = regionsForBackend(lobbyConfig.backend);
const region = allRegions.find(x => x.slug == lobby.region);
assertExists(region, "could not find region for lobby");

return {
id: lobby.id,
version: lobby.version,
tags: lobby.tags,
region,
createdAt: lobby.createdAt,
readyAt: lobby.readyAt,
players: Object.keys(lobby.players).length,
Expand Down
2 changes: 2 additions & 0 deletions modules/lobbies/utils/lobby/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { LobbyBackendServerResponse } from "./backend/server.ts";
import {
LobbyBackendLocalDevelopmentResponse,
} from "./backend/local_development.ts";
import { Region } from "../region.ts";

/**
* Check if a lobby with the given tags matches a query.
Expand All @@ -21,6 +22,7 @@ export interface LobbyResponse {
id: string;
version: string;
tags: Record<string, string>;
region: Region,

createdAt: number;
readyAt?: number;
Expand Down
64 changes: 32 additions & 32 deletions sandbox/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"name": "rivet-sdk",
"version": "1.0.0",
"repository": {
"type": "git",
"url": "https://github.com/rivet-gg/rivet.git"
},
"scripts": {
"build": "tsup",
"prepare": "npm run build"
},
"name": "rivet-sdk",
"version": "1.0.0",
"repository": {
"type": "git",
"url": "https://github.com/rivet-gg/rivet.git"
},
"scripts": {
"build": "tsup",
"prepare": "npm run build"
},

"devDependencies": {
"typescript": "^4.0 || ^5.0",
"tsup": "^8.3.0"
},
"devDependencies": {
"typescript": "^4.0 || ^5.0",
"tsup": "^8.3.0"
},

"tsup": {
"entry": ["src/index.ts"],
"format": ["esm", "cjs", "iife"],
"sourcemap": true,
"dts": true
},
"tsup": {
"entry": ["src/index.ts"],
"format": ["esm", "cjs", "iife"],
"sourcemap": true,
"dts": true
},

"files": ["dist"],
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"browser": "./dist/index.global.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
}
"files": ["dist"],
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"browser": "./dist/index.global.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
}
}
23 changes: 11 additions & 12 deletions sandbox/sdk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"compilerOptions": {
"declaration": true,
"target": "esnext",
"module": "commonjs",
"moduleResolution": "node",
"allowImportingTsExtensions": true
},
"exclude": [
"dist",
"node_modules"
]
"compilerOptions": {
"declaration": true,
"target": "esnext",
"module": "commonjs",
"moduleResolution": "node",
"allowImportingTsExtensions": true
},
"exclude": [
"dist",
"node_modules"
]
}

0 comments on commit 7a74f3c

Please sign in to comment.