From f283a52a9dfe542d0d494bacd2e8d0b37d7e7443 Mon Sep 17 00:00:00 2001 From: chatt Date: Thu, 6 Jun 2024 23:02:45 -0500 Subject: [PATCH] Fix map keys used by database models BSON requires the map keys as strings --- src/database/models/participant.rs | 4 ++-- src/database/models/player.rs | 9 +++++---- src/socket/participant/participant_stat_listener.rs | 8 ++++---- src/socket/player/player_gamemode_stat_listener.rs | 4 ++-- src/socket/player/player_stat_listener.rs | 8 ++++---- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/database/models/participant.rs b/src/database/models/participant.rs index 96a6d91..9960820 100644 --- a/src/database/models/participant.rs +++ b/src/database/models/participant.rs @@ -98,8 +98,8 @@ pub struct ParticipantStats { pub messages: PlayerMessages, pub weapon_kills: HashMap, pub weapon_deaths: HashMap, - pub killstreaks: HashMap, - pub killstreaks_ended: HashMap, + pub killstreaks: HashMap, + pub killstreaks_ended: HashMap, pub duels: HashMap } diff --git a/src/database/models/player.rs b/src/database/models/player.rs index bff60f2..1fcc369 100644 --- a/src/database/models/player.rs +++ b/src/database/models/player.rs @@ -109,8 +109,8 @@ pub struct PlayerStats { pub records: PlayerRecords, pub weapon_kills: HashMap, pub weapon_deaths: HashMap, - pub killstreaks: HashMap, - pub killstreaks_ended: HashMap, + pub killstreaks: HashMap, + pub killstreaks_ended: HashMap, pub achievements: HashMap } @@ -150,8 +150,9 @@ impl PlayerStats { ScoreType::WoolDefends => self.objectives.wool_defends, ScoreType::ControlPointCaptures => self.objectives.control_point_captures, ScoreType::HighestKillstreak => { - let key = self.killstreaks.keys().max().unwrap_or(&100); - let value = self.killstreaks.get(key).unwrap_or(&0).clone(); + let key = self.killstreaks.keys().map(|ksstr| ksstr.parse::().unwrap_or(0)) + .max().unwrap_or(100u32); + let value = self.killstreaks.get(&key.to_string()).unwrap_or(&0).clone(); value }, } diff --git a/src/socket/participant/participant_stat_listener.rs b/src/socket/participant/participant_stat_listener.rs index df762d2..0e31c52 100644 --- a/src/socket/participant/participant_stat_listener.rs +++ b/src/socket/participant/participant_stat_listener.rs @@ -92,8 +92,8 @@ impl PlayerListener for ParticipantStatListener { context: &mut Self::Context, amount: u32 ) { - let current_amount = context.stats.killstreaks.get(&amount).unwrap_or(&0).to_owned(); - context.stats.killstreaks.insert(amount, current_amount + 1); + let current_amount = context.stats.killstreaks.get(&amount.to_string()).unwrap_or(&0).to_owned(); + context.stats.killstreaks.insert(amount.to_string(), current_amount + 1); } async fn on_killstreak_end( @@ -103,8 +103,8 @@ impl PlayerListener for ParticipantStatListener { context: &mut Self::Context, amount: u32 ) { - let current_amount = context.stats.killstreaks_ended.get(&amount).unwrap_or(&0).to_owned(); - context.stats.killstreaks_ended.insert(amount, current_amount + 1); + let current_amount = context.stats.killstreaks_ended.get(&amount.to_string()).unwrap_or(&0).to_owned(); + context.stats.killstreaks_ended.insert(amount.to_string(), current_amount + 1); } async fn on_party_join( diff --git a/src/socket/player/player_gamemode_stat_listener.rs b/src/socket/player/player_gamemode_stat_listener.rs index ff4ef93..041bc18 100644 --- a/src/socket/player/player_gamemode_stat_listener.rs +++ b/src/socket/player/player_gamemode_stat_listener.rs @@ -84,8 +84,8 @@ impl PlayerListener for PlayerGamemodeStatListener { let mut default_gamemode_stats = GamemodeStats::default(); let stats = context.gamemode_stats.get_mut(&gamemode).unwrap_or(&mut default_gamemode_stats); - let prev_amount = stats.killstreaks.get(&amount).unwrap_or(&0).to_owned(); - stats.killstreaks.insert(amount, prev_amount + 1); + let prev_amount = stats.killstreaks.get(&amount.to_string()).unwrap_or(&0).to_owned(); + stats.killstreaks.insert(amount.to_string(), prev_amount + 1); }; }; } diff --git a/src/socket/player/player_stat_listener.rs b/src/socket/player/player_stat_listener.rs index 27b42b7..53a5c33 100644 --- a/src/socket/player/player_stat_listener.rs +++ b/src/socket/player/player_stat_listener.rs @@ -89,8 +89,8 @@ impl PlayerListener for PlayerStatListener { return; }; - let current_killstreak_count = context.stats.killstreaks.get(&amount).unwrap_or(&0).to_owned(); - context.stats.killstreaks.insert(amount, current_killstreak_count + 1); + let current_killstreak_count = context.stats.killstreaks.get(&amount.to_string()).unwrap_or(&0).to_owned(); + context.stats.killstreaks.insert(amount.to_string(), current_killstreak_count + 1); }; } @@ -106,8 +106,8 @@ impl PlayerListener for PlayerStatListener { return; }; - let current_killstreak_count = context.stats.killstreaks_ended.get(&amount).unwrap_or(&0).to_owned(); - context.stats.killstreaks_ended.insert(amount, current_killstreak_count + 1); + let current_killstreak_count = context.stats.killstreaks_ended.get(&amount.to_string()).unwrap_or(&0).to_owned(); + context.stats.killstreaks_ended.insert(amount.to_string(), current_killstreak_count + 1); }; }