mirror of
https://github.com/redstrate/Kawari.git
synced 2025-06-30 19:57:46 +00:00
Overhaul the Lua permissions:
-Renamed permissions to required_rank -Don't panic when the script author omits required_rank -Reset state in the global table after reading it, so scripts can refresh it each time
This commit is contained in:
parent
579bef8cd6
commit
a24e0a5658
7 changed files with 27 additions and 11 deletions
|
@ -3,10 +3,16 @@ function onBeginLogin(player)
|
||||||
player:send_message("Welcome to Kawari!")
|
player:send_message("Welcome to Kawari!")
|
||||||
end
|
end
|
||||||
|
|
||||||
function onCommandPermissionError(player)
|
function onCommandRequiredRankInsufficientError(player)
|
||||||
player:send_message("You do not have permission to run this command.")
|
player:send_message("You do not have permission to run this command.")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function onCommandRequiredRankMissingError(additional_information, player)
|
||||||
|
local error_msg = "Your script does not define the required_rank variable. Please define it in your script for it to run."
|
||||||
|
|
||||||
|
player:send_message(string.format("%s\nAdditional information: %s", error_msg, additional_information))
|
||||||
|
end
|
||||||
|
|
||||||
function split(input, separator)
|
function split(input, separator)
|
||||||
if separator == nil then
|
if separator == nil then
|
||||||
separator = '%s'
|
separator = '%s'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
permissions = GM_RANK_DEBUG
|
required_rank = GM_RANK_DEBUG
|
||||||
|
|
||||||
function onCommand(args, player)
|
function onCommand(args, player)
|
||||||
local parts = split(args)
|
local parts = split(args)
|
||||||
|
|
|
@ -1,6 +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
|
required_rank = GM_RANK_DEBUG
|
||||||
|
|
||||||
function onCommand(args, player)
|
function onCommand(args, player)
|
||||||
local parts = split(args)
|
local parts = split(args)
|
||||||
|
|
|
@ -1,6 +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_DEBUG
|
required_rank = GM_RANK_DEBUG
|
||||||
|
|
||||||
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))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
permissions = GM_RANK_MAX
|
required_rank = GM_RANK_MAX
|
||||||
|
|
||||||
function onCommand(args, player)
|
function onCommand(args, player)
|
||||||
player:send_message("How did you run this? This shouldn't be runnable!")
|
player:send_message("How did you run this? This shouldn't be runnable!")
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
permissions = GM_RANK_DEBUG
|
required_rank = GM_RANK_DEBUG
|
||||||
|
|
||||||
function onCommand(args, player)
|
function onCommand(args, player)
|
||||||
local parts = split(args)
|
local parts = split(args)
|
||||||
|
|
|
@ -535,10 +535,20 @@ async fn client_loop(
|
||||||
.exec()
|
.exec()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let permissions: u8 = lua.globals().get("permissions")
|
let required_rank = lua.globals().get("required_rank");
|
||||||
.expect("Script does not have permissions variable set");
|
if let Err(error) = required_rank {
|
||||||
|
tracing::info!("Script is missing required_rank! Unable to run command, sending error to user. Additional information: {}", error);
|
||||||
|
let func: Function =
|
||||||
|
lua.globals().get("onCommandRequiredRankMissingError").unwrap();
|
||||||
|
func.call::<()>((error.to_string(), connection_data)).unwrap();
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
if connection.player_data.gm_rank as u8 >= permissions {
|
/* Reset state for future commands. Without this it'll stay set to the last value
|
||||||
|
* and allow other commands that omit required_rank to run, which is undesirable. */
|
||||||
|
lua.globals().set("required_rank", mlua::Value::Nil).unwrap();
|
||||||
|
|
||||||
|
if connection.player_data.gm_rank as u8 >= required_rank.unwrap() {
|
||||||
let mut func_args = "";
|
let mut func_args = "";
|
||||||
if parts.len() > 1 {
|
if parts.len() > 1 {
|
||||||
func_args = &chat_message.message[command_name.len() + 2..];
|
func_args = &chat_message.message[command_name.len() + 2..];
|
||||||
|
@ -552,10 +562,10 @@ async fn client_loop(
|
||||||
unwrap();
|
unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
tracing::info!("User with account_id {} tried to invoke GM command {} they have no permissions for!",
|
tracing::info!("User with account_id {} tried to invoke GM command {} with insufficient privileges!",
|
||||||
connection.player_data.account_id, command_name);
|
connection.player_data.account_id, command_name);
|
||||||
let func: Function =
|
let func: Function =
|
||||||
lua.globals().get("onCommandPermissionError").unwrap();
|
lua.globals().get("onCommandRequiredRankInsufficientError").unwrap();
|
||||||
func.call::<()>(connection_data).unwrap();
|
func.call::<()>(connection_data).unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue