Skip to content

Commit

Permalink
🚑️ Fix for 64-bit player IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed Jan 29, 2024
1 parent 581192b commit 87beaf2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
6 changes: 2 additions & 4 deletions src/models/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ fn assert_magic<T: Into<u32> + PartialEq>(actual: T, expected: T) -> Result {
#[inline]
fn read_length_delimited(reader: &mut impl Read) -> Result<Vec<u8>> {
let length = reader.read_u8()? as usize;
let mut buffer = Vec::new();
buffer.resize(length, 0);
let mut buffer = vec![0; length];
reader.read_exact(&mut buffer)?;
Ok(buffer)
}
Expand All @@ -76,8 +75,7 @@ fn read_string(reader: &mut impl Read) -> Result<String> {

#[inline]
fn read_pickled<T: DeserializeOwned>(reader: &mut impl Read, length: usize) -> Result<T> {
let mut buffer = Vec::new();
buffer.resize(length, 0);
let mut buffer = vec![0; length];
reader.read_exact(&mut buffer)?;
Ok(serde_pickle::from_slice(&buffer, Default::default())?)
}
Expand Down
6 changes: 3 additions & 3 deletions src/models/data/base_player_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct BasePlayerCreate {
#[serde(default, rename(deserialize = "playersBattleCategoriesIds"))]
pub players_battle_categories_ids: Option<HashMap<u32, (u8, u32)>>,
pub players_battle_categories_ids: Option<HashMap<u64, (u8, u32)>>,

#[serde(rename(deserialize = "battleLevel"))]
pub battle_level: u8,
Expand Down Expand Up @@ -34,10 +34,10 @@ pub struct BasePlayerCreate {
pub average_mm_ratings: Option<Vec<Option<f64>>>,

#[serde(default, rename(deserialize = "playerWaitTimes"))]
pub player_wait_times: Option<HashMap<u32, f64>>,
pub player_wait_times: Option<HashMap<u64, f64>>,

#[serde(rename(deserialize = "accountDatabaseIds"))]
pub account_database_ids: Option<Vec<u32>>,
pub account_database_ids: Option<Vec<u64>>,

#[serde(default, rename(deserialize = "turboBattlesStats"))]
pub turbo_battles_statistics: Option<TurboBattlesStatistics>,
Expand Down
7 changes: 4 additions & 3 deletions src/models/data/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ impl Packet {
///
/// Parsed packet, or [`None`], when no packets are left.
pub fn from_reader(reader: &mut impl Read) -> Result<Option<Self>> {
let Ok(length) = reader.read_u32::<LittleEndian>() else { return Ok(None) };
let Ok(length) = reader.read_u32::<LittleEndian>() else {
return Ok(None);
};
let type_ = reader.read_u32::<LittleEndian>()?;
let clock_secs = reader.read_f32::<LittleEndian>()?;
let raw_payload = Self::read_raw_payload(reader, length as usize)?;
Expand All @@ -57,8 +59,7 @@ impl Packet {
}

fn read_raw_payload(reader: &mut impl Read, length: usize) -> Result<Vec<u8>> {
let mut buffer = Vec::new();
buffer.resize(length, 0);
let mut buffer = vec![0; length];
reader.read_exact(&mut buffer)?;
Ok(buffer)
}
Expand Down

0 comments on commit 87beaf2

Please sign in to comment.