From 2c6fd43aa6e32243070962f9690cff69278c0ed8 Mon Sep 17 00:00:00 2001 From: yukirij Date: Sun, 13 Oct 2024 10:56:48 -0700 Subject: [PATCH] Acquire handle from authentication. --- www/js/scene.js | 15 +++++++++++++++ www/js/system.js | 11 ++++++++++- www/js/ui.js | 5 +++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/www/js/scene.js b/www/js/scene.js index 01c6e00..0470495 100644 --- a/www/js/scene.js +++ b/www/js/scene.js @@ -204,6 +204,9 @@ const SCENES = { case Status.Ok: { sessionStorage.setItem("auth", PACK.base64(data.token)); sessionStorage.setItem("auth_secret", PACK.base64(data.secret)); + CONTEXT.Auth = { + handle: data.handle, + }; LOAD_URL(); } break; case Status.Error: { @@ -1044,6 +1047,18 @@ const SCENES = { LOAD(SCENES.Offline); } }, + + UserProfile:class{ + constructor() { + + } + preload() { + + } + load(data) { + + } + }, }; function LOAD(scene, data=null) { diff --git a/www/js/system.js b/www/js/system.js index 34830e6..608f1d8 100644 --- a/www/js/system.js +++ b/www/js/system.js @@ -95,20 +95,29 @@ function MESSAGE(event) { case OpCode.Authenticate: { console.log("RECV Authenticate"); - if(bytes.length - index == 26) { + if(bytes.length - index >= 26) { data = { status:(bytes[2] << 8) + bytes[3], token:new Uint8Array(8), secret:new Uint8Array(16), + handle:"", }; index += 2; + // Token for(let i = 0; i < 8; ++i) { data.token[i] = bytes[index++]; } + + // Secret for(let i = 0; i < 16; ++i) { data.secret[i] = bytes[index++]; } + + // User Handle + result = UNPACK.string(bytes, index, UNPACK.u8); + index = result.index; + data.handle = result.data; } else { console.error("Authenticate packet bad length:" + bytes.length); return; diff --git a/www/js/ui.js b/www/js/ui.js index 045407e..14a1249 100644 --- a/www/js/ui.js +++ b/www/js/ui.js @@ -167,14 +167,15 @@ const UI = { bottom.push(UI.button(LANG("extras"), () => { LOAD(SCENES.Extras) }, page == "extras")); - if(sessionStorage.getItem("auth") !== null) { - bottom.push(UI.button(LANG("account"), () => { })); + if(CONTEXT.Auth !== null) { + bottom.push(UI.button(CONTEXT.Auth.handle, () => { })); bottom.push(UI.button(LANG("logout"), () => { BADGE_UPDATE(false); MESSAGE_COMPOSE([ PACK.u16(OpCode.Deauthenticate), ]); sessionStorage.clear(); + CONTEXT.Auth = null; LOAD_URL(); })); }