mirror of
https://github.com/redstrate/Kawari.git
synced 2025-06-30 11:47:45 +00:00
Add a basic permission system to Lua scripts to bring them in line with ingame GM commands.
This commit is contained in:
parent
b488cfb348
commit
be20b0f604
7 changed files with 47 additions and 11 deletions
|
@ -3,6 +3,10 @@ function onBeginLogin(player)
|
||||||
player:send_message("Welcome to Kawari!")
|
player:send_message("Welcome to Kawari!")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function onCommandPermissionError(player)
|
||||||
|
player:send_message("You do not have permission to run this command.")
|
||||||
|
end
|
||||||
|
|
||||||
function split(input, separator)
|
function split(input, separator)
|
||||||
if separator == nil then
|
if separator == nil then
|
||||||
separator = '%s'
|
separator = '%s'
|
||||||
|
@ -16,6 +20,17 @@ function split(input, separator)
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Constants
|
||||||
|
GM_RANK_NORMALUSER = 0
|
||||||
|
GM_RANK_GAMEMASTER = 1
|
||||||
|
GM_RANK_EVENTJUNIOR = 3
|
||||||
|
GM_RANK_EVENTSENIOR = 4
|
||||||
|
GM_RANK_SUPPORT = 5
|
||||||
|
GM_RANK_SENIOR = 7
|
||||||
|
GM_RANK_DEBUG = 90
|
||||||
|
GM_RANK_MAX = 255 -- Doesn't exist, used for purposes of testing permissions in scripts
|
||||||
|
|
||||||
|
|
||||||
-- please keep these ids sorted!
|
-- please keep these ids sorted!
|
||||||
|
|
||||||
-- Actions
|
-- Actions
|
||||||
|
@ -51,3 +66,4 @@ registerCommand("classjob", "commands/debug/ClassJob.lua")
|
||||||
registerCommand("setspeed", "commands/debug/SetSpeed.lua")
|
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")
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
permissions = GM_RANK_DEBUG
|
||||||
|
|
||||||
function onCommand(args, player)
|
function onCommand(args, player)
|
||||||
local parts = split(args)
|
local parts = split(args)
|
||||||
player:set_classjob(parts[1])
|
player:set_classjob(parts[1])
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
-- 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
|
||||||
|
permissions = GM_RANK_DEBUG
|
||||||
|
|
||||||
function onCommand(args, player)
|
function onCommand(args, player)
|
||||||
local parts = split(args)
|
local parts = split(args)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
-- 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
|
||||||
|
permissions = GM_RANK_MAX
|
||||||
|
|
||||||
function send_msg(message, player)
|
function send_msg(message, player)
|
||||||
player:send_message(string.format("[nudge] %s", message))
|
player:send_message(string.format("[nudge] %s", message))
|
||||||
|
|
5
resources/scripts/commands/debug/PermissionTest.lua
Normal file
5
resources/scripts/commands/debug/PermissionTest.lua
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
permissions = GM_RANK_MAX
|
||||||
|
|
||||||
|
function onCommand(args, player)
|
||||||
|
player:send_message("How did you run this? This shouldn't be runnable!")
|
||||||
|
end
|
|
@ -1,3 +1,5 @@
|
||||||
|
permissions = GM_RANK_DEBUG
|
||||||
|
|
||||||
function onCommand(args, player)
|
function onCommand(args, player)
|
||||||
local parts = split(args)
|
local parts = split(args)
|
||||||
player:set_position({ x = tonumber(parts[1]), y = tonumber(parts[2]), z = tonumber(parts[3]) }, 0)
|
player:set_position({ x = tonumber(parts[1]), y = tonumber(parts[2]), z = tonumber(parts[3]) }, 0)
|
||||||
|
|
|
@ -535,20 +535,29 @@ async fn client_loop(
|
||||||
.exec()
|
.exec()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let func: Function =
|
let permissions: u8 = lua.globals().get("permissions")
|
||||||
lua.globals().get("onCommand").unwrap();
|
.expect("Script does not have permissions variable set");
|
||||||
|
|
||||||
let mut func_args = "";
|
if connection.player_data.gm_rank as u8 >= permissions {
|
||||||
if parts.len() > 1 {
|
let mut func_args = "";
|
||||||
func_args = &chat_message.message[command_name.len() + 2..];
|
if parts.len() > 1 {
|
||||||
tracing::info!("Args passed to Lua command {}: {}", command_name, func_args);
|
func_args = &chat_message.message[command_name.len() + 2..];
|
||||||
|
tracing::info!("Args passed to Lua command {}: {}", command_name, func_args);
|
||||||
|
} else {
|
||||||
|
tracing::info!("No additional args passed to Lua command {}.", command_name);
|
||||||
|
}
|
||||||
|
let func: Function =
|
||||||
|
lua.globals().get("onCommand").unwrap();
|
||||||
|
func.call::<()>((func_args, connection_data)).
|
||||||
|
unwrap();
|
||||||
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
tracing::info!("No additional args passed to Lua command {}.", command_name);
|
tracing::info!("User with account_id {} tried to invoke GM command they have no permissions for!!!", connection.player_data.account_id);
|
||||||
|
let func: Function =
|
||||||
|
lua.globals().get("onCommandPermissionError").unwrap();
|
||||||
|
func.call::<()>(connection_data).unwrap();
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
func.call::<()>((func_args, connection_data)).
|
|
||||||
unwrap();
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue