From 8ec0a06bbe76a1d46372a9224c9d1c060b30e78d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Korg=C3=B3l?= Date: Mon, 12 Aug 2019 18:11:06 +0200 Subject: [PATCH] Fix spawn command, properly search for admins --- common/src/npc.rs | 3 +-- server/src/lib.rs | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/common/src/npc.rs b/common/src/npc.rs index b896e6f1d3..3f95c17cca 100644 --- a/common/src/npc.rs +++ b/common/src/npc.rs @@ -36,8 +36,7 @@ impl FromStr for NpcKind { } lazy_static! { - static ref NPC_NAMES_JSON: Arc = - assets::load_expect("common/npc_names.json"); + static ref NPC_NAMES_JSON: Arc = assets::load_expect("common.npc_names"); } pub fn get_npc_name(npc_type: NpcKind) -> String { diff --git a/server/src/lib.rs b/server/src/lib.rs index 896920f424..ea2f090418 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -193,7 +193,7 @@ impl Server { let spawn_point = state.ecs().read_resource::().0; state.write_component(entity, body); - state.write_component(entity, comp::Stats::new(name.to_string())); + state.write_component(entity, comp::Stats::new(name)); state.write_component(entity, comp::Controller::default()); state.write_component(entity, comp::Pos(spawn_point)); state.write_component(entity, comp::Vel(Vec3::zero())); @@ -204,15 +204,16 @@ impl Server { // Make sure physics are accepted. state.write_component(entity, comp::ForceUpdate); - let settings = server_settings.clone(); // Give the AdminPerms component to the player if their name exists in admin list - if settings.admins.contains(&name) { + if server_settings.admins.contains( + &state + .ecs() + .read_storage::() + .get(entity) + .unwrap() + .alias, + ) { state.write_component(entity, comp::AdminPerms); - dbg!("Given admin perms to an user"); - dbg!(settings.admins); - } else { - dbg!(settings.admins); - dbg!("The new user isn't an admin"); } // Tell the client its request was successful. client.allow_state(ClientState::Character); @@ -821,7 +822,17 @@ impl Server { } else { let message = match self.state.ecs().read_storage::().get(entity) { - Some(player) => format!("[{}] {}", &player.alias, message), + Some(player) => match self + .state + .ecs() + .read_storage::() + .get(entity) + { + Some(_perms) => { + format!("[ADMIN][{}] {}", &player.alias, message) + } + None => format!("[{}] {}", &player.alias, message), + }, None => format!("[] {}", message), }; self.clients