use crate::util::pack::{pack_u8, pack_u16}; use super::{ Packet, PacketSessionListResponseRecord, }; #[derive(Clone)] pub struct PacketUserInfo { pub handle:String, } impl PacketUserInfo { pub fn new() -> Self { Self { handle:String::new(), } } } impl Packet for PacketUserInfo { type Data = Self; fn decode(_data:&Vec, _index:&mut usize) -> Result { Ok(Self::new()) } } #[derive(Clone)] pub struct PacketUserInfoResponse { pub status:u16, pub handle:String, pub is_online:bool, pub history:Vec, } impl PacketUserInfoResponse { pub fn new() -> Self { Self { status:0, handle:String::new(), is_online:false, history:Vec::new(), } } } impl Packet for PacketUserInfoResponse { type Data = Self; fn encode(&self) -> Vec { let handle_bytes = self.handle.as_bytes().to_vec(); let flags = self.is_online as u16; let mut history_bytes = pack_u16(self.history.len() as u16); for record in &self.history { history_bytes.append(&mut record.encode()); } [ pack_u16(self.status as u16), pack_u16(flags), pack_u8(handle_bytes.len() as u8), handle_bytes, history_bytes, ].concat() } }