Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGruber committed Aug 27, 2024
1 parent 484499b commit b1f893f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
2 changes: 0 additions & 2 deletions rust-toolchain.toml

This file was deleted.

11 changes: 9 additions & 2 deletions src/soeprotocol/ack_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,6 +41,6 @@ impl AckPacket {
pub fn from(mut _rdr: Cursor<&std::vec::Vec<u8>>, opcode: u16) -> AckPacket {
let sequence = _rdr.read_u16::<BigEndian>().unwrap_or_default();

AckPacket { sequence, opcode }
AckPacket::new(sequence, opcode)
}
}
5 changes: 5 additions & 0 deletions src/soeprotocol/data_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ pub struct DataPacket {
data: Vec<u8>,
pub opcode: u16,
pub sequence: u16,
pub bufferable: bool,
pub length: u16,
}
#[wasm_bindgen]
impl DataPacket {
#[wasm_bindgen(constructor)]
pub fn new(data: Vec<u8>, 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 {
Expand Down
15 changes: 8 additions & 7 deletions src/soeprotocol/session_reply_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -73,12 +80,6 @@ impl SessionReplyPacket {
let crc_length = _rdr.read_u8().unwrap_or_default();
let encrypt_method = _rdr.read_u16::<BigEndian>().unwrap_or_default();
let udp_length = _rdr.read_u32::<BigEndian>().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)
}
}
7 changes: 4 additions & 3 deletions src/soeprotocol/soeprotocol_packets_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ impl SoePacketParsed {
_ => None,
}
}
pub fn get_session_reply_packet(&self) -> Option<SessionReplyPacket> {
match &self.packet {
SoePacket::SessionReplyPacket(packet) => Some(packet.clone()),
// TODO: remove all clones like that
pub fn get_session_reply_packet(self) -> Option<SessionReplyPacket> {
match self.packet {
SoePacket::SessionReplyPacket(packet) => Some(packet),
_ => None,
}
}
Expand Down

0 comments on commit b1f893f

Please sign in to comment.