mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add Admins field to the settings file
This commit is contained in:
parent
98c0692260
commit
6882170d6f
@ -1,4 +1,5 @@
|
||||
mod action_state;
|
||||
mod admin;
|
||||
mod agent;
|
||||
mod animation;
|
||||
mod body;
|
||||
@ -10,10 +11,10 @@ mod phys;
|
||||
mod player;
|
||||
mod stats;
|
||||
mod visual;
|
||||
mod admin;
|
||||
|
||||
// Reexports
|
||||
pub use action_state::ActionState;
|
||||
pub use admin::AdminPerms;
|
||||
pub use agent::Agent;
|
||||
pub use animation::{Animation, AnimationInfo};
|
||||
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 stats::{Dying, Exp, HealthSource, Level, Stats};
|
||||
pub use visual::LightEmitter;
|
||||
pub use admin::AdminPerms;
|
||||
|
@ -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) {
|
||||
let opt_s = scan_fmt_some!(&args, action.arg_fmt, f32);
|
||||
let opt_s = scan_fmt_some!(&args, action.arg_fmt, f32);
|
||||
|
||||
if server
|
||||
.state
|
||||
.read_storage::<comp::LightEmitter>()
|
||||
.get(entity)
|
||||
.is_some()
|
||||
{
|
||||
if let Some(s) = opt_s {
|
||||
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
|
||||
if server
|
||||
.state
|
||||
.read_storage::<comp::LightEmitter>()
|
||||
.get(entity)
|
||||
.is_some()
|
||||
{
|
||||
if let Some(s) = opt_s {
|
||||
if let Some(light) = server
|
||||
.state
|
||||
.ecs()
|
||||
.write_storage::<comp::LightEmitter>()
|
||||
.insert(
|
||||
.get_mut(entity)
|
||||
{
|
||||
light.strength = s.max(0.1).min(20.0);
|
||||
server.clients.notify(
|
||||
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
|
||||
},
|
||||
},
|
||||
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 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) {
|
||||
|
@ -188,11 +188,12 @@ impl Server {
|
||||
client: &mut Client,
|
||||
name: String,
|
||||
body: comp::Body,
|
||||
server_settings: &ServerSettings,
|
||||
) {
|
||||
let spawn_point = state.ecs().read_resource::<SpawnPoint>().0;
|
||||
|
||||
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::Pos(spawn_point));
|
||||
state.write_component(entity, comp::Vel(Vec3::zero()));
|
||||
@ -203,6 +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) {
|
||||
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);
|
||||
}
|
||||
@ -518,6 +529,7 @@ impl Server {
|
||||
let mut frontend_events = Vec::new();
|
||||
|
||||
let accounts = &mut self.accounts;
|
||||
let server_settings = &self.server_settings;
|
||||
|
||||
let state = &mut self.state;
|
||||
let mut new_chat_msgs = Vec::new();
|
||||
@ -669,7 +681,14 @@ impl Server {
|
||||
ClientState::Registered
|
||||
| ClientState::Spectator
|
||||
| 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) =
|
||||
state.ecs().read_storage::<comp::Player>().get(entity)
|
||||
{
|
||||
|
@ -12,6 +12,7 @@ pub struct ServerSettings {
|
||||
pub server_description: String,
|
||||
//pub login_server: whatever
|
||||
pub start_time: f64,
|
||||
pub admins: Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for ServerSettings {
|
||||
@ -23,6 +24,7 @@ impl Default for ServerSettings {
|
||||
server_description: "This is the best Veloren server.".to_owned(),
|
||||
max_players: 100,
|
||||
start_time: 9.0 * 3600.0,
|
||||
admins: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user