-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sandbox): create sandbox foundation
- Loading branch information
1 parent
bca968f
commit aebbb0b
Showing
26 changed files
with
3,327 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sdk/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"game_server": {"deploy": {"dockerfile_path": "game_server.Dockerfile"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"extends": "./backend.json", | ||
"modules": { | ||
"lobbies": { | ||
"registry": "local", | ||
"config": { | ||
"lobbies": { | ||
"regions": ["local"], | ||
"backend": { | ||
"localDevelopment": { | ||
"tags": {}, | ||
"ports": { | ||
"game": { "protocol": "http", "port": 7777 } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"runtime": { | ||
"cors": { | ||
"origins": [ | ||
"http://localhost:8080" | ||
] | ||
} | ||
}, | ||
"registries": { | ||
"local": { | ||
"local": { | ||
"directory": "../modules" | ||
} | ||
} | ||
}, | ||
"modules": { | ||
"rate_limit": { | ||
"registry": "local" | ||
}, | ||
"tokens": { | ||
"registry": "local" | ||
}, | ||
"lobbies": { | ||
"registry": "local", | ||
"config": { | ||
"lobbies": { | ||
"regions": [ | ||
"atl" | ||
], | ||
"backend": { | ||
"server": { | ||
"environment": { | ||
"SERVER_HOSTNAME": "0.0.0.0" | ||
}, | ||
"tags": { | ||
|
||
}, | ||
"ports": { | ||
"game": { | ||
"protocol": "http", | ||
"internalPort": 7777 | ||
} | ||
}, | ||
"resources": { | ||
"cpu": 250, | ||
"memory": 250 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"rivet": { | ||
"registry": "local", | ||
"config": { | ||
"apiEndpoint": "https://api.nathan16.gameinc.io", | ||
"serviceTokenVariable": "RIVET_SERVICE_TOKEN" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>OpenGB E2E Test</title> | ||
</head> | ||
<body> | ||
<h1>OpenGB 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> | ||
|
||
<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> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/// <reference path="./dist/sdk.d.mts" /> | ||
import { Backend } from './dist/sdk.mjs'; | ||
|
||
const urlParams = new URLSearchParams(window.location.search); | ||
const environment = urlParams.get('env') || 'local'; | ||
const API_ENDPOINT = environment === 'remote' ? "https://sandbox-back-vlk--staging.backend.nathan16.gameinc.io" : "http://localhost:6420"; | ||
|
||
const backend = new Backend({ endpoint: API_ENDPOINT }); | ||
|
||
console.log('backend', backend); | ||
|
||
window.findOrCreateLobby = async function() { | ||
let res; | ||
if (environment == 'local') { | ||
res = await backend.lobbies.findOrCreate({ | ||
version: "default", | ||
regions: ["local"], | ||
tags: {}, | ||
players: [{}], | ||
|
||
createConfig: { | ||
region: "local", | ||
tags: {}, | ||
maxPlayers: 8, | ||
maxPlayersDirect: 8, | ||
}, | ||
}); | ||
} else { | ||
const region = "atl"; | ||
const tags = {"foo": "bar"}; | ||
res = await backend.lobbies.findOrCreate({ | ||
version: "95cbad73-dcfd-4a74-96de-799b8ddc1b72", | ||
regions: [region], | ||
tags, | ||
players: [{}], | ||
|
||
createConfig: { | ||
region, | ||
tags, | ||
maxPlayers: 8, | ||
maxPlayersDirect: 8, | ||
}, | ||
}); | ||
} | ||
|
||
let { lobby, players } = res; | ||
|
||
// Test lobby connection | ||
while (true) { | ||
try { | ||
await connect(lobby, players); | ||
break; | ||
} catch (err) { | ||
console.warn('failed', err); | ||
} | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 500)); | ||
} | ||
|
||
console.log('finished'); | ||
} | ||
|
||
function connect(lobby, players) { | ||
return new Promise((resolve, reject) => { | ||
let hostname; | ||
let port; | ||
if (lobby.backend.server) { | ||
port = lobby.backend.server.ports["game"]; | ||
} else if (lobby.backend.localDevelopment) { | ||
port = lobby.backend.localDevelopment.ports["game"]; | ||
} else { | ||
throw new Error("unknown backend"); | ||
} | ||
|
||
console.log('connecting to', port); | ||
|
||
const ws = new WebSocket(`${port.isTls ? "wss" : "ws"}://${port.hostname}:${port.port}?token=${players[0].token}`); | ||
ws.onopen = () => { | ||
console.log('open'); | ||
}; | ||
ws.onerror = err => { | ||
reject(err) | ||
}; | ||
ws.onmessage = ev => { | ||
let [event, data] = JSON.parse(ev.data); | ||
if (event == 'init') { | ||
console.log('init', data) | ||
ws.send(JSON.stringify(["ping", 1])) | ||
} else if (event == 'pong') { | ||
console.log('pong'); | ||
ws.close(); | ||
resolve(); | ||
} else if (event == 'stats') { | ||
// pass | ||
} else { | ||
console.warn('unknown event', event, data) | ||
} | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"lint": { | ||
"include": [ | ||
"src/" | ||
], | ||
"exclude": [ | ||
"tests/" | ||
], | ||
"rules": { | ||
"exclude": [ | ||
"no-empty-interface", | ||
"no-explicit-any", | ||
"require-await" | ||
] | ||
} | ||
}, | ||
"fmt": { | ||
"useTabs": true | ||
} | ||
} |
Oops, something went wrong.