From af47c0dc21a85450424ac7c444dba59dac5eec82 Mon Sep 17 00:00:00 2001 From: Avi Weinstock Date: Sat, 17 Apr 2021 13:44:22 -0400 Subject: [PATCH] Added `/server_physics` admin command. --- CHANGELOG.md | 1 + common/src/cmd.rs | 11 +++++++++++ server/src/cmd.rs | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eb859a105..6b4b8c95b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added disconnectall CLI command - One handed weapons can now be used and found in the world - Players can now opt-in to server-authoritiative physics in gameplay settings. +- Added `/server_physics` admin command. ### Changed diff --git a/common/src/cmd.rs b/common/src/cmd.rs index 7628e24f9b..452213418a 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -82,6 +82,7 @@ pub enum ChatCommand { RevokeBuildAll, Safezone, Say, + ServerPhysics, SetMotd, Site, SkillPoint, @@ -144,6 +145,7 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[ ChatCommand::RevokeBuildAll, ChatCommand::Safezone, ChatCommand::Say, + ChatCommand::ServerPhysics, ChatCommand::SetMotd, ChatCommand::Site, ChatCommand::SkillPoint, @@ -466,6 +468,14 @@ impl ChatCommand { "Send messages to everyone within shouting distance", NoAdmin, ), + ChatCommand::ServerPhysics => cmd( + vec![ + Any("username", Required), + Boolean("enabled", "true".to_string(), Optional), + ], + "Set/unset server-authoritative physics for an account", + Admin, + ), ChatCommand::SetMotd => { cmd(vec![Message(Optional)], "Set the server description", Admin) }, @@ -580,6 +590,7 @@ impl ChatCommand { ChatCommand::RevokeBuildAll => "revoke_build_all", ChatCommand::Safezone => "safezone", ChatCommand::Say => "say", + ChatCommand::ServerPhysics => "server_physics", ChatCommand::SetMotd => "set_motd", ChatCommand::Site => "site", ChatCommand::SkillPoint => "skill_point", diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 29603283b7..f2805f1b47 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -24,7 +24,7 @@ use common::{ effect::Effect, event::{EventBus, ServerEvent}, npc::{self, get_npc_name}, - resources::TimeOfDay, + resources::{PlayerPhysicsSettings, TimeOfDay}, terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize}, uid::Uid, vol::RectVolSize, @@ -137,6 +137,7 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler { ChatCommand::RevokeBuildAll => handle_revoke_build_all, ChatCommand::Safezone => handle_safezone, ChatCommand::Say => handle_say, + ChatCommand::ServerPhysics => handle_server_physics, ChatCommand::SetMotd => handle_set_motd, ChatCommand::Site => handle_site, ChatCommand::SkillPoint => handle_skill_point, @@ -2477,3 +2478,35 @@ fn handle_unban( Err(action.help_string()) } } + +fn handle_server_physics( + server: &mut Server, + client: EcsEntity, + _target: EcsEntity, + args: String, + action: &ChatCommand, +) -> CmdResult<()> { + if let (Some(username), enabled_opt) = scan_fmt_some!(&args, &action.arg_fmt(), String, bool) { + let uuid = find_username(server, &username)?; + let server_force = enabled_opt.unwrap_or(true); + + let mut player_physics_settings = + server.state.ecs().write_resource::(); + let entry = player_physics_settings.settings.entry(uuid).or_default(); + entry.server_force = server_force; + + server.notify_client( + client, + ServerGeneral::server_msg( + ChatType::CommandInfo, + format!( + "Updated physics settings for {} ({}): {:?}", + username, uuid, entry + ), + ), + ); + Ok(()) + } else { + Err(action.help_string()) + } +}