Removed panic sources from server event handling

This commit is contained in:
Joshua Barretto 2020-12-07 12:28:29 +00:00
parent 115c09120d
commit fe7f73bf62
3 changed files with 19 additions and 22 deletions

View File

@ -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

View File

@ -118,12 +118,11 @@ pub fn handle_shoot(
) {
let state = server.state_mut();
let mut pos = state
.ecs()
.read_storage::<Pos>()
.get(entity)
.expect("Failed to fetch entity")
.0;
let mut pos = if let Some(pos) = state.ecs().read_storage::<Pos>().get(entity) {
pos.0
} else {
return;
};
let vel = *dir * speed;

View File

@ -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::<Uid>();
let uid = uids
if let Some((uid, pos)) = ecs
.read_storage::<Uid>()
.get(entity)
.expect("Failed to fetch uid component for entity.");
let pos = server
.state
.ecs()
.read_storage::<Pos>()
.get(entity)
.expect("Failed to fetch position component for the entity.")
.0;
server.state.notify_players(ServerGeneral::PlayerListUpdate(
PlayerListUpdate::LevelChange(*uid, new_level),
));
.copied()
.zip(ecs.read_storage::<Pos>().get(entity).map(|p| p.0))
{
ecs.write_resource::<Vec<Outcome>>()
.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) {