Command use now in rank table

This commit is contained in:
Cooldude2606
2017-09-14 19:11:42 +01:00
parent f8a7d14e42
commit af82181886
2 changed files with 19 additions and 17 deletions

View File

@@ -49,15 +49,13 @@ end
--name is what is used in /command --name is what is used in /command
--help is the help info given --help is the help info given
--inputs is a list i.e. {'name','message',true} the last value being true opposed to a string allows a variable number of words for the last input i.e. message can be multiple words long --inputs is a list i.e. {'name','message',true} the last value being true opposed to a string allows a variable number of words for the last input i.e. message can be multiple words long
--restriction is the lowest rank that can use the command
--event(player,event,args) if the function that will be ran on the command use --event(player,event,args) if the function that will be ran on the command use
function define_command(name,help,inputs,restriction,event) function define_command(name,help,inputs,event)
if not name then error('Command requires a name') end if not name then error('Command requires a name') end
local help = help or 'No Help Given' local help = help or 'No Help Given'
local inputs = inputs or {true} local inputs = inputs or {true}
local restriction = restriction or 0
if not event or type(event) ~= 'function' then error('Command requires a function') end if not event or type(event) ~= 'function' then error('Command requires a function') end
table.insert(Exp_commands,{name=name,help=help,inputs=inputs,restriction=restriction,event=event}) table.insert(Exp_commands,{name=name,help=help,inputs=inputs,event=event})
end end
--The magic for the commands. It is a hard bit of code so GL; but it will call the command event have some sanitisaion of the input --The magic for the commands. It is a hard bit of code so GL; but it will call the command event have some sanitisaion of the input
function load_command(command) function load_command(command)
@@ -68,10 +66,7 @@ function load_command(command)
for _,command_d in pairs(Exp_commands) do if event.name == command_d[1] then command_data = command_d break end end for _,command_d in pairs(Exp_commands) do if event.name == command_d[1] then command_data = command_d break end end
if event.player_index then if event.player_index then
local player = game.players[event.player_index] local player = game.players[event.player_index]
local temp_restriction = nil if rank_allowed(get_rank(player),command.name) then
if type(command.restriction) == 'number' then temp_restriction = command.restriction end
local restriction = temp_restriction or string_to_rank(command.restriction).power or 0
if get_rank(player).power > restriction then
player.print('401 - Unauthorized: Access is denied due to invalid credentials') player.print('401 - Unauthorized: Access is denied due to invalid credentials')
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Failed to use command (Unauthorized): '..command.name..' With args of: '..table.to_string(get_command_args(event,command,true)), true, 0) game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Failed to use command (Unauthorized): '..command.name..' With args of: '..table.to_string(get_command_args(event,command,true)), true, 0)
return return
@@ -98,10 +93,7 @@ function get_commands(rank)
local rank = rank or 'Owner' local rank = rank or 'Owner'
local to_return = {} local to_return = {}
for _,command in pairs(global.commands) do for _,command in pairs(global.commands) do
local temp_restriction = nil if rank_allowed(string_to_rank(rank),command.name) then table.insert(to_return,command) end
if type(command.restriction) == 'number' then temp_restriction = command.restriction end
local restriction = temp_restriction or string_to_rank(command.restriction).power or 0
if restriction > string_to_rank(rank).power then table.insert(to_return,command) end
end end
return to_return return to_return
end end

View File

@@ -60,7 +60,8 @@ local ranks = {
time=nil, time=nil,
colour={r=179,g=125,b=46}, colour={r=179,g=125,b=46},
disallow={}, disallow={},
allow={}}, allow={}
},
{name='Admin', {name='Admin',
short_hand='Admin', short_hand='Admin',
@@ -72,7 +73,9 @@ local ranks = {
'edit_permission_group', 'edit_permission_group',
'delete_permission_group', 'delete_permission_group',
'add_permission_group'}, 'add_permission_group'},
allow={} allow={
'server-interface',
'tp-all'}
}, },
{name='Mod', {name='Mod',
@@ -82,7 +85,9 @@ local ranks = {
colour={r=0,g=170,b=0}, colour={r=0,g=170,b=0},
disallow={ disallow={
'server_command'}, 'server_command'},
allow={} allow={
'temp-ban'
}
}, },
{name='Donator', {name='Donator',
@@ -91,7 +96,10 @@ local ranks = {
time=nil, time=nil,
colour={r=233,g=63,b=233}, colour={r=233,g=63,b=233},
disallow={}, disallow={},
allow={}}, allow={
'tp',
'repair'}
},
{name='Veteran', {name='Veteran',
short_hand='Vet', short_hand='Vet',
@@ -132,7 +140,9 @@ local ranks = {
'launch_rocket', 'launch_rocket',
'reset_assembling_machine', 'reset_assembling_machine',
'cancel_research'}, 'cancel_research'},
allow={} allow={
'kill',
'tag'}
}, },
{name='Jail', {name='Jail',