Indiciate history winner and online users.

This commit is contained in:
yukirij 2024-10-01 11:45:07 -07:00
parent 820a75dfe2
commit f096fd6f79
7 changed files with 68 additions and 1 deletions

View File

@ -336,6 +336,39 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
QRPacketData::QAuthRevoke => { QRPacketData::QAuthRevoke => {
println!("Request: Auth Revoke"); println!("Request: Auth Revoke");
// Remove connection from chain.
if let Some(conn) = app.connections.get(qr.id as usize).cloned() {
if let Some(auth_id) = conn.auth {
if let Some(auth) = app.auths.get(&auth_id).cloned() {
// Update user connection reference.
if let Some(user) = app.get_user_by_id_mut(auth.user) {
if Some(qr.id) == user.connection {
// Set connection to next if exists.
if conn.next != qr.id {
user.connection = Some(conn.next);
} else {
user.connection = None;
}
}
}
// Link prev and next connections.
if conn.next != qr.id {
if let Some(prev_conn) = app.connections.get_mut(conn.prev as usize) {
prev_conn.next = conn.next;
}
if let Some(next_conn) = app.connections.get_mut(conn.next as usize) {
next_conn.prev = conn.prev;
}
}
}
}
}
// Remove authentication from connection.
if let Some(conn) = app.connections.get_mut(qr.id as usize) { if let Some(conn) = app.connections.get_mut(qr.id as usize) {
match conn.auth { match conn.auth {
Some(auth) => { Some(auth) => {
@ -346,6 +379,7 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
} }
conn.auth = None; conn.auth = None;
} }
Some(QRPacket::new(0, QRPacketData::None)) Some(QRPacket::new(0, QRPacketData::None))
} }
@ -376,7 +410,9 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
else if Some(session.p_dusk.user) == user_id { 2 } else if Some(session.p_dusk.user) == user_id { 2 }
else { 0 } else { 0 }
} else { 0 }; } else { 0 };
let is_turn = player != 0 && (session.game.turn & 1) == player as u16 - 1; let is_turn = player != 0 && (session.game.turn & 1) == player as u16 - 1;
let is_complete = (session.game.is_complete() as u8) * (((session.game.turn & 1) == 0) as u8 + 1);
let dawn_handle = if let Some(user) = app.get_user_by_id(session.p_dawn.user) { let dawn_handle = if let Some(user) = app.get_user_by_id(session.p_dawn.user) {
user.handle.clone() user.handle.clone()
@ -397,6 +433,7 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
viewers:session.connections.len() as u32, viewers:session.connections.len() as u32,
player, player,
is_turn, is_turn,
is_complete,
}); });
count += 1; count += 1;
@ -739,6 +776,7 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
if let Some(user) = app.get_user_by_id(uid) { if let Some(user) = app.get_user_by_id(uid) {
response.records.push(PacketUserListData { response.records.push(PacketUserListData {
handle:user.handle.clone(), handle:user.handle.clone(),
is_online:user.connection.is_some(),
}); });
} }
} }

View File

@ -61,6 +61,7 @@ pub struct PacketSessionListResponseRecord {
pub viewers:u32, pub viewers:u32,
pub player:u8, pub player:u8,
pub is_turn:bool, pub is_turn:bool,
pub is_complete:u8,
} }
#[derive(Clone)] #[derive(Clone)]
@ -88,6 +89,7 @@ impl Packet for PacketSessionListResponse {
let mut flags = 0u32; let mut flags = 0u32;
flags |= record.player as u32; flags |= record.player as u32;
flags |= (record.is_turn as u32) << 2; flags |= (record.is_turn as u32) << 2;
flags |= (record.is_complete as u32) << 3;
// Flags // Flags
chunk.append(&mut pack_u32(flags)); chunk.append(&mut pack_u32(flags));

View File

@ -5,6 +5,7 @@ use super::Packet;
#[derive(Clone)] #[derive(Clone)]
pub struct PacketUserListData { pub struct PacketUserListData {
pub handle:String, pub handle:String,
pub is_online:bool,
} }
#[derive(Clone)] #[derive(Clone)]
@ -33,6 +34,11 @@ impl Packet for PacketUserListResponse {
for record in &self.records { for record in &self.records {
let mut chunk = Vec::new(); let mut chunk = Vec::new();
// Flags
let mut flags = 0u8;
flags |= record.is_online as u8;
chunk.append(&mut pack_u8(flags));
// Handle // Handle
let mut bytes = record.handle.as_bytes().to_vec(); let mut bytes = record.handle.as_bytes().to_vec();
chunk.append(&mut pack_u8(bytes.len() as u8)); chunk.append(&mut pack_u8(bytes.len() as u8));

View File

@ -1,4 +1,6 @@
span.text-system{color:#909090;} span.text-system{color:#909090;}
span.c_dawn{color:#ffe082;}
span.c_dusk{color:#f6a1bd;}
button#button-resign.warn { button#button-resign.warn {
background-color:#471414; background-color:#471414;

View File

@ -856,8 +856,13 @@ const SCENES = {
callback = callback.bind({handle: data.users[r].handle}); callback = callback.bind({handle: data.users[r].handle});
buttons.push(UI.button(LANG("challenge"), callback)); buttons.push(UI.button(LANG("challenge"), callback));
let handle = UI.text(data.users[r].handle);
if(!data.users[r].is_online) {
handle = UI.span([handle], "text-system");
}
rows.push([ rows.push([
UI.text(data.users[r].handle), handle,
UI.text(LANG("unranked")), UI.text(LANG("unranked")),
buttons, buttons,
]); ]);

View File

@ -160,6 +160,7 @@ function MESSAGE(event) {
viewers: 0, viewers: 0,
player: false, player: false,
is_turn: false, is_turn: false,
is_complete: 0,
}; };
// Token // Token
@ -177,6 +178,7 @@ function MESSAGE(event) {
record.player = flags & 3; record.player = flags & 3;
record.is_turn = ((flags >> 2) & 1) != 0; record.is_turn = ((flags >> 2) & 1) != 0;
record.is_complete = ((flags >> 3) & 3);
// Dawn handle // Dawn handle
result = UNPACK.string(bytes, index); result = UNPACK.string(bytes, index);
@ -378,8 +380,15 @@ function MESSAGE(event) {
for(let i = 0; i < length; ++i) { for(let i = 0; i < length; ++i) {
let record = { let record = {
handle:"", handle:"",
is_online:false,
}; };
// Flags
result = UNPACK.u8(bytes, index);
index = result.index;
let flags = result.data;
record.is_online = (flags & 1) == 1;
// Handle // Handle
result = UNPACK.string(bytes, index, UNPACK.u8); result = UNPACK.string(bytes, index, UNPACK.u8);
index = result.index; index = result.index;

View File

@ -363,6 +363,11 @@ const UI = {
let dawn = UI.text(records[r].dawn); let dawn = UI.text(records[r].dawn);
let dusk = UI.text(records[r].dusk); let dusk = UI.text(records[r].dusk);
switch(records[r].is_complete) {
case 1: dawn = UI.span([dawn], "c_dawn"); break;
case 2: dusk = UI.span([dusk], "c_dusk"); break;
}
rows.push([ rows.push([
dawn, dawn,
dusk, dusk,