From 3f76d1d702e7e37b353e094614ca6b86842a1084 Mon Sep 17 00:00:00 2001 From: CapsizeGlimmer <> Date: Sat, 9 May 2020 21:17:03 -0400 Subject: [PATCH] Rework tp command - "/sudo player /tp" is short for "/sudo player /tp sudoer" --- CHANGELOG.md | 4 +++ common/src/assets/mod.rs | 2 +- server/src/cmd.rs | 78 ++++++++++++++++++++++------------------ 3 files changed, 48 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1978b3b1ed..00cde7ef01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Cultists clothing - You can start the game by pressing "enter" from the character selection menu - Added server-side character saving +- Added tab completion in chat for player names and chat commands ### Changed @@ -87,6 +88,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Rewrote the humanoid skeleton to be more ideal for attack animations - Arrows can no longer hurt their owners - Increased overall character scale +- `/sudo player /tp` is short for `/sudo player /tp me` +- The `/object` command can create any object in comp::object::Body +- The `/help` command takes an optional argument. `/help /sudo` will show you information about only the sudo command. ### Removed diff --git a/common/src/assets/mod.rs b/common/src/assets/mod.rs index 3f2ba97805..003ec94a54 100644 --- a/common/src/assets/mod.rs +++ b/common/src/assets/mod.rs @@ -60,7 +60,7 @@ lazy_static! { pub static ref ASSETS: RwLock>> = RwLock::new(HashMap::new()); - /// List of item specifiers. Used for tab completing + /// List of item specifiers. Useful for tab completing pub static ref ITEM_SPECS: Vec = { let base = ASSETS_PATH.join("common").join("items"); let mut items = vec![]; diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 0d1dca0958..9beaf292c3 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -86,7 +86,9 @@ fn handle_give_item( args: String, action: &ChatCommand, ) { - if let (Some(item_name), give_amount_opt) = scan_fmt_some!(&args, &action.arg_fmt(), String, u32) { + if let (Some(item_name), give_amount_opt) = + scan_fmt_some!(&args, &action.arg_fmt(), String, u32) + { let give_amount = give_amount_opt.unwrap_or(1); if let Ok(item) = assets::load_cloned(&item_name) { let mut item: Item = item; @@ -145,7 +147,10 @@ fn handle_give_item( ); } } else { - server.notify_client(client, ServerMsg::private(String::from(action.help_string()))); + server.notify_client( + client, + ServerMsg::private(String::from(action.help_string())), + ); } } @@ -356,44 +361,47 @@ fn handle_tp( args: String, action: &ChatCommand, ) { - if let Ok(alias) = scan_fmt!(&args, &action.arg_fmt(), String) { + let opt_player = if let Some(alias) = scan_fmt_some!(&args, &action.arg_fmt(), String) { let ecs = server.state.ecs(); - let opt_player = (&ecs.entities(), &ecs.read_storage::()) + (&ecs.entities(), &ecs.read_storage::()) .join() .find(|(_, player)| player.alias == alias) - .map(|(entity, _)| entity); - match server.state.read_component_cloned::(target) { - Some(_pos) => match opt_player { - Some(player) => match server.state.read_component_cloned::(player) { - Some(pos) => { - server.state.write_component(target, pos); - server.state.write_component(target, comp::ForceUpdate); - }, - None => server.notify_client( - client, - ServerMsg::private(format!("Unable to teleport to player '{}'!", alias)), - ), - }, - None => { - server.notify_client( - client, - ServerMsg::private(format!("Player '{}' not found!", alias)), - ); - server.notify_client( - client, - ServerMsg::private(String::from(action.help_string())), - ); - }, - }, - None => { - server.notify_client(client, ServerMsg::private(format!("You have no position!"))); - }, + .map(|(entity, _)| entity) + } else { + if client != target { + Some(client) + } else { + server.notify_client( + client, + ServerMsg::private("You must specify a player name".to_string()), + ); + server.notify_client( + client, + ServerMsg::private(String::from(action.help_string())), + ); + return; + } + }; + if let Some(_pos) = server.state.read_component_cloned::(target) { + if let Some(player) = opt_player { + if let Some(pos) = server.state.read_component_cloned::(player) { + server.state.write_component(target, pos); + server.state.write_component(target, comp::ForceUpdate); + } else { + server.notify_client( + client, + ServerMsg::private(format!("Unable to teleport to player!")), + ); + } + } else { + server.notify_client(client, ServerMsg::private(format!("Player not found!"))); + server.notify_client( + client, + ServerMsg::private(String::from(action.help_string())), + ); } } else { - server.notify_client( - client, - ServerMsg::private(String::from(action.help_string())), - ); + server.notify_client(client, ServerMsg::private(format!("You have no position!"))); } }