diff --git a/common/src/cmd.rs b/common/src/cmd.rs index 1131284c96..ea56970e7b 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -534,7 +534,7 @@ impl ServerChatCommand { ), ServerChatCommand::Campfire => cmd(vec![], "Spawns a campfire", Some(Admin)), ServerChatCommand::ClearPersistedTerrain => cmd( - vec![Integer("radius", 6, Required)], + vec![Integer("chunk_radius", 6, Required)], "Clears nearby persisted terrain", Some(Admin), ), @@ -723,7 +723,7 @@ impl ServerChatCommand { Some(Admin), ), ServerChatCommand::ReloadChunks => cmd( - vec![Integer("radius", 6, Optional)], + vec![Integer("chunk_radius", 6, Optional)], "Reloads chunks loaded on the server", Some(Admin), ), diff --git a/server/src/cmd.rs b/server/src/cmd.rs index c8c0a52e74..65cf2841f7 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -2023,7 +2023,8 @@ fn handle_clear_persisted_terrain( let Some(radius) = parse_cmd_args!(args, i32) else { return Err(Content::Plain(action.help_string())); }; - let radius = radius.min(64); + // Clamp the radius to prevent accidentally passing too large radiuses + let radius = radius.clamp(0, 64); let pos = position(server, target, "target")?; let chunk_key = server.state.terrain().pos_key(pos.0.as_()); @@ -3742,7 +3743,7 @@ fn handle_reload_chunks( let radius = parse_cmd_args!(args, i32); let pos = position(server, target, "target")?.0; - let removed = reload_chunks_inner(server, pos, radius.map(|radius| radius.min(64))); + let removed = reload_chunks_inner(server, pos, radius.map(|radius| radius.clamp(0, 64))); server.notify_client( client, diff --git a/server/src/terrain_persistence.rs b/server/src/terrain_persistence.rs index 7965b8aa17..d48dbf993e 100644 --- a/server/src/terrain_persistence.rs +++ b/server/src/terrain_persistence.rs @@ -246,9 +246,6 @@ impl Chunk { } /// LRU limiter that limits by the number of blocks -/// -/// > **Warning**: Make sure to call [`add_block`] and [`remove_block`] when -/// > performing direct mutations to a chunk struct ByBlockLimiter { /// Maximum number of blocks that can be contained block_limit: usize, @@ -288,7 +285,9 @@ impl Limiter, Chunk> for ByBlockLimiter { ) -> bool { let old_size = old_chunk.len() as isize; // I assume chunks are never larger than a few thousand blocks anyways, cast should be OK let new_size = new_chunk.len() as isize; - let new_total = self.counted_blocks.wrapping_add_signed(new_size - old_size); + let new_total = self + .counted_blocks + .saturating_add_signed(new_size - old_size); if new_total > self.block_limit { false