From 5dce5ffdae8a2f7896c82fe04b983302886718d7 Mon Sep 17 00:00:00 2001 From: Mathis Brossier Date: Mon, 21 Oct 2024 22:38:24 +0200 Subject: [PATCH] started working on auth --- client/src/server/protocol.ts | 14 ++++-- client/src/twmap/datafile.ts | 1 - client/src/ui/index.svelte | 22 +++++++-- client/src/ui/lib/dialog.ts | 10 ++++ client/src/ui/lib/fence.svelte | 10 ++-- client/src/ui/lib/util.ts | 10 +++- client/src/ui/routes/edit.svelte | 3 +- client/src/ui/routes/lobby.svelte | 19 ++++++-- desktop/Cargo.lock | 43 +++++++++++++++++ server/Cargo.lock | 43 +++++++++++++++++ server/Cargo.toml | 1 + server/src/error.rs | 3 ++ server/src/map_cfg.rs | 57 ++++++++++++++++++---- server/src/protocol.rs | 34 ++++++++++---- server/src/room.rs | 22 ++++----- server/src/router.rs | 39 +++++++++++----- server/src/server.rs | 78 ++++++++++++++++++++++--------- 17 files changed, 327 insertions(+), 82 deletions(-) diff --git a/client/src/server/protocol.ts b/client/src/server/protocol.ts index 1287e0c..059dfc0 100644 --- a/client/src/server/protocol.ts +++ b/client/src/server/protocol.ts @@ -13,7 +13,9 @@ type Base64 = string export interface Config { name: string - access: 'public' | 'unlisted' + public: boolean + password: string + version: 'ddnet06' | 'teeworlds07' } export interface MapDetail { @@ -74,7 +76,8 @@ export interface AutomapperDiagnostic { export type MapCreation = { version: 'ddnet06' | 'teeworlds07' - access: 'public' | 'unlisted' + public: boolean + password: string } & ({ clone: string } | { @@ -86,6 +89,11 @@ export type MapCreation = { upload: Base64 }) +export interface JoinReq { + name: string, + password: string, +} + export interface MapGetReq { users: undefined cursors: undefined @@ -249,7 +257,7 @@ export interface Send { "delete/automapper": MapDelReq['automapper'] "cursor": Cursor "save": undefined - "join": string + "join": JoinReq "leave": string "create": EditReq['map'] "delete": DeleteReq['map'] diff --git a/client/src/twmap/datafile.ts b/client/src/twmap/datafile.ts index 6776c08..89d1f86 100644 --- a/client/src/twmap/datafile.ts +++ b/client/src/twmap/datafile.ts @@ -92,7 +92,6 @@ export class DataFile { // calculate checksum this.crc = crc32(new Uint8Array(this.data)) - console.info('map crc', this.crc.toString(16)) // we only support datafile version 4 if (this.version != 4) { diff --git a/client/src/ui/index.svelte b/client/src/ui/index.svelte index 17f35d1..512c782 100644 --- a/client/src/ui/index.svelte +++ b/client/src/ui/index.svelte @@ -6,29 +6,41 @@ import storage from '../storage' import { WebSocketServer } from '../server/server' import { server, serverCfg } from './global' - import { serverWsUrl } from '../server/util' + import { serverHttpUrl, serverWsUrl } from '../server/util' + import { queryConfig } from './lib/util' export let url = '' - function joinServer() { + async function joinServer(params: { [name: string]: string }) { const serverCfgs = storage.load('servers') const serverId = storage.load('currentServer') + $serverCfg = serverCfgs[serverId] + console.log('joining server', $serverCfg) const wsUrl = serverWsUrl($serverCfg) $server = new WebSocketServer(wsUrl) - return new Promise((resolve, reject) => { + const connected = new Promise((resolve, reject) => { $server.socket.addEventListener('open', resolve, { once: true }) $server.socket.addEventListener('error', () => reject("Failed to connect to the server"), { once: true }) }) + await connected + let config = await queryConfig(serverHttpUrl($serverCfg), params.mapName) + + if (config.password) { + return prompt("enter password") + } else { + return '' + } } - - + {@const signal = joinServer(params)} + + diff --git a/client/src/ui/lib/dialog.ts b/client/src/ui/lib/dialog.ts index b62df88..0b88300 100644 --- a/client/src/ui/lib/dialog.ts +++ b/client/src/ui/lib/dialog.ts @@ -40,6 +40,16 @@ export function showDialog( }, ...dialog.messages] }) + if (controls !== 'yesno') { + if (type === 'info') { + console.info(`[%c%s%c] ${message}`, 'color: green', 'INFO', 'color: unset') + } else if (type === 'warning') { + console.warn(`[%c%s%c] ${message}`, 'color: orange', 'WARN', 'color: unset') + } else if (type === 'error') { + console.error(`[%c%s%c] ${message}`, 'color: red', 'ERROR', 'color: unset') + } + } + if (controls === 'none') return id else diff --git a/client/src/ui/lib/fence.svelte b/client/src/ui/lib/fence.svelte index 3e21487..11c7f49 100644 --- a/client/src/ui/lib/fence.svelte +++ b/client/src/ui/lib/fence.svelte @@ -1,7 +1,8 @@ - + + DDNet Map Editor + +