Skip to content

Commit 07ef5bb

Browse files
committed
fix: safe unsigned arithmetic in xp calculations
1 parent 5720c10 commit 07ef5bb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/socket/player/player_xp_listener.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl PlayerXPListener {
2424
let start_multiplier = if level > XP_BEGINNER_ASSIST_MAX {
2525
1
2626
} else {
27-
u32::max(XP_BEGINNER_ASSIST_MAX - level, 1)
27+
u32::max(XP_BEGINNER_ASSIST_MAX.saturating_sub(level), 1)
2828
};
2929
xp * start_multiplier
3030
}
@@ -114,7 +114,7 @@ impl PlayerListener for PlayerXPListener {
114114
context: &mut Self::Context,
115115
held_time: u64
116116
) {
117-
let xp = XP_FLAG_OBJECTIVE + (XP_FLAG_TIME_BOUNS - ((held_time / 1000) as u32));
117+
let xp = XP_FLAG_OBJECTIVE + (XP_FLAG_TIME_BOUNS.saturating_sub((held_time / 1000) as u32));
118118
context.add_xp(server_context, xp, &String::from("Captured flag"), true, false).await;
119119
}
120120

@@ -144,7 +144,7 @@ impl PlayerListener for PlayerXPListener {
144144
contributors: u32,
145145
) {
146146
let others = contributors + 1;
147-
let xp = u32::max(XP_POINT_CAPTURE_MAX - (others * 10), 20);
147+
let xp = u32::max(XP_POINT_CAPTURE_MAX.saturating_sub(others * 10), 20);
148148
context.add_xp(server_context, xp, &String::from("Captured point"), true, false).await;
149149
}
150150

0 commit comments

Comments
 (0)