use crate::util::pack::{pack_u8, pack_u16}; use super::{ Packet, PacketSessionListResponseRecord, }; #[derive(Clone)] pub struct PacketAccountInfo { pub secret:Vec, } impl PacketAccountInfo { pub fn new() -> Self { Self { secret:Vec::new(), } } } impl Packet for PacketAccountInfo { type Data = Self; fn decode(_data:&Vec, _index:&mut usize) -> Result { Ok(Self::new()) } } #[derive(Clone)] pub struct PacketAccountInfoResponse { pub status:u16, pub handle:String, pub is_online:bool, pub history:Vec, } impl PacketAccountInfoResponse { pub fn new() -> Self { Self { status:0, handle:String::new(), is_online:false, history:Vec::new(), } } } impl Packet for PacketAccountInfoResponse { 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() } }