Add adminify command to temporarily give admin perms

This commit is contained in:
Piotr Korgól 2019-08-17 20:16:58 +02:00
parent f12821db35
commit 586bf5faff
2 changed files with 41 additions and 1 deletions

View File

@ -1,6 +1,6 @@
use specs::{Component, NullStorage};
#[derive(Default)]
#[derive(Clone, Copy, Default)]
pub struct Admin;
impl Component for Admin {

View File

@ -190,6 +190,13 @@ lazy_static! {
false,
handle_explosion,
),
ChatCommand::new(
"adminify",
"{}",
"/adminify <playername> : Temporarily gives a player admin permissions or removes them",
true,
handle_adminify,
)
];
}
@ -732,6 +739,39 @@ fn handle_explosion(server: &mut Server, entity: EcsEntity, args: String, action
}
}
fn handle_adminify(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
if let Ok(alias) = scan_fmt!(&args, action.arg_fmt, String) {
let ecs = server.state.ecs();
let opt_player = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
.join()
.find(|(_, player)| player.alias == alias)
.map(|(entity, _)| entity);
match opt_player {
Some(player) => match server.state.read_component_cloned::<comp::Admin>(player) {
Some(_admin) => {
ecs.write_storage::<comp::Admin>().remove(player);
}
None => {
server.state.write_component(player, comp::Admin);
}
},
None => {
server.clients.notify(
entity,
ServerMsg::private(format!("Player '{}' not found!", alias)),
);
server
.clients
.notify(entity, ServerMsg::private(String::from(action.help_string)));
}
}
} else {
server
.clients
.notify(entity, ServerMsg::private(String::from(action.help_string)));
}
}
fn handle_tell(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
if let Ok(alias) = scan_fmt!(&args, action.arg_fmt, String) {
let ecs = server.state.ecs();