diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index 27ae62c..0000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "1.74.1" diff --git a/src/soeprotocol/ack_packet.rs b/src/soeprotocol/ack_packet.rs index 8783334..cbcf6cb 100644 --- a/src/soeprotocol/ack_packet.rs +++ b/src/soeprotocol/ack_packet.rs @@ -9,12 +9,19 @@ use wasm_bindgen::prelude::*; pub struct AckPacket { pub opcode: u16, pub sequence: u16, + pub bufferable: bool, + pub length: u16, } #[wasm_bindgen] impl AckPacket { #[wasm_bindgen(constructor)] pub fn new(opcode: u16, sequence: u16) -> Self { - Self { opcode, sequence } + Self { + opcode, + sequence, + bufferable: true, + length: 4, + } } pub fn get_sequence(&self) -> u16 { self.sequence @@ -34,6 +41,6 @@ impl AckPacket { pub fn from(mut _rdr: Cursor<&std::vec::Vec>, opcode: u16) -> AckPacket { let sequence = _rdr.read_u16::().unwrap_or_default(); - AckPacket { sequence, opcode } + AckPacket::new(sequence, opcode) } } diff --git a/src/soeprotocol/data_packet.rs b/src/soeprotocol/data_packet.rs index 809630d..ee0bb11 100644 --- a/src/soeprotocol/data_packet.rs +++ b/src/soeprotocol/data_packet.rs @@ -11,15 +11,20 @@ pub struct DataPacket { data: Vec, pub opcode: u16, pub sequence: u16, + pub bufferable: bool, + pub length: u16, } #[wasm_bindgen] impl DataPacket { #[wasm_bindgen(constructor)] pub fn new(data: Vec, sequence: u16, opcode: u16) -> Self { + let length = 4 + data.len() as u16; Self { data, sequence, opcode, + bufferable: true, + length, } } pub fn get_sequence(&self) -> u16 { diff --git a/src/soeprotocol/session_reply_packet.rs b/src/soeprotocol/session_reply_packet.rs index c7915da..d000848 100644 --- a/src/soeprotocol/session_reply_packet.rs +++ b/src/soeprotocol/session_reply_packet.rs @@ -8,12 +8,15 @@ use crate::soeprotocol::protocol::SoeOpcode; #[wasm_bindgen] #[derive(Serialize, Deserialize, Debug, Clone)] pub struct SessionReplyPacket { + pub opcode: u16, pub session_id: u32, pub crc_seed: u32, pub crc_length: u8, // TODO: use the EncryptionMethod enum pub encrypt_method: u16, pub udp_length: u32, + pub bufferable: bool, + pub length: u16, } #[wasm_bindgen] impl SessionReplyPacket { @@ -25,12 +28,16 @@ impl SessionReplyPacket { encrypt_method: u16, udp_length: u32, ) -> Self { + let length = 15 as u16; Self { + opcode: SoeOpcode::SessionReply as u16, session_id, crc_seed, crc_length, encrypt_method, udp_length, + bufferable: false, + length, } } pub fn get_session_id(&self) -> u32 { @@ -73,12 +80,6 @@ impl SessionReplyPacket { let crc_length = _rdr.read_u8().unwrap_or_default(); let encrypt_method = _rdr.read_u16::().unwrap_or_default(); let udp_length = _rdr.read_u32::().unwrap_or_default(); - SessionReplyPacket { - session_id, - crc_seed, - crc_length, - encrypt_method, - udp_length, - } + SessionReplyPacket::new(session_id, crc_seed, crc_length, encrypt_method, udp_length) } } diff --git a/src/soeprotocol/soeprotocol_packets_structs.rs b/src/soeprotocol/soeprotocol_packets_structs.rs index 1f10495..c6cb35d 100644 --- a/src/soeprotocol/soeprotocol_packets_structs.rs +++ b/src/soeprotocol/soeprotocol_packets_structs.rs @@ -50,9 +50,10 @@ impl SoePacketParsed { _ => None, } } - pub fn get_session_reply_packet(&self) -> Option { - match &self.packet { - SoePacket::SessionReplyPacket(packet) => Some(packet.clone()), + // TODO: remove all clones like that + pub fn get_session_reply_packet(self) -> Option { + match self.packet { + SoePacket::SessionReplyPacket(packet) => Some(packet), _ => None, } }