diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 4b878c806c..872f6bec35 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -239,6 +239,13 @@ lazy_static! { true, handle_exp, ), + ChatCommand::new( + "set_level", + "{d} {}", + "/set_level : Set own Level or specify a target player", + true, + handle_level + ), ChatCommand::new( "removelights", "{}", @@ -1059,6 +1066,34 @@ fn handle_exp(server: &mut Server, entity: EcsEntity, args: String, action: &Cha } } +fn handle_level(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) { + let (a_lvl, a_alias) = scan_fmt_some!(&args, action.arg_fmt, u32, String); + + if let Some(lvl) = a_lvl { + let ecs = server.state.ecs_mut(); + let target = find_target(&ecs, a_alias, entity); + + let mut error_msg = None; + + match target { + Ok(player) => { + if let Some(stats) = ecs.write_storage::().get_mut(player) { + stats.level.set_level(lvl); + } else { + error_msg = Some(ServerMsg::private(String::from("Player has no stats!"))); + } + }, + Err(e) => { + error_msg = Some(e); + }, + } + + if let Some(msg) = error_msg { + server.notify_client(entity, msg); + } + } +} + use common::comp::Item; fn handle_debug(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) { if let Ok(items) = assets::load_glob::("common.items.debug.*") {