use crate::{ app::session::SessionToken, util::pack::{pack_u8, pack_u16}, }; use super::Packet; #[derive(Clone)] pub struct PacketSessionView { pub token:SessionToken, pub join:bool, } impl PacketSessionView { pub fn new() -> Self { Self { token:SessionToken::default(), join:false, } } } impl Packet for PacketSessionView { type Data = Self; fn decode(data:&Vec, index:&mut usize) -> Result { let mut result = Self::new(); if data.len() - *index == 9 { for i in 0..8 { result.token[i] = data[*index]; *index += 1; } result.join = data[*index] != 0; Ok(result) } else { Err(()) } } } #[derive(Clone)] pub struct PacketSessionViewResponse { pub status:u16, pub token:SessionToken, pub player:u8, pub is_complete:bool, } impl PacketSessionViewResponse { pub fn new() -> Self { Self { status:0, token:SessionToken::default(), player:0, is_complete:false, } } } impl Packet for PacketSessionViewResponse { type Data = Self; fn encode(&self) -> Vec { let mut flags = 0u8; flags |= self.is_complete as u8; flags |= (self.player as u8) << 1; [ pack_u16(self.status), pack_u8(flags), self.token.to_vec(), ].concat() } }