Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lobbies): rename region id -> region slug #591

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/lobbies/actors/lobby_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class Actor extends ActorBase<undefined, State.StateVersioned> {

// Valiadte region
const validRegions = regionsForBackend(lobbyConfig.backend);
if (validRegions.findIndex((x) => x.id == req.lobby.region) == -1) {
if (validRegions.findIndex((x) => x.slug == req.lobby.region) == -1) {
throw new RuntimeError("region_not_found", {
meta: { region: req.lobby.region },
});
Expand Down
2 changes: 1 addition & 1 deletion modules/lobbies/utils/lobby/backend/local_development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface LobbyBackendLocalDevelopmentResponse {

export const REGIONS: Region[] = [
{
id: "local",
slug: "local",
name: "Local",
latitude: 32.232330,
longitude: -110.961670,
Expand Down
20 changes: 10 additions & 10 deletions modules/lobbies/utils/lobby/backend/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,62 +34,62 @@ export interface LobbyBackendServerPortResponse {
// TODO: Return dynamic regions instead of hardcoded
export const REGIONS: Region[] = [
{
id: "atl",
slug: "atl",
name: "Atlanta",
latitude: 33.7490,
longitude: -84.3880,
},
{
id: "lax",
slug: "lax",
name: "Los Angeles",
latitude: 34.0522,
longitude: -118.2437,
},
{
id: "fra",
slug: "fra",
name: "Frankfurt",
latitude: 50.1109,
longitude: 8.6821,
},
{
id: "syd",
slug: "syd",
name: "Sydney",
latitude: -33.8688,
longitude: 151.2093,
},
{
id: "osa",
slug: "osa",
name: "Osaka",
latitude: 34.6937,
longitude: 135.5023,
},
{
id: "gru",
slug: "gru",
name: "São Paulo",
latitude: -23.5505,
longitude: -46.6333,
},
{
id: "bom",
slug: "bom",
name: "Mumbai",
latitude: 19.0760,
longitude: 72.8777,
},
{
id: "sin",
slug: "sin",
name: "Singapore",
latitude: 1.3521,
longitude: 103.8198,
},

{
id: "lnd-atl",
slug: "lnd-atl",
name: "Atlanta",
latitude: 33.7490,
longitude: -84.3880,
},
{
id: "lnd-fra",
slug: "lnd-fra",
name: "Frankfurt",
latitude: 50.1109,
longitude: 8.6821,
Expand Down
2 changes: 1 addition & 1 deletion modules/lobbies/utils/lobby/backend/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type LobbyBackendTestResponse = Record<never, never>;

export const REGIONS: Region[] = [
{
id: "test",
slug: "test",
name: "Test",
latitude: 33.67727501667558,
longitude: -106.47527637325621,
Expand Down
2 changes: 1 addition & 1 deletion modules/lobbies/utils/region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { UnreachableError } from "../module.gen.ts";
import { LobbyBackend } from "../config.ts";

export interface Region {
id: string;
slug: string;
name: string;
latitude: number;
longitude: number;
Expand Down
39 changes: 10 additions & 29 deletions sandbox/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,17 @@
<body>
<h1>Rivet Modules E2E Test</h1>

<div>
<label for="environmentToggle">Environment:</label>
<select id="environmentToggle" onchange="updateEnvironment()">
<option value="local">Local</option>
<option value="remote">Remote</option>
</select>
</div>

<script type="module" src="./index.js"></script>

<button onclick="findOrCreateLobby()">Find Or Create Lobby</button>
<button onclick="fetchState()">Fetch State</button>
<button onclick="resetState()">Reset State</button>
<button onclick="setAdminToken()">Set Admin Token</button>

<script>
window.addEventListener('load', function() {
const urlParams = new URLSearchParams(window.location.search);
const environment = urlParams.get('env');
if (environment === 'local' || environment === 'remote') {
document.getElementById('environmentToggle').value = environment;
}
});

function updateEnvironment() {
const environment = document.getElementById('environmentToggle').value;
const url = new URL(window.location);
url.searchParams.set('env', environment);
window.location.href = url.toString();
}
</script>
<div>
<button onclick="setEndpoint()">Set Endpoint</button>
<button onclick="setAdminToken()">Set Admin Token</button>
<button onclick="setGameVersion()">Set Game Version</button>
</div>
<div>
<button onclick="findOrCreateLobby()">Find Or Create Lobby</button>
<button onclick="fetchState()">Fetch State</button>
<button onclick="resetState()">Reset State</button>
</div>
</body>
</html>
62 changes: 27 additions & 35 deletions sandbox/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import { Rivet } from './sdk/index.mjs';

const urlParams = new URLSearchParams(window.location.search);
const environment = urlParams.get('env') || 'local';

function getBackend() {
return new Rivet({ endpoint: localStorage.apiEndpoint ?? "http://localhost:6420" });
return new Rivet({ endpoint: localStorage.endpoint });
}

window.fetchState = async function() {
Expand All @@ -21,44 +20,37 @@ window.resetState = async function() {
});
};

window.setEndpoint = function() {
localStorage.endpoint = prompt("Endpoint", localStorage.endpoint);
};

window.setAdminToken = function() {
let token = prompt("Admin token");
localStorage.adminToken = token;
localStorage.adminToken = prompt("Admin token", localStorage.adminToken);
};

window.setGameVersion = function() {
localStorage.gameVersion = prompt("Game version", localStorage.gameVersion);
};

window.findOrCreateLobby = async function() {
let res;
if (environment == 'local') {
res = await getBackend().lobbies.findOrCreate({
version: "default",
regions: ["local"],
tags: {},
players: [{}],

createConfig: {
region: "local",
tags: {},
maxPlayers: 8,
maxPlayersDirect: 8,
},
});
} else {
const region = "lnd-atl";
const tags = {"foo": "bar"};
res = await getBackend().lobbies.findOrCreate({
version: "2024.09.18-2",
regions: [region],
const regions = await getBackend().lobbies.listRegions({});

// const region = regions.regions[0].slug;
const region = 'lnd-atl';
const tags = {};
let res = await getBackend().lobbies.findOrCreate({
version: localStorage.gameVersion ?? "default",
regions: [region],
tags,
players: [{}],

createConfig: {
region,
tags,
players: [{}],

createConfig: {
region,
tags,
maxPlayers: 8,
maxPlayersDirect: 8,
},
});
}
maxPlayers: 8,
maxPlayersDirect: 8,
},
});

let { lobby, players } = res;

Expand Down
Loading