Skip to content

Commit

Permalink
Fix map keys used by database models
Browse files Browse the repository at this point in the history
BSON requires the map keys as strings
  • Loading branch information
chatasma committed Jun 7, 2024
1 parent 987bc19 commit f283a52
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/database/models/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ pub struct ParticipantStats {
pub messages: PlayerMessages,
pub weapon_kills: HashMap<String, u32>,
pub weapon_deaths: HashMap<String, u32>,
pub killstreaks: HashMap<u32, u32>,
pub killstreaks_ended: HashMap<u32, u32>,
pub killstreaks: HashMap<String, u32>,
pub killstreaks_ended: HashMap<String, u32>,
pub duels: HashMap<String, Duel>
}

Expand Down
9 changes: 5 additions & 4 deletions src/database/models/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ pub struct PlayerStats {
pub records: PlayerRecords,
pub weapon_kills: HashMap<String, u32>,
pub weapon_deaths: HashMap<String, u32>,
pub killstreaks: HashMap<u32, u32>,
pub killstreaks_ended: HashMap<u32, u32>,
pub killstreaks: HashMap<String, u32>,
pub killstreaks_ended: HashMap<String, u32>,
pub achievements: HashMap<String, AchievementData>
}

Expand Down Expand Up @@ -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::<u32>().unwrap_or(0))
.max().unwrap_or(100u32);
let value = self.killstreaks.get(&key.to_string()).unwrap_or(&0).clone();
value
},
}
Expand Down
8 changes: 4 additions & 4 deletions src/socket/participant/participant_stat_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/socket/player/player_gamemode_stat_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
};
}
Expand Down
8 changes: 4 additions & 4 deletions src/socket/player/player_stat_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}

Expand All @@ -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);
};
}

Expand Down

0 comments on commit f283a52

Please sign in to comment.