mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add adminify command to temporarily give admin perms
This commit is contained in:
parent
f12821db35
commit
586bf5faff
@ -1,6 +1,6 @@
|
|||||||
use specs::{Component, NullStorage};
|
use specs::{Component, NullStorage};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Clone, Copy, Default)]
|
||||||
pub struct Admin;
|
pub struct Admin;
|
||||||
|
|
||||||
impl Component for Admin {
|
impl Component for Admin {
|
||||||
|
@ -190,6 +190,13 @@ lazy_static! {
|
|||||||
false,
|
false,
|
||||||
handle_explosion,
|
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) {
|
fn handle_tell(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
|
||||||
if let Ok(alias) = scan_fmt!(&args, action.arg_fmt, String) {
|
if let Ok(alias) = scan_fmt!(&args, action.arg_fmt, String) {
|
||||||
let ecs = server.state.ecs();
|
let ecs = server.state.ecs();
|
||||||
|
Loading…
Reference in New Issue
Block a user