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

Add support on the Rust side for resetting the command identifier.

-sender was also renamed to command_sender in case we'd like to reserve the word "sender" in the future.
This commit is contained in:
The Dax 2025-06-25 18:24:21 -04:00 committed by Joshua Goins
parent 0f7e068ba3
commit 385672d797
10 changed files with 23 additions and 14 deletions

View file

@ -26,17 +26,15 @@ end
function printf(player, fmt_str, ...) function printf(player, fmt_str, ...)
-- Sender would be defined elsewhere, if at all -- Sender would be defined elsewhere, if at all
if sender == nil then if command_sender == nil then
sender = "" command_sender = ""
end end
if ... ~= nil then if ... ~= nil then
player:send_message(sender..fmt_str:format(...)) player:send_message(command_sender..fmt_str:format(...))
else else
player:send_message(sender..fmt_str) player:send_message(command_sender..fmt_str)
end 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 end
-- Constants -- Constants

View file

@ -1,5 +1,5 @@
required_rank = GM_RANK_DEBUG required_rank = GM_RANK_DEBUG
sender = "[teri] " command_sender = "[teri] "
function onCommand(args, player) function onCommand(args, player)
local parts = split(args) local parts = split(args)

View file

@ -1,7 +1,7 @@
-- A list of festival ids can be found in Hyperborea's source tree: -- A list of festival ids can be found in Hyperborea's source tree:
-- https://github.com/kawaii/Hyperborea/blob/main/Hyperborea/festivals.yaml -- https://github.com/kawaii/Hyperborea/blob/main/Hyperborea/festivals.yaml
required_rank = GM_RANK_DEBUG required_rank = GM_RANK_DEBUG
sender = "[festival] " command_sender = "[festival] "
function onCommand(args, player) function onCommand(args, player)
local parts = split(args) local parts = split(args)

View file

@ -1,7 +1,7 @@
-- Ported from Ioncannon's Project Meteor Server -- Ported from Ioncannon's Project Meteor Server
-- https://bitbucket.org/Ioncannon/project-meteor-server/src/develop/Data/scripts/commands/gm/nudge.lua -- https://bitbucket.org/Ioncannon/project-meteor-server/src/develop/Data/scripts/commands/gm/nudge.lua
required_rank = GM_RANK_DEBUG required_rank = GM_RANK_DEBUG
sender = "[nudge] " command_sender = "[nudge] "
function onCommand(args, player) function onCommand(args, player)
local parts = split(args) local parts = split(args)
@ -70,5 +70,6 @@ function onCommand(args, player)
end end
player:set_position(new_position, player.rotation) player:set_position(new_position, player.rotation)
printf(player, "Positioning %s %s yalms.", direction_str, distance) printf(player, "Positioning %s %s yalms.", direction_str, distance)
end end

View file

@ -1,5 +1,5 @@
required_rank = GM_RANK_DEBUG required_rank = GM_RANK_DEBUG
sender = "[setspeed] " command_sender = "[setspeed] "
function onCommand(args, player) function onCommand(args, player)
local parts = split(args) local parts = split(args)

View file

@ -1,5 +1,5 @@
required_rank = GM_RANK_DEBUG required_rank = GM_RANK_DEBUG
sender = "[invis] " command_sender = "[invis] "
function onCommand(args, player) function onCommand(args, player)
local usage = "\nThis command makes the user invisible to all other actors." local usage = "\nThis command makes the user invisible to all other actors."

View file

@ -1,5 +1,5 @@
required_rank = GM_RANK_DEBUG required_rank = GM_RANK_DEBUG
sender = "[wireframe] " command_sender = "[wireframe] "
function onCommand(args, player) function onCommand(args, player)
local usage = "\nThis command allows the user to view the world in wireframe mode." local usage = "\nThis command allows the user to view the world in wireframe mode."

View file

@ -1,5 +1,5 @@
required_rank = GM_RANK_DEBUG required_rank = GM_RANK_DEBUG
sender = "[unlockaction] " command_sender = "[unlockaction] "
function onCommand(args, player) function onCommand(args, player)
local parts = split(args) local parts = split(args)

View file

@ -1,5 +1,5 @@
required_rank = GM_RANK_DEBUG required_rank = GM_RANK_DEBUG
sender = "[unlockaetheryte] " command_sender = "[unlockaetheryte] "
function onCommand(args, player) function onCommand(args, player)
local parts = split(args) local parts = split(args)

View file

@ -555,6 +555,16 @@ async fn client_loop(
let func: Function = let func: Function =
lua.globals().get("onCommand")?; lua.globals().get("onCommand")?;
func.call::<()>((func_args, connection_data))?; 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<mlua::prelude::LuaValue, mlua::prelude::LuaError> = 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(()) Ok(())
} else { } else {
tracing::info!("User with account_id {} tried to invoke GM command {} with insufficient privileges!", tracing::info!("User with account_id {} tried to invoke GM command {} with insufficient privileges!",