Skip to content

Commit

Permalink
fix: IC-82 - fixed large packet reading (#51)
Browse files Browse the repository at this point in the history
* fix: IC-82 - fixed long packet reading; refactoring

* fix: IC-82 - updated idewave_packet version and .gitignore
  • Loading branch information
sergio-ivanuzzo authored Feb 16, 2024
1 parent 08dccd8 commit 4fecfc8
Show file tree
Hide file tree
Showing 38 changed files with 286 additions and 433 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/target
/files
**/files
**/target

.env
.idea
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ thiserror = "1.0"
anyhow = "1.0"
cfg-if = { version = "1.0.0", features = [] }
async-broadcast = "0.7.0"
idewave_packet = "0.1.0"
idewave_packet = "1.0.0"

[dev-dependencies]
rusty-hook = "0.11.2"
Expand Down
4 changes: 1 addition & 3 deletions src/primary/client/auth/check_proof_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ impl PacketHandler for Handler {
async fn handle(&mut self, input: &mut HandlerInput) -> HandlerResult {
let mut response = Vec::new();

let (Income { code, .. }, _) = Income::from_binary(
input.data.as_ref().unwrap()
)?;
let (Income { code, .. }, _) = Income::from_binary(&input.data)?;

if code != AuthLogonResult::AUTH_LOGON_SUCCESS {
let message = match code {
Expand Down
4 changes: 2 additions & 2 deletions src/primary/client/auth/get_realmlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ impl PacketHandler for Handler {
async fn handle(&mut self, input: &mut HandlerInput) -> HandlerResult {
let mut response = Vec::new();

let (Income { realms, .. }, json) = Income::from_binary(input.data.as_ref().unwrap())?;
let (Income { realms, .. }, json) = Income::from_binary(&input.data)?;

response.push(HandlerOutput::ResponseMessage(
Opcode::get_server_opcode_name(input.opcode.unwrap()),
Opcode::get_server_opcode_name(input.opcode),
Some(json),
));

Expand Down
4 changes: 2 additions & 2 deletions src/primary/client/auth/login_challenge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::{Result as AnyResult};

use crate::primary::client::Opcode;
use crate::primary::macros::with_opcode;
use crate::primary::types::{PacketOutcome, TerminatedString};
use crate::primary::types::{OutcomePacket, TerminatedString};

with_opcode! {
@login_opcode(Opcode::LOGIN_CHALLENGE)
Expand All @@ -28,7 +28,7 @@ with_opcode! {
const PACKET_LENGTH_WITHOUT_ACCOUNT: u16 = 30;

// TODO: need to refactor endianness converting for strings
pub fn handler(account: &str) -> AnyResult<PacketOutcome> {
pub fn handler(account: &str) -> AnyResult<OutcomePacket> {
let account_length = account.chars().count() as u8;
let packet_size = PACKET_LENGTH_WITHOUT_ACCOUNT + account_length as u16;

Expand Down
6 changes: 2 additions & 4 deletions src/primary/client/auth/login_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ impl PacketHandler for Handler {
async fn handle(&mut self, input: &mut HandlerInput) -> HandlerResult {
let mut response = Vec::new();

let (Income { n, g, server_ephemeral, salt, .. }, json) = Income::from_binary(
input.data.as_ref().unwrap()
)?;
let (Income { n, g, server_ephemeral, salt, .. }, json) = Income::from_binary(&input.data)?;

response.push(HandlerOutput::ResponseMessage(
Opcode::get_server_opcode_name(input.opcode.unwrap()),
Opcode::get_server_opcode_name(input.opcode),
Some(json),
));

Expand Down
9 changes: 1 addition & 8 deletions src/primary/client/auth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use std::io::{Cursor};
use byteorder::{ReadBytesExt};

mod check_proof_code;
mod connect_to_realm;
mod get_realmlist;
Expand All @@ -20,23 +17,19 @@ pub struct AuthProcessor;

impl Processor for AuthProcessor {
fn process_input(input: &mut HandlerInput) -> ProcessorResult {
let mut reader = Cursor::new(input.data.as_ref().unwrap());
let opcode = reader.read_u8().unwrap();
let opcode = input.opcode as u8;

let handlers: ProcessorResult = match opcode {
Opcode::LOGIN_CHALLENGE => {
input.opcode = Some(opcode as u16);
vec![
Box::new(check_proof_code::Handler),
Box::new(login_proof::Handler),
]
},
Opcode::LOGIN_PROOF => {
input.opcode = Some(opcode as u16);
vec![Box::new(request_realmlist::Handler)]
},
Opcode::REALM_LIST => {
input.opcode = Some(opcode as u16);
vec![
Box::new(get_realmlist::Handler),
Box::new(connect_to_realm::Handler),
Expand Down
4 changes: 2 additions & 2 deletions src/primary/client/chat/log_chat_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ impl PacketHandler for Handler {
message,
message_type,
..
}, json) = Income::from_binary(input.data.as_ref().unwrap())?;
}, json) = Income::from_binary(&input.data)?;

response.push(HandlerOutput::ResponseMessage(
Opcode::get_server_opcode_name(input.opcode.unwrap()),
Opcode::get_server_opcode_name(input.opcode),
Some(json),
));

Expand Down
10 changes: 1 addition & 9 deletions src/primary/client/chat/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use std::io::Cursor;
use byteorder::{LittleEndian, ReadBytesExt};

pub mod globals;
mod log_chat_message;
mod query_unknown_player;
Expand All @@ -14,19 +11,14 @@ pub struct ChatProcessor;

impl Processor for ChatProcessor {
fn process_input(input: &mut HandlerInput) -> ProcessorResult {
let mut reader = Cursor::new(input.data.as_ref().unwrap()[2..].to_vec());
let opcode = reader.read_u16::<LittleEndian>().unwrap();

let handlers: ProcessorResult = match opcode {
let handlers: ProcessorResult = match input.opcode {
Opcode::SMSG_MESSAGECHAT => {
input.opcode = Some(opcode);
vec![
Box::new(query_unknown_player::Handler),
Box::new(log_chat_message::Handler),
]
},
Opcode::SMSG_TEXT_EMOTE => {
input.opcode = Some(opcode);
vec![]
},
_ => vec![]
Expand Down
4 changes: 2 additions & 2 deletions src/primary/client/chat/query_unknown_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ impl PacketHandler for Handler {
async fn handle(&mut self, input: &mut HandlerInput) -> HandlerResult {
let mut response = Vec::new();

let (Income { sender_guid, .. }, json) = Income::from_binary(input.data.as_ref().unwrap())?;
let (Income { sender_guid, .. }, json) = Income::from_binary(&input.data)?;

response.push(HandlerOutput::ResponseMessage(
Opcode::get_server_opcode_name(input.opcode.unwrap()),
Opcode::get_server_opcode_name(input.opcode),
Some(json),
));

Expand Down
Loading

0 comments on commit 4fecfc8

Please sign in to comment.