Start maybe working on a native app
This commit is contained in:
+5
-4
@@ -4,6 +4,7 @@
|
||||
// connecting to a server and getting what it needs before joining, see docs/modding/networking/index.md:
|
||||
// hello -> welcome, download and check everything, ready -> join
|
||||
import { ClientMessage, PROTOCOL_VERSION, ServerMessage } from "@/common/protocol.ts";
|
||||
import { platform } from "./platform.ts";
|
||||
|
||||
const CONNECT_TIMEOUT_MS = 5000;
|
||||
const TRUST_KEY_PREFIX = "cubi:trusted:";
|
||||
@@ -23,12 +24,12 @@ export interface ServerAddress {
|
||||
export class HandshakeError extends Error {}
|
||||
|
||||
// what the server field starts as: ?server=host:port, otherwise the server that served the page
|
||||
export function default_server(page = new URL(location.href)): string {
|
||||
export function default_server(page = platform.page): string {
|
||||
return page.searchParams.get("server") ?? page.host;
|
||||
}
|
||||
|
||||
// what a player typed as the server: host:port, or a full http(s) or ws(s) url to pick the scheme
|
||||
export function server_address(input: string, page = new URL(location.href)): ServerAddress {
|
||||
export function server_address(input: string, page = platform.page): ServerAddress {
|
||||
const text = input.trim();
|
||||
let host = text;
|
||||
let secure: boolean;
|
||||
@@ -209,7 +210,7 @@ function mod_versions(welcome: Welcome) {
|
||||
|
||||
export function is_trusted(address: ServerAddress, welcome: Welcome): boolean {
|
||||
try {
|
||||
return localStorage.getItem(trust_key(address)) === mod_versions(welcome);
|
||||
return platform.storage.getItem(trust_key(address)) === mod_versions(welcome);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
@@ -217,7 +218,7 @@ export function is_trusted(address: ServerAddress, welcome: Welcome): boolean {
|
||||
|
||||
export function remember_trust(address: ServerAddress, welcome: Welcome) {
|
||||
try {
|
||||
localStorage.setItem(trust_key(address), mod_versions(welcome));
|
||||
platform.storage.setItem(trust_key(address), mod_versions(welcome));
|
||||
} catch {
|
||||
// private windows and blocked storage just ask again next time
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user