From 198a8a3e2cf4123c5106a07fc5fb16ceb883c024 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 22 Jun 2025 08:49:06 -0400 Subject: [PATCH] Make !reload command always available, add !finishevent The reload command was previously implemented in Lua, but this is a little dangerous as it could itself have an error and is unable to work in the first place. I moved this to Rust to ensure it's always available. I left the reload_scripts() API in Lua as someone could still find that useful! Additionally, I added a !finishevent debug command to forcefully end the current event you're in. This can be useful if your script is incomplete or has an error, as your client gets stuck very easily. --- USAGE.md | 1 + resources/scripts/Global.lua | 1 - resources/scripts/commands/debug/Reload.lua | 6 ------ src/world/chat_handler.rs | 12 ++++++++++++ src/world/connection.rs | 13 +++++++++---- src/world/event.rs | 7 ++++--- 6 files changed, 26 insertions(+), 14 deletions(-) delete mode 100644 resources/scripts/commands/debug/Reload.lua diff --git a/USAGE.md b/USAGE.md index e2799ac..e6f7797 100644 --- a/USAGE.md +++ b/USAGE.md @@ -117,6 +117,7 @@ These special debug commands start with `!` and are custom to Kawari. * `!invis: Toggles the hidden GM invisibility mode on or off for your character.` * `!unlockaetheryte `: Unlock an aetheryte. For the first parameter, the literal words are required. * `!teri `: Changes to the specified territory. +* `!finishevent`: Forcefully finishes the current event, useful if the script has an error and you're stuck talking to something. ### GM commands diff --git a/resources/scripts/Global.lua b/resources/scripts/Global.lua index b112ce4..1067423 100644 --- a/resources/scripts/Global.lua +++ b/resources/scripts/Global.lua @@ -212,7 +212,6 @@ registerCommand("setspeed", "commands/debug/SetSpeed.lua") registerCommand("nudge", "commands/debug/Nudge.lua") registerCommand("festival", "commands/debug/Festival.lua") registerCommand("permtest", "commands/debug/PermissionTest.lua") -registerCommand("reload", "commands/debug/Reload.lua") registerCommand("unlockaction", "commands/debug/UnlockAction.lua") registerCommand("wireframe", "commands/debug/ToggleWireframe.lua") registerCommand("invis", "commands/debug/ToggleInvisibility.lua") diff --git a/resources/scripts/commands/debug/Reload.lua b/resources/scripts/commands/debug/Reload.lua deleted file mode 100644 index 6c69111..0000000 --- a/resources/scripts/commands/debug/Reload.lua +++ /dev/null @@ -1,6 +0,0 @@ -required_rank = GM_RANK_DEBUG - -function onCommand(args, player) - player:reload_scripts() - player:send_message("Scripts reloaded!") -end diff --git a/src/world/chat_handler.rs b/src/world/chat_handler.rs index 0ed6fd9..34a1ac2 100644 --- a/src/world/chat_handler.rs +++ b/src/world/chat_handler.rs @@ -70,6 +70,18 @@ impl ChatHandler { connection.send_inventory(true).await; } + "!reload" => { + connection.reload_scripts(); + connection.send_message("Scripts reloaded!").await; + } + "!finishevent" => { + if let Some(event) = &connection.event { + connection.event_finish(event.id).await; + connection + .send_message("Current event forcefully finished.") + .await; + } + } _ => {} } } diff --git a/src/world/connection.rs b/src/world/connection.rs index cfb226c..634c13b 100644 --- a/src/world/connection.rs +++ b/src/world/connection.rs @@ -625,10 +625,7 @@ impl ZoneConnection { self.warp_aetheryte(*aetheryte_id).await; } Task::ReloadScripts => { - let mut lua = self.lua.lock().unwrap(); - if let Err(err) = load_global_script(&mut lua) { - tracing::warn!("Failed to load Global.lua: {:?}", err); - } + self.reload_scripts(); } Task::ToggleInvisibility { invisible } => { self.toggle_invisibility(*invisible).await; @@ -638,6 +635,14 @@ impl ZoneConnection { player.queued_tasks.clear(); } + /// Reloads Global.lua + pub fn reload_scripts(&mut self) { + let mut lua = self.lua.lock().unwrap(); + if let Err(err) = load_global_script(&mut lua) { + tracing::warn!("Failed to load Global.lua: {:?}", err); + } + } + pub async fn event_finish(&mut self, handler_id: u32) { // sent event finish { diff --git a/src/world/event.rs b/src/world/event.rs index 913116b..0bfc142 100644 --- a/src/world/event.rs +++ b/src/world/event.rs @@ -5,8 +5,9 @@ use crate::{common::ObjectTypeId, config::get_config}; use super::{LuaPlayer, Zone}; pub struct Event { - file_name: String, + pub file_name: String, lua: Lua, + pub id: u32, } impl Event { @@ -22,12 +23,12 @@ impl Event { .exec() { tracing::warn!("Syntax error in {}: {:?}", file_name, err); - return Self { file_name, lua }; + return Self { file_name, lua, id }; } lua.globals().set("EVENT_ID", id).unwrap(); - Self { file_name, lua } + Self { file_name, lua, id } } pub fn enter_territory(&mut self, player: &mut LuaPlayer, zone: &Zone) {