Indiciate history winner and online users.
This commit is contained in:
parent
820a75dfe2
commit
f096fd6f79
@ -336,6 +336,39 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
|
||||
QRPacketData::QAuthRevoke => {
|
||||
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) {
|
||||
match conn.auth {
|
||||
Some(auth) => {
|
||||
@ -346,6 +379,7 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
|
||||
}
|
||||
conn.auth = 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 { 0 }
|
||||
} else { 0 };
|
||||
|
||||
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) {
|
||||
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,
|
||||
player,
|
||||
is_turn,
|
||||
is_complete,
|
||||
});
|
||||
|
||||
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) {
|
||||
response.records.push(PacketUserListData {
|
||||
handle:user.handle.clone(),
|
||||
is_online:user.connection.is_some(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ pub struct PacketSessionListResponseRecord {
|
||||
pub viewers:u32,
|
||||
pub player:u8,
|
||||
pub is_turn:bool,
|
||||
pub is_complete:u8,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -88,6 +89,7 @@ impl Packet for PacketSessionListResponse {
|
||||
let mut flags = 0u32;
|
||||
flags |= record.player as u32;
|
||||
flags |= (record.is_turn as u32) << 2;
|
||||
flags |= (record.is_complete as u32) << 3;
|
||||
|
||||
// Flags
|
||||
chunk.append(&mut pack_u32(flags));
|
||||
|
@ -5,6 +5,7 @@ use super::Packet;
|
||||
#[derive(Clone)]
|
||||
pub struct PacketUserListData {
|
||||
pub handle:String,
|
||||
pub is_online:bool,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -33,6 +34,11 @@ impl Packet for PacketUserListResponse {
|
||||
for record in &self.records {
|
||||
let mut chunk = Vec::new();
|
||||
|
||||
// Flags
|
||||
let mut flags = 0u8;
|
||||
flags |= record.is_online as u8;
|
||||
chunk.append(&mut pack_u8(flags));
|
||||
|
||||
// Handle
|
||||
let mut bytes = record.handle.as_bytes().to_vec();
|
||||
chunk.append(&mut pack_u8(bytes.len() as u8));
|
||||
|
@ -1,4 +1,6 @@
|
||||
span.text-system{color:#909090;}
|
||||
span.c_dawn{color:#ffe082;}
|
||||
span.c_dusk{color:#f6a1bd;}
|
||||
|
||||
button#button-resign.warn {
|
||||
background-color:#471414;
|
||||
|
@ -856,8 +856,13 @@ const SCENES = {
|
||||
callback = callback.bind({handle: data.users[r].handle});
|
||||
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([
|
||||
UI.text(data.users[r].handle),
|
||||
handle,
|
||||
UI.text(LANG("unranked")),
|
||||
buttons,
|
||||
]);
|
||||
|
@ -160,6 +160,7 @@ function MESSAGE(event) {
|
||||
viewers: 0,
|
||||
player: false,
|
||||
is_turn: false,
|
||||
is_complete: 0,
|
||||
};
|
||||
|
||||
// Token
|
||||
@ -177,6 +178,7 @@ function MESSAGE(event) {
|
||||
|
||||
record.player = flags & 3;
|
||||
record.is_turn = ((flags >> 2) & 1) != 0;
|
||||
record.is_complete = ((flags >> 3) & 3);
|
||||
|
||||
// Dawn handle
|
||||
result = UNPACK.string(bytes, index);
|
||||
@ -378,8 +380,15 @@ function MESSAGE(event) {
|
||||
for(let i = 0; i < length; ++i) {
|
||||
let record = {
|
||||
handle:"",
|
||||
is_online:false,
|
||||
};
|
||||
|
||||
// Flags
|
||||
result = UNPACK.u8(bytes, index);
|
||||
index = result.index;
|
||||
let flags = result.data;
|
||||
record.is_online = (flags & 1) == 1;
|
||||
|
||||
// Handle
|
||||
result = UNPACK.string(bytes, index, UNPACK.u8);
|
||||
index = result.index;
|
||||
|
@ -363,6 +363,11 @@ const UI = {
|
||||
let dawn = UI.text(records[r].dawn);
|
||||
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([
|
||||
dawn,
|
||||
dusk,
|
||||
|
Loading…
x
Reference in New Issue
Block a user