diff --git a/resources/scripts/Global.lua b/resources/scripts/Global.lua index 53aad3f..b217293 100644 --- a/resources/scripts/Global.lua +++ b/resources/scripts/Global.lua @@ -26,17 +26,15 @@ end function printf(player, fmt_str, ...) -- Sender would be defined elsewhere, if at all - if sender == nil then - sender = "" + if command_sender == nil then + command_sender = "" end if ... ~= nil then - player:send_message(sender..fmt_str:format(...)) + player:send_message(command_sender..fmt_str:format(...)) else - player:send_message(sender..fmt_str) + player:send_message(command_sender..fmt_str) end - - sender = nil -- Reset the sender, it's not required to have for printf to work, and not all users of printf will be commands, most likely. end -- Constants diff --git a/resources/scripts/commands/debug/ChangeTerritory.lua b/resources/scripts/commands/debug/ChangeTerritory.lua index 561eabb..e1e6202 100644 --- a/resources/scripts/commands/debug/ChangeTerritory.lua +++ b/resources/scripts/commands/debug/ChangeTerritory.lua @@ -1,5 +1,5 @@ required_rank = GM_RANK_DEBUG -sender = "[teri] " +command_sender = "[teri] " function onCommand(args, player) local parts = split(args) diff --git a/resources/scripts/commands/debug/Festival.lua b/resources/scripts/commands/debug/Festival.lua index 1230c9a..8752273 100644 --- a/resources/scripts/commands/debug/Festival.lua +++ b/resources/scripts/commands/debug/Festival.lua @@ -1,7 +1,7 @@ -- A list of festival ids can be found in Hyperborea's source tree: -- https://github.com/kawaii/Hyperborea/blob/main/Hyperborea/festivals.yaml required_rank = GM_RANK_DEBUG -sender = "[festival] " +command_sender = "[festival] " function onCommand(args, player) local parts = split(args) diff --git a/resources/scripts/commands/debug/Nudge.lua b/resources/scripts/commands/debug/Nudge.lua index ed8a261..7082e79 100644 --- a/resources/scripts/commands/debug/Nudge.lua +++ b/resources/scripts/commands/debug/Nudge.lua @@ -1,7 +1,7 @@ -- Ported from Ioncannon's Project Meteor Server -- https://bitbucket.org/Ioncannon/project-meteor-server/src/develop/Data/scripts/commands/gm/nudge.lua required_rank = GM_RANK_DEBUG -sender = "[nudge] " +command_sender = "[nudge] " function onCommand(args, player) local parts = split(args) @@ -70,5 +70,6 @@ function onCommand(args, player) end player:set_position(new_position, player.rotation) + printf(player, "Positioning %s %s yalms.", direction_str, distance) end diff --git a/resources/scripts/commands/debug/SetSpeed.lua b/resources/scripts/commands/debug/SetSpeed.lua index f28a6e3..b3666c7 100644 --- a/resources/scripts/commands/debug/SetSpeed.lua +++ b/resources/scripts/commands/debug/SetSpeed.lua @@ -1,5 +1,5 @@ required_rank = GM_RANK_DEBUG -sender = "[setspeed] " +command_sender = "[setspeed] " function onCommand(args, player) local parts = split(args) diff --git a/resources/scripts/commands/debug/ToggleInvisibility.lua b/resources/scripts/commands/debug/ToggleInvisibility.lua index 955a11b..b611fda 100644 --- a/resources/scripts/commands/debug/ToggleInvisibility.lua +++ b/resources/scripts/commands/debug/ToggleInvisibility.lua @@ -1,5 +1,5 @@ required_rank = GM_RANK_DEBUG -sender = "[invis] " +command_sender = "[invis] " function onCommand(args, player) local usage = "\nThis command makes the user invisible to all other actors." diff --git a/resources/scripts/commands/debug/ToggleWireframe.lua b/resources/scripts/commands/debug/ToggleWireframe.lua index 386f277..630f0fc 100644 --- a/resources/scripts/commands/debug/ToggleWireframe.lua +++ b/resources/scripts/commands/debug/ToggleWireframe.lua @@ -1,5 +1,5 @@ required_rank = GM_RANK_DEBUG -sender = "[wireframe] " +command_sender = "[wireframe] " function onCommand(args, player) local usage = "\nThis command allows the user to view the world in wireframe mode." diff --git a/resources/scripts/commands/debug/Unlock.lua b/resources/scripts/commands/debug/Unlock.lua index 019ef85..356bc65 100644 --- a/resources/scripts/commands/debug/Unlock.lua +++ b/resources/scripts/commands/debug/Unlock.lua @@ -1,5 +1,5 @@ required_rank = GM_RANK_DEBUG -sender = "[unlockaction] " +command_sender = "[unlockaction] " function onCommand(args, player) local parts = split(args) diff --git a/resources/scripts/commands/debug/UnlockAetheryte.lua b/resources/scripts/commands/debug/UnlockAetheryte.lua index b0ddff4..75af3b8 100644 --- a/resources/scripts/commands/debug/UnlockAetheryte.lua +++ b/resources/scripts/commands/debug/UnlockAetheryte.lua @@ -1,5 +1,5 @@ required_rank = GM_RANK_DEBUG -sender = "[unlockaetheryte] " +command_sender = "[unlockaetheryte] " function onCommand(args, player) local parts = split(args) diff --git a/src/bin/kawari-world.rs b/src/bin/kawari-world.rs index 8c5e22a..2c73fa0 100644 --- a/src/bin/kawari-world.rs +++ b/src/bin/kawari-world.rs @@ -555,6 +555,16 @@ async fn client_loop( let func: Function = lua.globals().get("onCommand")?; func.call::<()>((func_args, connection_data))?; + + /* `command_sender` is an optional variable scripts can define to identify themselves in print messages. + * It's okay if this global isn't set. We also don't care what its value is, just that it exists. + * This is reset -after- running the command intentionally. Resetting beforehand will never display the command's identifier. + */ + let command_sender: Result = lua.globals().get("command_sender"); + if let Ok(_) = command_sender { + // tracing::info!("Resetting command_sender for next script run."); + lua.globals().set("command_sender", mlua::Value::Nil)?; + } Ok(()) } else { tracing::info!("User with account_id {} tried to invoke GM command {} with insufficient privileges!",