Add Admins field to the settings file

This commit is contained in:
Piotr Korgól
2019-08-12 16:05:58 +02:00
parent 98c0692260
commit 6882170d6f
4 changed files with 70 additions and 49 deletions

View File

@ -1,4 +1,5 @@
mod action_state; mod action_state;
mod admin;
mod agent; mod agent;
mod animation; mod animation;
mod body; mod body;
@ -10,10 +11,10 @@ mod phys;
mod player; mod player;
mod stats; mod stats;
mod visual; mod visual;
mod admin;
// Reexports // Reexports
pub use action_state::ActionState; pub use action_state::ActionState;
pub use admin::AdminPerms;
pub use agent::Agent; pub use agent::Agent;
pub use animation::{Animation, AnimationInfo}; pub use animation::{Animation, AnimationInfo};
pub use body::{humanoid, object, quadruped, quadruped_medium, Body}; pub use body::{humanoid, object, quadruped, quadruped_medium, Body};
@ -27,4 +28,3 @@ pub use phys::{ForceUpdate, Ori, Pos, Scale, Vel};
pub use player::Player; pub use player::Player;
pub use stats::{Dying, Exp, HealthSource, Level, Stats}; pub use stats::{Dying, Exp, HealthSource, Level, Stats};
pub use visual::LightEmitter; pub use visual::LightEmitter;
pub use admin::AdminPerms;

View File

@ -668,61 +668,61 @@ fn handle_light(server: &mut Server, entity: EcsEntity, args: String, action: &C
} }
fn handle_lantern(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) { fn handle_lantern(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
let opt_s = scan_fmt_some!(&args, action.arg_fmt, f32); let opt_s = scan_fmt_some!(&args, action.arg_fmt, f32);
if server if server
.state .state
.read_storage::<comp::LightEmitter>() .read_storage::<comp::LightEmitter>()
.get(entity) .get(entity)
.is_some() .is_some()
{ {
if let Some(s) = opt_s { if let Some(s) = opt_s {
if let Some(light) = server if let Some(light) = server
.state
.ecs()
.write_storage::<comp::LightEmitter>()
.get_mut(entity)
{
light.strength = s.max(0.1).min(20.0);
server.clients.notify(
entity,
ServerMsg::private(String::from("You played with flame strength.")),
);
}
} else {
server
.state
.ecs()
.write_storage::<comp::LightEmitter>()
.remove(entity);
server.clients.notify(
entity,
ServerMsg::private(String::from("You put out the lantern.")),
);
}
} else {
let _ = server
.state .state
.ecs() .ecs()
.write_storage::<comp::LightEmitter>() .write_storage::<comp::LightEmitter>()
.insert( .get_mut(entity)
{
light.strength = s.max(0.1).min(20.0);
server.clients.notify(
entity, entity,
comp::LightEmitter { ServerMsg::private(String::from("You played with flame strength.")),
offset: Vec3::new(0.5, 0.2, 0.8),
col: Rgb::new(1.0, 0.75, 0.3),
strength: if let Some(s) = opt_s {
s.max(0.0).min(20.0)
} else {
6.0
},
},
); );
}
} else {
server
.state
.ecs()
.write_storage::<comp::LightEmitter>()
.remove(entity);
server.clients.notify( server.clients.notify(
entity, entity,
ServerMsg::private(String::from("You lighted your lantern.")), ServerMsg::private(String::from("You put out the lantern.")),
); );
} }
} else {
let _ = server
.state
.ecs()
.write_storage::<comp::LightEmitter>()
.insert(
entity,
comp::LightEmitter {
offset: Vec3::new(0.5, 0.2, 0.8),
col: Rgb::new(1.0, 0.75, 0.3),
strength: if let Some(s) = opt_s {
s.max(0.0).min(20.0)
} else {
6.0
},
},
);
server.clients.notify(
entity,
ServerMsg::private(String::from("You lighted your lantern.")),
);
}
} }
fn handle_explosion(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) { fn handle_explosion(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {

View File

@ -188,11 +188,12 @@ impl Server {
client: &mut Client, client: &mut Client,
name: String, name: String,
body: comp::Body, body: comp::Body,
server_settings: &ServerSettings,
) { ) {
let spawn_point = state.ecs().read_resource::<SpawnPoint>().0; let spawn_point = state.ecs().read_resource::<SpawnPoint>().0;
state.write_component(entity, body); state.write_component(entity, body);
state.write_component(entity, comp::Stats::new(name)); state.write_component(entity, comp::Stats::new(name.to_string()));
state.write_component(entity, comp::Controller::default()); state.write_component(entity, comp::Controller::default());
state.write_component(entity, comp::Pos(spawn_point)); state.write_component(entity, comp::Pos(spawn_point));
state.write_component(entity, comp::Vel(Vec3::zero())); state.write_component(entity, comp::Vel(Vec3::zero()));
@ -203,6 +204,16 @@ impl Server {
// Make sure physics are accepted. // Make sure physics are accepted.
state.write_component(entity, comp::ForceUpdate); 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) {
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. // Tell the client its request was successful.
client.allow_state(ClientState::Character); client.allow_state(ClientState::Character);
} }
@ -518,6 +529,7 @@ impl Server {
let mut frontend_events = Vec::new(); let mut frontend_events = Vec::new();
let accounts = &mut self.accounts; let accounts = &mut self.accounts;
let server_settings = &self.server_settings;
let state = &mut self.state; let state = &mut self.state;
let mut new_chat_msgs = Vec::new(); let mut new_chat_msgs = Vec::new();
@ -669,7 +681,14 @@ impl Server {
ClientState::Registered ClientState::Registered
| ClientState::Spectator | ClientState::Spectator
| ClientState::Dead => { | ClientState::Dead => {
Self::create_player_character(state, entity, client, name, body); Self::create_player_character(
state,
entity,
client,
name,
body,
&server_settings,
);
if let Some(player) = if let Some(player) =
state.ecs().read_storage::<comp::Player>().get(entity) state.ecs().read_storage::<comp::Player>().get(entity)
{ {

View File

@ -12,6 +12,7 @@ pub struct ServerSettings {
pub server_description: String, pub server_description: String,
//pub login_server: whatever //pub login_server: whatever
pub start_time: f64, pub start_time: f64,
pub admins: Vec<String>,
} }
impl Default for ServerSettings { impl Default for ServerSettings {
@ -23,6 +24,7 @@ impl Default for ServerSettings {
server_description: "This is the best Veloren server.".to_owned(), server_description: "This is the best Veloren server.".to_owned(),
max_players: 100, max_players: 100,
start_time: 9.0 * 3600.0, start_time: 9.0 * 3600.0,
admins: vec![],
} }
} }
} }