add bounds check for block modification

This commit is contained in:
Zoey 2024-04-20 00:48:03 -07:00
parent 167b8c6bf9
commit a8decfa3db
No known key found for this signature in database
GPG key ID: 8611B896D1AAFAF2

View file

@ -226,6 +226,17 @@ async fn handle_stream_inner(
} => {
let block_type = if mode == 0x00 { 0 } else { block_type };
let mut data = data.write().await;
// kick players if they attempt to place a block out of bounds
if x.clamp(0, data.level.x_size as i16 - 1) != x
|| y.clamp(0, data.level.y_size as i16 - 1) != y
|| z.clamp(0, data.level.z_size as i16 - 1) != z
{
return Ok(Some(
"Attempt to place block out of bounds".to_string(),
));
}
let new_block_info = BLOCK_INFO.get(&block_type);
let mut cancel = new_block_info.is_none();
let block =