From 7cfcedd97bb2e8abded58bf19d9c7650d789b66e Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 9 Apr 2019 21:48:09 +0100 Subject: [PATCH] Added command parse for roles --- config/command_parase_roles.lua | 38 +++++++++++++++++++++++++++++++++ expcore/locale/en.cfg | 11 ++++++---- locale/en/expcore.cfg | 9 ++++---- modules/commands/kill.lua | 11 +++------- modules/commands/tag.lua | 11 +++------- 5 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 config/command_parase_roles.lua diff --git a/config/command_parase_roles.lua b/config/command_parase_roles.lua new file mode 100644 index 00000000..e717cbea --- /dev/null +++ b/config/command_parase_roles.lua @@ -0,0 +1,38 @@ +--- Adds some parse functions that can be used with the role system +local Commands = require 'expcore.commands' +local Roles = require 'expcore.roles' +require 'config.command_parse_general' + +Commands.add_parse('role',function(input,player,reject) + if not role then return end + local role = Roles.get_role_from_any(input) + if not role then + return reject{'expcore-role.reject-role'} + else + return role + end +end) + +Commands.add_parse('player-role',function(input,player,reject) + local input_player = Commands.parse('player',input,player,reject) + if not input_player then return end -- nil check + local player_highest = Roles.get_player_highest_role(player) + local action_player_highest = Roles.get_player_highest_role(input_player) + if player_highest.index < action_player_highest.index then + return input_player + else + return reject{'expcore-roles.reject-player-role'} + end +end) + +Commands.add_parse('player-role-online',function(input,player,reject) + local input_player = Commands.parse('player-rank',input,player,reject) + if not input_player then return end -- nil check + return Commands.parse('player-online',input_player,player,reject) +end) + +Commands.add_parse('player-role-alive',function(input,player,reject) + local input_player = Commands.parse('player-rank',input,player,reject) + if not input_player then return end -- nil check + return Commands.parse('player-alive',input_player,player,reject) +end) \ No newline at end of file diff --git a/expcore/locale/en.cfg b/expcore/locale/en.cfg index f064aa41..82d68681 100644 --- a/expcore/locale/en.cfg +++ b/expcore/locale/en.cfg @@ -1,14 +1,16 @@ +time-symbol-days-short=__1__d + [expcore-commands] unauthorized=Unauthorized, Access is denied due to invalid credentials reject-string-options=Invalid Option, Must be one of: __1__ reject-string-max-length=Invalid Length, Max: __1__ -reject-number=Invalid Number +reject-number=Invalid Number. reject-number-range=Invalid Range, Min (inclusive): __1__, Max (inclusive): __2__ reject-player=Invaild Player Name, __1__ ,try using tab key to auto-complete the name reject-player-online=Player is offline. reject-player-alive=Player is dead. -reject-force=Invaild Force Name -reject-surface=Invaild surface Name +reject-force=Invaild Force Name. +reject-surface=Invaild Surface Name. invalid-inputs=Invalid Input, /__1__ __2__ invalid-param=Invalid Param "__1__"; __2__ command-help=__1__ - __2__ @@ -21,4 +23,5 @@ error-log-format-flag=[ERROR] roleFlag/__1__ :: __2__ error-log-format-promote=[ERROR] rolePromote/__1__ :: __2__ game-message-assign=__1__ has been assigned to __2__ by __3__ game-message-unassign=__1__ has been unassigned from __2__ by __3__ -command-error-higher-role=Unauthorized, __1__ has a higher role than you. \ No newline at end of file +reject-role=Invalid Role Name. +reject-player-role=Player has a higher role. \ No newline at end of file diff --git a/locale/en/expcore.cfg b/locale/en/expcore.cfg index 68a1f9f9..82d68681 100644 --- a/locale/en/expcore.cfg +++ b/locale/en/expcore.cfg @@ -4,13 +4,13 @@ time-symbol-days-short=__1__d unauthorized=Unauthorized, Access is denied due to invalid credentials reject-string-options=Invalid Option, Must be one of: __1__ reject-string-max-length=Invalid Length, Max: __1__ -reject-number=Invalid Number +reject-number=Invalid Number. reject-number-range=Invalid Range, Min (inclusive): __1__, Max (inclusive): __2__ reject-player=Invaild Player Name, __1__ ,try using tab key to auto-complete the name reject-player-online=Player is offline. reject-player-alive=Player is dead. -reject-force=Invaild Force Name -reject-surface=Invaild surface Name +reject-force=Invaild Force Name. +reject-surface=Invaild Surface Name. invalid-inputs=Invalid Input, /__1__ __2__ invalid-param=Invalid Param "__1__"; __2__ command-help=__1__ - __2__ @@ -23,4 +23,5 @@ error-log-format-flag=[ERROR] roleFlag/__1__ :: __2__ error-log-format-promote=[ERROR] rolePromote/__1__ :: __2__ game-message-assign=__1__ has been assigned to __2__ by __3__ game-message-unassign=__1__ has been unassigned from __2__ by __3__ -command-error-higher-role=Unauthorized, __1__ has a higher role than you. \ No newline at end of file +reject-role=Invalid Role Name. +reject-player-role=Player has a higher role. \ No newline at end of file diff --git a/modules/commands/kill.lua b/modules/commands/kill.lua index 2467f5a7..5b4391eb 100644 --- a/modules/commands/kill.lua +++ b/modules/commands/kill.lua @@ -1,9 +1,10 @@ local Commands = require 'expcore.commands' local Roles = require 'expcore.roles' require 'config.command_parse_general' +require 'config.command_parse_role' Commands.new_command('kill','Kills yourself or another player.') -:add_param('player',true,'player-alive') -- the player to kill, must be alive to be valid +:add_param('player',true,'player-role-alive') -- the player to kill, must be alive to be valid :set_defaults{player=function(player) -- default is the player unless they are dead if player.character and player.character.health > 0 then @@ -18,13 +19,7 @@ end} if player == action_player then action_player.character.die() elseif Roles.player_allowed(player,'command/kill/always') then - local player_highest = Roles.get_player_highest_role(player) - local action_player_highest = Roles.get_player_highest_role(action_player) - if player_highest.index < action_player_highest.index then - action_player.character.die() - else - return Commands.error{'expcore-roles.command-error-higher-role',action_player.name} - end + action_player.character.die() else return Commands.error{'expcore-commands.unauthorized'} end diff --git a/modules/commands/tag.lua b/modules/commands/tag.lua index c335e892..177fbd4b 100644 --- a/modules/commands/tag.lua +++ b/modules/commands/tag.lua @@ -1,6 +1,7 @@ local Commands = require 'expcore.commands' local Roles = require 'expcore.roles' require 'config.command_parse_general' +require 'config.command_parse_role' Commands.new_command('tag','Sets your player tag.') :add_param('tag',false,'string-max-length',20) -- new tag for your player max 20 char @@ -10,7 +11,7 @@ Commands.new_command('tag','Sets your player tag.') end) Commands.new_command('tag-clear','Clears your tag. Or another player if you are admin.') -:add_param('player',true,'player') -- player to remove the tag of, nil to apply to self +:add_param('player',true,'player-role') -- player to remove the tag of, nil to apply to self :set_defaults{player=function(player) return player -- default is the user using the command end} @@ -20,13 +21,7 @@ end} action_player.tag = '' elseif Roles.player_allowed(player,'command/clear-tag/always') then -- player given and user is admin so clears that player's tag - local player_highest = Roles.get_player_highest_role(player) - local action_player_highest = Roles.get_player_highest_role(action_player) - if player_highest.index < action_player_highest.index then - action_player.tag = '' - else - return Commands.error{'expcore-roles.command-error-higher-role',action_player.name} - end + action_player.tag = '' else -- user is not admin and tried to clear another users tag return Commands.error{'expcore-commands.unauthorized'}