Fix repeat connection issue.

This commit is contained in:
yukirij 2024-08-16 17:21:33 -07:00
parent 365f80444d
commit 71879a9efc
3 changed files with 20 additions and 7 deletions

View File

@ -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 {

View File

@ -448,12 +448,7 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
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);
}
}

View File

@ -493,10 +493,10 @@ const SCENES = {
return true;
},
unload() {
INTERFACE.uninit();
MESSAGE_COMPOSE([
PACK.u16(OpCode.SessionLeave),
]);
INTERFACE.uninit();
},
message(code, data) {
switch(code) {