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!")
|
||||
end
|
||||
|
||||
function onCommandPermissionError(player)
|
||||
player:send_message("You do not have permission to run this command.")
|
||||
end
|
||||
|
||||
function split(input, separator)
|
||||
if separator == nil then
|
||||
separator = '%s'
|
||||
|
@ -16,6 +20,17 @@ function split(input, separator)
|
|||
return t
|
||||
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!
|
||||
|
||||
-- Actions
|
||||
|
@ -51,3 +66,4 @@ registerCommand("classjob", "commands/debug/ClassJob.lua")
|
|||
registerCommand("setspeed", "commands/debug/SetSpeed.lua")
|
||||
registerCommand("nudge", "commands/debug/Nudge.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)
|
||||
local parts = split(args)
|
||||
player:set_classjob(parts[1])
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
-- A list of festival ids can be found in Hyperborea's source tree:
|
||||
-- https://github.com/kawaii/Hyperborea/blob/main/Hyperborea/festivals.yaml
|
||||
permissions = GM_RANK_DEBUG
|
||||
|
||||
function onCommand(args, player)
|
||||
local parts = split(args)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
-- Ported from Ioncannon's Project Meteor Server
|
||||
-- https://bitbucket.org/Ioncannon/project-meteor-server/src/develop/Data/scripts/commands/gm/nudge.lua
|
||||
permissions = GM_RANK_MAX
|
||||
|
||||
function send_msg(message, player)
|
||||
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)
|
||||
local parts = split(args)
|
||||
player:set_position({ x = tonumber(parts[1]), y = tonumber(parts[2]), z = tonumber(parts[3]) }, 0)
|
||||
|
|
|
@ -535,9 +535,10 @@ async fn client_loop(
|
|||
.exec()
|
||||
.unwrap();
|
||||
|
||||
let func: Function =
|
||||
lua.globals().get("onCommand").unwrap();
|
||||
let permissions: u8 = lua.globals().get("permissions")
|
||||
.expect("Script does not have permissions variable set");
|
||||
|
||||
if connection.player_data.gm_rank as u8 >= permissions {
|
||||
let mut func_args = "";
|
||||
if parts.len() > 1 {
|
||||
func_args = &chat_message.message[command_name.len() + 2..];
|
||||
|
@ -545,10 +546,18 @@ async fn client_loop(
|
|||
} 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 {
|
||||
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(())
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue