From e320f15ff9749973ba7d88fd58fa0ca2cdf4f691 Mon Sep 17 00:00:00 2001 From: tyuXX Date: Sun, 15 Nov 2026 14:44:30 +0300 Subject: [PATCH] Better pass handling through links --- src/client/api.ts | 10 ++++++++++ src/client/app.ts | 17 ++++++++++++++++- src/client/screens/mainMenu.ts | 11 +++++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/client/api.ts b/src/client/api.ts index d768517..02047fa 100644 --- a/src/client/api.ts +++ b/src/client/api.ts @@ -16,6 +16,16 @@ export interface ClientSettings { const TOKEN_KEY = "spacegaem_proto_token"; const SETTINGS_KEY = "spacegaem_proto_settings"; +const SERVER_JOIN_KEY = "spacegaem_server_join_ok"; + +export function getServerJoinOk(): boolean { + return sessionStorage.getItem(SERVER_JOIN_KEY) === "1"; +} + +export function setServerJoinOk(ok: boolean): void { + if (ok) sessionStorage.setItem(SERVER_JOIN_KEY, "1"); + else sessionStorage.removeItem(SERVER_JOIN_KEY); +} export function getToken(): string | null { return localStorage.getItem(TOKEN_KEY); diff --git a/src/client/app.ts b/src/client/app.ts index d72e3dd..b1a7db4 100644 --- a/src/client/app.ts +++ b/src/client/app.ts @@ -1,5 +1,5 @@ // Literally everything (pls help me my autocorrect is trying to insult me how does this even work) -import { getSettings, saveSettings } from "./api.js"; +import { api, getSettings, saveSettings, setServerJoinOk } from "./api.js"; import { navigate, registerScreenRenderers } from "./router.js"; import { loadCatalogs, @@ -128,6 +128,21 @@ async function boot(): Promise { } catch (err) { toast(`Failed to load mission catalogs: ${(err as Error).message}`, "err"); } + const passParam = new URLSearchParams(window.location.search).get("pass"); + if (passParam) { + const url = new URL(window.location.href); + url.searchParams.delete("pass"); + window.history.replaceState(null, "", url.toString()); + if (state.serverInfo?.serverPasswordRequired) { + try { + await api.post("/api/join", { password: passParam }, false); + setServerJoinOk(true); + toast("Server access granted via link.", "ok"); + } catch { + toast("Server password in link was rejected.", "err"); + } + } + } await refreshMe(); if (state.agency) { await refreshWorld(); diff --git a/src/client/screens/mainMenu.ts b/src/client/screens/mainMenu.ts index 06ce319..6ad00eb 100644 --- a/src/client/screens/mainMenu.ts +++ b/src/client/screens/mainMenu.ts @@ -1,7 +1,13 @@ // Renders the animated 3D solar system main menu, settings dialog, and quick-join entry. // Again, self explanatory -import { api, getSettings, saveSettings } from "../api.js"; +import { + api, + getServerJoinOk, + getSettings, + saveSettings, + setServerJoinOk, +} from "../api.js"; import { navigate } from "../router.js"; import { refreshMe, refreshWorld, startEvents } from "../session.js"; import { state } from "../state.js"; @@ -211,7 +217,7 @@ function proceedAfterJoin(): void { } function handleJoinClick(): void { - if (!state.serverInfo?.serverPasswordRequired) { + if (!state.serverInfo?.serverPasswordRequired || getServerJoinOk()) { proceedAfterJoin(); return; } @@ -241,6 +247,7 @@ function handleJoinClick(): void { errLine.textContent = ""; try { await api.post("/api/join", { password: pwdInput.value }, false); + setServerJoinOk(true); proceedAfterJoin(); } catch (err) { errLine.textContent = (err as Error).message;