diff --git a/CHANGELOG.md b/CHANGELOG.md index b7d0b9bb4c..268ddf2578 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed a bug that would cause a server crash when a player levelled up or fired + a projectile in very specific circumstances + ## [0.8.0] - 2020-11-28 ### Added diff --git a/server/src/events/entity_creation.rs b/server/src/events/entity_creation.rs index 4c08fa1aa8..7af70eccd4 100644 --- a/server/src/events/entity_creation.rs +++ b/server/src/events/entity_creation.rs @@ -118,12 +118,11 @@ pub fn handle_shoot( ) { let state = server.state_mut(); - let mut pos = state - .ecs() - .read_storage::() - .get(entity) - .expect("Failed to fetch entity") - .0; + let mut pos = if let Some(pos) = state.ecs().read_storage::().get(entity) { + pos.0 + } else { + return; + }; let vel = *dir * speed; diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 1eef4279cf..6914dc30d9 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -721,23 +721,18 @@ pub fn handle_explosion( pub fn handle_level_up(server: &mut Server, entity: EcsEntity, new_level: u32) { let ecs = &server.state.ecs(); - let uids = server.state.ecs().read_storage::(); - let uid = uids + if let Some((uid, pos)) = ecs + .read_storage::() .get(entity) - .expect("Failed to fetch uid component for entity."); - let pos = server - .state - .ecs() - .read_storage::() - .get(entity) - .expect("Failed to fetch position component for the entity.") - .0; - - server.state.notify_players(ServerGeneral::PlayerListUpdate( - PlayerListUpdate::LevelChange(*uid, new_level), - )); - ecs.write_resource::>() - .push(Outcome::LevelUp { pos }); + .copied() + .zip(ecs.read_storage::().get(entity).map(|p| p.0)) + { + ecs.write_resource::>() + .push(Outcome::LevelUp { pos }); + server.state.notify_players(ServerGeneral::PlayerListUpdate( + PlayerListUpdate::LevelChange(uid, new_level), + )); + } } pub fn handle_aura(server: &mut Server, entity: EcsEntity, aura_change: aura::AuraChange) {