Skip to content

Commit

Permalink
chore: fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
CosminPerRam committed Nov 8, 2023
1 parent 9cb3d1b commit dd9d7b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
6 changes: 3 additions & 3 deletions crates/lib/src/protocols/unreal2/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,14 @@ impl StringDecoder for Unreal2StringDecoder {
// For UCS-2 strings, some unreal 2 games randomly insert an extra 0x01 here,
// not included in the length. Skip it if present (hopefully this never happens
// legitimately)
if let Some(1) = data[start..].first() {
if let Some(1) = data[start ..].first() {
start += 1;
}
}

// If UCS2 the first byte is the masked length of the string
let result = if ucs2 {
let string_data = &data[start..start + length];
let string_data = &data[start .. start + length];
if string_data.len() != length {
return Err(PacketBad.context("Not enough data in buffer to read string"));
}
Expand Down Expand Up @@ -262,7 +262,7 @@ impl StringDecoder for Unreal2StringDecoder {
length = position + 1;

// Decode as latin1
let (result, _, invalid_sequences) = WINDOWS_1252.decode(&data[0..position]);
let (result, _, invalid_sequences) = WINDOWS_1252.decode(&data[0 .. position]);

if invalid_sequences {
return Err(PacketBad.context("latin1 string contained invalid character(s)"));
Expand Down
44 changes: 11 additions & 33 deletions crates/lib/src/protocols/unreal2/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ impl Players {
}

/// Length of both players and bots.
pub fn total_len(&self) -> usize {
self.players.len() + self.bots.len()
}
pub fn total_len(&self) -> usize { self.players.len() + self.bots.len() }
}

/// Unreal 2 player info.
Expand All @@ -165,17 +163,11 @@ pub struct Player {
}

impl CommonPlayer for Player {
fn name(&self) -> &str {
&self.name
}
fn name(&self) -> &str { &self.name }

fn score(&self) -> Option<i32> {
Some(self.score)
}
fn score(&self) -> Option<i32> { Some(self.score) }

fn as_original(&self) -> GenericPlayer {
GenericPlayer::Unreal2(self)
}
fn as_original(&self) -> GenericPlayer { GenericPlayer::Unreal2(self) }
}

/// Unreal 2 response.
Expand All @@ -188,25 +180,15 @@ pub struct Response {
}

impl CommonResponse for Response {
fn map(&self) -> Option<&str> {
Some(&self.server_info.map)
}
fn map(&self) -> Option<&str> { Some(&self.server_info.map) }

fn name(&self) -> Option<&str> {
Some(&self.server_info.name)
}
fn name(&self) -> Option<&str> { Some(&self.server_info.name) }

fn game_mode(&self) -> Option<&str> {
Some(&self.server_info.game_type)
}
fn game_mode(&self) -> Option<&str> { Some(&self.server_info.game_type) }

fn players_online(&self) -> u32 {
self.server_info.num_players
}
fn players_online(&self) -> u32 { self.server_info.num_players }

fn players_maximum(&self) -> u32 {
self.server_info.max_players
}
fn players_maximum(&self) -> u32 { self.server_info.max_players }

fn players(&self) -> Option<Vec<&dyn crate::protocols::types::CommonPlayer>> {
Some(
Expand All @@ -218,9 +200,7 @@ impl CommonResponse for Response {
)
}

fn as_original(&self) -> GenericResponse {
GenericResponse::Unreal2(self)
}
fn as_original(&self) -> GenericResponse { GenericResponse::Unreal2(self) }
}

/// What data to gather, purely used only with the query function.
Expand Down Expand Up @@ -252,9 +232,7 @@ impl GatheringSettings {
}

impl Default for GatheringSettings {
fn default() -> Self {
GatheringSettings::default()
}
fn default() -> Self { GatheringSettings::default() }
}

impl From<ExtraRequestSettings> for GatheringSettings {
Expand Down

0 comments on commit dd9d7b4

Please sign in to comment.