Fix spectator update on disconnect; change spectator symbol.
This commit is contained in:
parent
6cc65737d9
commit
285987210b
@ -67,15 +67,55 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
|
|||||||
QRPacketData::QDisconn => {
|
QRPacketData::QDisconn => {
|
||||||
println!("Disconnect: {}", qr.id);
|
println!("Disconnect: {}", qr.id);
|
||||||
|
|
||||||
|
let mut packets = Vec::<QRPacket>::new();
|
||||||
|
|
||||||
// Uninitialize connection
|
// Uninitialize connection
|
||||||
if if let Some(conn) = app.connections.get(qr.id as usize).cloned() {
|
if if let Some(conn) = app.connections.get(qr.id as usize).cloned() {
|
||||||
|
|
||||||
// Disassociate session if present
|
// Disassociate session if present
|
||||||
if let Some(session_token) = conn.session {
|
if let Some(session_token) = conn.session {
|
||||||
if let Some(session) = app.sessions.get_mut(&session_token) {
|
if let Some(session) = app.sessions.get_mut(&session_token) {
|
||||||
if user_id == Some(session.p_dawn.user) { session.remove_connection(0, qr.id); }
|
if user_id == Some(session.p_dawn.user) {
|
||||||
else if user_id == Some(session.p_dusk.user) { session.remove_connection(1, qr.id); }
|
session.remove_connection(0, qr.id);
|
||||||
else { session.remove_connection(2, 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 } {
|
} else { false } {
|
||||||
app.connections.remove(qr.id as usize).ok();
|
app.connections.remove(qr.id as usize).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for packet in packets {
|
||||||
|
app.send_response(packet).await;
|
||||||
|
}
|
||||||
|
|
||||||
Some(QRPacket::new(0, QRPacketData::None))
|
Some(QRPacket::new(0, QRPacketData::None))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,7 +710,7 @@ const INTERFACE = {
|
|||||||
ctx.fillStyle = INTERFACE.Color.Text;
|
ctx.fillStyle = INTERFACE.Color.Text;
|
||||||
ctx.textBaseline = "bottom";
|
ctx.textBaseline = "bottom";
|
||||||
ctx.textAlign = "right";
|
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
|
// Game state message
|
||||||
let message = null;
|
let message = null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user