From 71879a9efc3f9f06c8e6f3553e2f452b0ee00faa Mon Sep 17 00:00:00 2001 From: yukirij Date: Fri, 16 Aug 2024 17:21:33 -0700 Subject: [PATCH] Fix repeat connection issue. --- server/src/app/session.rs | 18 ++++++++++++++++++ server/src/manager/data.rs | 7 +------ www/js/scene.js | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/server/src/app/session.rs b/server/src/app/session.rs index a1039d7..aae525b 100644 --- a/server/src/app/session.rs +++ b/server/src/app/session.rs @@ -32,6 +32,24 @@ impl Session { ].concat() } + pub fn add_connection(&mut self, source:u8, id:u32) + { + let connections = match source { + 0 => &mut self.p_dawn.connections, + 1 => &mut self.p_dusk.connections, + _ => &mut self.connections, + }; + + for i in 0..connections.len() { + if connections[i] == id { + connections.remove(i); + break; + } + } + + connections.push(id); + } + pub fn remove_connection(&mut self, source:u8, id:u32) { let connections = match source { diff --git a/server/src/manager/data.rs b/server/src/manager/data.rs index 288d0ee..4b348eb 100644 --- a/server/src/manager/data.rs +++ b/server/src/manager/data.rs @@ -448,12 +448,7 @@ pub async fn thread_system(mut app:App, bus:Bus) if let Some(conn) = app.connections.get_mut(qr.id as usize) { conn.session = Some(session.token); } - match response.mode { - 0 => session.p_dawn.connections.push(qr.id), - 1 => session.p_dusk.connections.push(qr.id), - 2 => session.connections.push(qr.id), - _ => { } - } + session.add_connection(response.mode, qr.id); } } diff --git a/www/js/scene.js b/www/js/scene.js index 2f1910b..a1e6807 100644 --- a/www/js/scene.js +++ b/www/js/scene.js @@ -493,10 +493,10 @@ const SCENES = { return true; }, unload() { - INTERFACE.uninit(); MESSAGE_COMPOSE([ PACK.u16(OpCode.SessionLeave), ]); + INTERFACE.uninit(); }, message(code, data) { switch(code) {