1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-06-30 11:47:45 +00:00

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.
This commit is contained in:
Joshua Goins 2025-06-22 08:49:06 -04:00
parent e1b261c7d8
commit 198a8a3e2c
6 changed files with 26 additions and 14 deletions

View file

@ -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.` * `!invis: Toggles the hidden GM invisibility mode on or off for your character.`
* `!unlockaetheryte <on/off> <id>`: Unlock an aetheryte. For the first parameter, the literal words are required. * `!unlockaetheryte <on/off> <id>`: Unlock an aetheryte. For the first parameter, the literal words are required.
* `!teri <id>`: Changes to the specified territory. * `!teri <id>`: 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 ### GM commands

View file

@ -212,7 +212,6 @@ registerCommand("setspeed", "commands/debug/SetSpeed.lua")
registerCommand("nudge", "commands/debug/Nudge.lua") registerCommand("nudge", "commands/debug/Nudge.lua")
registerCommand("festival", "commands/debug/Festival.lua") registerCommand("festival", "commands/debug/Festival.lua")
registerCommand("permtest", "commands/debug/PermissionTest.lua") registerCommand("permtest", "commands/debug/PermissionTest.lua")
registerCommand("reload", "commands/debug/Reload.lua")
registerCommand("unlockaction", "commands/debug/UnlockAction.lua") registerCommand("unlockaction", "commands/debug/UnlockAction.lua")
registerCommand("wireframe", "commands/debug/ToggleWireframe.lua") registerCommand("wireframe", "commands/debug/ToggleWireframe.lua")
registerCommand("invis", "commands/debug/ToggleInvisibility.lua") registerCommand("invis", "commands/debug/ToggleInvisibility.lua")

View file

@ -1,6 +0,0 @@
required_rank = GM_RANK_DEBUG
function onCommand(args, player)
player:reload_scripts()
player:send_message("Scripts reloaded!")
end

View file

@ -70,6 +70,18 @@ impl ChatHandler {
connection.send_inventory(true).await; 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;
}
}
_ => {} _ => {}
} }
} }

View file

@ -625,10 +625,7 @@ impl ZoneConnection {
self.warp_aetheryte(*aetheryte_id).await; self.warp_aetheryte(*aetheryte_id).await;
} }
Task::ReloadScripts => { Task::ReloadScripts => {
let mut lua = self.lua.lock().unwrap(); self.reload_scripts();
if let Err(err) = load_global_script(&mut lua) {
tracing::warn!("Failed to load Global.lua: {:?}", err);
}
} }
Task::ToggleInvisibility { invisible } => { Task::ToggleInvisibility { invisible } => {
self.toggle_invisibility(*invisible).await; self.toggle_invisibility(*invisible).await;
@ -638,6 +635,14 @@ impl ZoneConnection {
player.queued_tasks.clear(); 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) { pub async fn event_finish(&mut self, handler_id: u32) {
// sent event finish // sent event finish
{ {

View file

@ -5,8 +5,9 @@ use crate::{common::ObjectTypeId, config::get_config};
use super::{LuaPlayer, Zone}; use super::{LuaPlayer, Zone};
pub struct Event { pub struct Event {
file_name: String, pub file_name: String,
lua: Lua, lua: Lua,
pub id: u32,
} }
impl Event { impl Event {
@ -22,12 +23,12 @@ impl Event {
.exec() .exec()
{ {
tracing::warn!("Syntax error in {}: {:?}", file_name, err); 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(); 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) { pub fn enter_territory(&mut self, player: &mut LuaPlayer, zone: &Zone) {