Skip to content

Commit 4876452

Browse files
committed
better documenting server status
1 parent 39d348d commit 4876452

2 files changed

Lines changed: 68 additions & 12 deletions

File tree

src/lib/state.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const SessionState = {
1616
dynamoDBClient: null as DynamoDBClient | null,
1717
s3Client: null as S3Client | null,
1818
devMode: (browser && window.location.hostname === "localhost"),
19+
serverResponses: [] as { server: Server; success: boolean; time: number }[],
1920
plays: 0,
2021
user: null as null | { name: string; email: string; tokens: any } | undefined,
2122
loggedIn: false
@@ -61,7 +62,7 @@ export const State = createState({
6162
homeView: "grid",
6263
pinnedGames: [],
6364
games: [],
64-
isAHost: () => (AHosts.some((h): boolean => browser && h.hostname === window.location.hostname)) || SessionState.devMode,
65+
isAHost: () => (AHosts.some((h): boolean => browser && h.hostname === window.location.hostname)),
6566
localPlays: 0
6667
});
6768

@@ -98,16 +99,26 @@ export async function initializeTooling() {
9899
export async function findServer(): Promise<Server | null> {
99100
const servers = await findServers();
100101
State.servers = servers;
102+
SessionState.serverResponses = [];
101103
for (let server of State.servers.sort((a, b) => a.priority - b.priority)) {
104+
const start = performance.now();
102105
const response = await fetch(`https://${server.hostname}/blocked_res.txt`);
106+
let end = start;
107+
if (response) end = performance.now();
108+
103109
if (response.ok && response.status === 200) {
104110
const text = await response.text();
105111
if (text.includes("===NOT_BLOCKED===") && text.includes("SOmehtin23\"")) {
106-
return server;
112+
SessionState.serverResponses.push({ server, success: true, time: end - start });
113+
} else {
114+
SessionState.serverResponses.push({ server, success: false, time: end - start });
107115
}
116+
} else {
117+
SessionState.serverResponses.push({ server, success: false, time: end - start });
108118
}
109119
}
110-
return null;
120+
// Already sorted by priority, so first success is best
121+
return SessionState.serverResponses.find(r => r.success)?.server || null;
111122
}
112123

113124
export function loadState(state: StateType): StateType {

src/routes/+page.svelte

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import type { PageData } from "./$types.js";
88
import { getTimeBetween } from "$lib/helpers.js";
99
import { browser } from "$app/environment";
10+
import { page } from "$app/state";
1011
1112
const { data }: { data: PageData } = $props();
1213
@@ -15,6 +16,7 @@
1516
let devMode = $state(true);
1617
let adblockEnabled = $state(SessionState.adBlockEnabled);
1718
let adsEnabled = $state(SessionState.adsEnabled);
19+
let sResponses = $state(SessionState.serverResponses)
1820
onMount(async () => {
1921
await initializeTooling();
2022
isAHost = State.isAHost();
@@ -76,22 +78,65 @@
7678
Ads Enabled: {adsEnabled}<br />
7779
Current Server: {State.currentServer.name} (Loaded {State.servers
7880
.length})<br />
81+
<table style="width:100%; margin: 10px 0; border-collapse: collapse; font-size: 12px;">
82+
<thead>
83+
<tr>
84+
<th style="border-bottom: 1px solid #ccc; text-align: left;">Server</th>
85+
<th style="border-bottom: 1px solid #ccc; text-align: left;">Status</th>
86+
<th style="border-bottom: 1px solid #ccc; text-align: left;">Ping (ms)</th>
87+
</tr>
88+
</thead>
89+
<tbody>
90+
{#each sResponses as r}
91+
<tr>
92+
<td>{r.server.name}</td>
93+
<td>{r.success ? "Success" : "Failed"}</td>
94+
<td>{r.time.toFixed(2)}</td>
95+
</tr>
96+
{/each}
97+
</tbody>
98+
</table>
7999
AHost: {State.isAHost()} (Loaded {State.aHosts.length})<br />
80-
AHosts: {State.aHosts.map(h => h.hostname).join(", ")}
100+
<table style="width:100%; margin: 10px 0; border-collapse: collapse; font-size: 12px;">
101+
<thead>
102+
<tr>
103+
<th style="border-bottom: 1px solid #ccc; text-align: left;">AHost Hostname</th>
104+
<th style="border-bottom: 1px solid #ccc; text-align: left;">ACode</th>
105+
</tr>
106+
</thead>
107+
<tbody>
108+
{#each State.aHosts as h}
109+
<tr>
110+
<td>{h.hostname}{(h.hostname && browser && h.hostname == page.url.hostname) ? " (Active)" : " (Inactive)"}</td>
111+
<td>{h.acode}</td>
112+
</tr>
113+
{/each}
114+
</tbody>
115+
</table>
81116
<br />
82117
Games Loaded: {games.length} ({State.pinnedGames.length} pinned) - rendered
83118
{State.homeView}<br />
84119
Version: {State.version}<br />
85120
Logged In: {SessionState.loggedIn}<br />
86121
SSR: {SessionState.ssr}<br />
87-
AWS Ready: {SessionState.awsReady}<br />
88-
AWS Acting: {SessionState.credentials?.identityId} | {SessionState
89-
.credentials?.accessKeyId}<br />
90-
Credentials Expires: {SessionState.credentials?.expiration?.toLocaleTimeString()}
91-
{getTimeBetween(
92-
SessionState.credentials?.expiration || new Date(),
93-
new Date(),
94-
)} <br />
122+
<table style="width:100%; margin: 10px 0; border-collapse: collapse; font-size: 12px;">
123+
<thead>
124+
<tr>
125+
<th style="border-bottom: 1px solid #ccc; text-align: left;">AWS Ready</th>
126+
<th style="border-bottom: 1px solid #ccc; text-align: left;">Identity ID</th>
127+
<th style="border-bottom: 1px solid #ccc; text-align: left;">Access Key ID</th>
128+
<th style="border-bottom: 1px solid #ccc; text-align: left;">Credentials Expires</th>
129+
</tr>
130+
</thead>
131+
<tbody>
132+
<tr>
133+
<td>{SessionState.awsReady ? "Yes" : "No"}</td>
134+
<td title={SessionState.credentials?.identityId || "-"}>{SessionState.credentials?.identityId.slice(0, 10) + "..." || "-"}</td>
135+
<td title={SessionState.credentials?.accessKeyId || "-"}>{SessionState.credentials?.accessKeyId.slice(0, 6) + "..." || "-"}</td>
136+
<td>{SessionState.credentials?.expiration?.toLocaleTimeString() || "-"}</td>
137+
</tr>
138+
</tbody>
139+
</table>
95140
Plays: {SessionState.plays.toLocaleString()} ({State.localPlays.toLocaleString()}
96141
local)<br />
97142
</div>

0 commit comments

Comments
 (0)