Fix spectator update on disconnect; change spectator symbol.

This commit is contained in:
yukirij 2024-10-05 14:04:50 -07:00
parent 6cc65737d9
commit 285987210b
2 changed files with 49 additions and 4 deletions

View File

@ -67,15 +67,55 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
QRPacketData::QDisconn => {
println!("Disconnect: {}", qr.id);
let mut packets = Vec::<QRPacket>::new();
// Uninitialize connection
if if let Some(conn) = app.connections.get(qr.id as usize).cloned() {
// Disassociate session if present
if let Some(session_token) = conn.session {
if let Some(session) = app.sessions.get_mut(&session_token) {
if user_id == Some(session.p_dawn.user) { session.remove_connection(0, qr.id); }
else if user_id == Some(session.p_dusk.user) { session.remove_connection(1, qr.id); }
else { session.remove_connection(2, qr.id); }
if user_id == Some(session.p_dawn.user) {
session.remove_connection(0, qr.id);
if session.p_dawn.connections.len() == 0 {
for (cid, _) in session.get_connections() {
packets.push(QRPacket::new(
cid,
QRPacketData::GameMessage(PacketGameMessage {
data: GameMessageData::Online(1, 0),
}),
));
}
}
}
else if user_id == Some(session.p_dusk.user) {
session.remove_connection(1, qr.id);
if session.p_dusk.connections.len() == 0 {
for (cid, _) in session.get_connections() {
packets.push(QRPacket::new(
cid,
QRPacketData::GameMessage(PacketGameMessage {
data: GameMessageData::Online(2, 0),
}),
));
}
}
}
else {
session.remove_connection(2, qr.id);
// Add user online packets.
for (cid, _) in session.get_connections() {
packets.push(QRPacket::new(
cid,
QRPacketData::GameMessage(PacketGameMessage {
data: GameMessageData::Online(0, session.spectators() as u32),
}),
));
}
}
}
}
@ -116,6 +156,11 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
} else { false } {
app.connections.remove(qr.id as usize).ok();
}
for packet in packets {
app.send_response(packet).await;
}
Some(QRPacket::new(0, QRPacketData::None))
}

View File

@ -710,7 +710,7 @@ const INTERFACE = {
ctx.fillStyle = INTERFACE.Color.Text;
ctx.textBaseline = "bottom";
ctx.textAlign = "right";
ctx.fillText("👁" + INTERFACE_DATA.Session.Client.Spectators.count, width - gui_margin.t, height - gui_margin.t);
ctx.fillText("" + INTERFACE_DATA.Session.Client.Spectators.count, width - gui_margin.t, height - gui_margin.t);
// Game state message
let message = null;