1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-03-19 21:18:01 +02:00

implemented permissions

This commit is contained in:
Valansch 2017-07-09 15:20:01 +02:00
parent 0bc551b10a
commit f83daaffc7
4 changed files with 122 additions and 14 deletions

View File

@ -3,6 +3,7 @@ require "locale/utils/event"
require "config" require "config"
require "locale/utils/utils" require "locale/utils/utils"
require "base_data" require "base_data"
require "user_groups"
require "chatlog" require "chatlog"
require "info" require "info"
require "player_list" require "player_list"

View File

@ -1,9 +1,9 @@
function cant_run(name) function cant_run(name)
game.player.print("Can't run command (" .. name .. ") - you are not an admin.") game.player.print("Can't run command (" .. name .. ") - insufficient permission.")
end end
function invoke(cmd) function invoke(cmd)
if not game.player.admin then if not (game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name) cant_run(cmd.name)
return return
end end
@ -18,7 +18,7 @@ function invoke(cmd)
end end
function teleport_player(cmd) function teleport_player(cmd)
if not game.player.admin then if not (game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name) cant_run(cmd.name)
return return
end end
@ -46,7 +46,7 @@ function teleport_location(cmd)
end end
local function detrain(param) local function detrain(param)
if not game.player.admin then if not (game.player.admin or is_mod(game.player.name)) then
cant_run(param.name) cant_run(param.name)
return return
end end
@ -63,7 +63,7 @@ function kill()
end end
function walkabout(cmd) function walkabout(cmd)
if not game.player.admin then if not (game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name) cant_run(cmd.name)
return return
end end
@ -139,7 +139,7 @@ function walkabout(cmd)
end end
function on_set_time(cmd) function on_set_time(cmd)
if not game.player.admin then if not (game.player.admin or is_regular(game.player.name) or is_mod(game.player.name)) then
cant_run(cmd.name) cant_run(cmd.name)
return return
end end
@ -177,11 +177,64 @@ end
local function clock() local function clock()
game.player.print(format_time(game.tick)) game.player.print(format_time(game.tick))
end end
local function regular(cmd)
if not (game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name)
return
end
if cmd.parameter == nil then
game.player.print("Command failed. Usage: /regular <promote, demote>, <player>")
return
end
local params = {}
for param in string.gmatch(cmd.parameter, "%w+") do table.insert(params, param) end
if params[2] == nil then
game.player.print("Command failed. Usage: /regular <promote, demote>, <player>")
return
elseif (params[1] == "promote") then
add_regular(params[2])
elseif (params[1] == "demote") then
remove_regular(params[2])
else
game.player.print("Command failed. Usage: /regular <promote, demote>, <player>")
end
end
local function mod(cmd)
if not game.player.admin then
cant_run(cmd.name)
return
end
if cmd.parameter == nil then
game.player.print("Command failed. Usage: /mod <promote, demote>, <player>")
return
end
local params = {}
for param in string.gmatch(cmd.parameter, "%w+") do table.insert(params, param) end
if params[2] == nil then
game.player.print("Command failed. Usage: /mod <promote, demote>, <player>")
return
elseif (params[1] == "promote") then
add_mod(params[2])
elseif (params[1] == "demote") then
remove_mod(params[2])
else
game.player.print("Command failed. Usage: /mod <promote, demote>, <player>")
end
end
commands.add_command("kill", "Will kill you.", kill) commands.add_command("kill", "Will kill you.", kill)
commands.add_command("detrain", "<player> - Kicks the player off a train.", detrain) commands.add_command("detrain", "<player> - Kicks the player off a train. (Admins and moderators)", detrain)
commands.add_command("tpplayer", "<player> - Teleports you to the player.", teleport_player) commands.add_command("tpplayer", "<player> - Teleports you to the player. (Admins and moderators)", teleport_player)
commands.add_command("invoke", "<player> - Teleports the player to you.", invoke) commands.add_command("invoke", "<player> - Teleports the player to you. (Admins and moderators)", invoke)
commands.add_command("tppos", "Teleports you to a selected entity.", teleport_location) commands.add_command("tppos", "Teleports you to a selected entity. (Admins only)", teleport_location)
commands.add_command("walkabout", '<player> <"close", "far", "very far", number> - Send someone on a walk.', walkabout) commands.add_command("walkabout", '<player> <"close", "far", "very far", number> - Send someone on a walk. (Admins and moderators)', walkabout)
commands.add_command("settime", '<day> <month> <hour> <minute> - Sets the clock', on_set_time) commands.add_command("settime", '<day> <month> <hour> <minute> - Sets the clock (Admins, moderators and regulars)', on_set_time)
commands.add_command("clock", 'Look at the clock', clock) commands.add_command("clock", 'Look at the clock.', clock)
commands.add_command("regulars", 'Prints a list of game regulars.', print_regulars)
commands.add_command("regular", '<promote, demote>, <player> Change regular status of a player. (Admins and moderators)', regular)
commands.add_command("mods", 'Prints a list of game mods.', print_mods)
commands.add_command("mod", '<promote, demote>, <player> Changes moderator status of a player. (Admins only)', mod)

View File

@ -2,7 +2,7 @@
local function allowed_to_nuke(player) local function allowed_to_nuke(player)
return player.admin or(player.online_time / 216000) > global.scenario.config.nuke_min_time_hours return player.admin or is_mod(player.name) or is_regular(player.name) or ((player.online_time / 216000) > global.scenario.config.nuke_min_time_hours)
end end

54
user_groups.lua Normal file
View File

@ -0,0 +1,54 @@
local mods = {
sanctorio = "",
}
local regulars = {
helpower2 = "",
}
function is_mod(player_name)
return not (mods[player_name] == nil)
end
function is_regular(player_name)
return not (regulars[player_name] == nil)
end
function add_regular(player_name)
if is_regular(player_name) then game.player.print(player_name .. " was already a regular.")
else
game.print(game.player.name .. " promoted " .. player_name .. " to regular.")
end
regulars[player_name] = ""
end
function add_mod(player_name)
if is_mod(player_name) then game.player.print(player_name .. " was already a moderator.")
else
game.print(game.player.name .. " promoted " .. player_name .. " to moderator.")
end
mods[player_name] = ""
end
function remove_regular(player_name)
if is_regular(player_name) then game.print(player_name .. " was demoted from regular by " .. game.player.name .. ".") end
regulars[player_name] = nil
end
function remove_mod(player_name)
if is_mod(player_name) then game.print(player_name .. " was demoted from mod by " .. game.player.name .. ".") end
mods[player_name] = nil
end
function print_regulars()
for k,_ in pairs(regulars) do
game.player.print(k)
end
end
function print_mods()
for k,_ in pairs(mods) do
game.player.print(k)
end
end