From ae8ae5a41793f2649210bb9837b8e1252947027b Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Thu, 18 Feb 2016 19:42:17 +0100 Subject: [PATCH] load client and server commands dynamically (issue #51) --- luascripts/commands/{ => admin}/balance.lua | 4 +- luascripts/commands/{ => admin}/dewarn.lua | 6 +- .../commands/{ => admin}/enablevote.lua | 4 +- luascripts/commands/{ => admin}/greeting.lua | 4 +- luascripts/commands/{ => admin}/help.lua | 6 +- luascripts/commands/{ => admin}/incognito.lua | 4 +- luascripts/commands/{ => admin}/kickbots.lua | 4 +- .../commands/{ => admin}/listaliases.lua | 6 +- .../commands/{ => admin}/listlevels.lua | 4 +- luascripts/commands/{ => admin}/listmaps.lua | 4 +- luascripts/commands/{ => admin}/needbots.lua | 4 +- luascripts/commands/{ => admin}/plock.lua | 6 +- luascripts/commands/{ => admin}/punlock.lua | 6 +- luascripts/commands/{ => admin}/putbots.lua | 6 +- .../commands/{ => admin}/readconfig.lua | 4 +- .../commands/{ => admin}/resetsprees.lua | 4 +- luascripts/commands/{ => admin}/rules.lua | 4 +- luascripts/commands/{ => admin}/setlevel.lua | 4 +- luascripts/commands/{ => admin}/showwarns.lua | 6 +- luascripts/commands/{ => admin}/sprees.lua | 4 +- luascripts/commands/{ => admin}/stats.lua | 6 +- luascripts/commands/{ => admin}/vmute.lua | 8 +- luascripts/commands/{ => admin}/vunmute.lua | 6 +- luascripts/commands/{ => admin}/warn.lua | 4 +- luascripts/{ => commands}/commands.lua | 83 ++++++++++++++----- luascripts/main.lua | 2 +- 26 files changed, 123 insertions(+), 80 deletions(-) rename luascripts/commands/{ => admin}/balance.lua (86%) rename luascripts/commands/{ => admin}/dewarn.lua (91%) rename luascripts/commands/{ => admin}/enablevote.lua (87%) rename luascripts/commands/{ => admin}/greeting.lua (88%) rename luascripts/commands/{ => admin}/help.lua (94%) rename luascripts/commands/{ => admin}/incognito.lua (95%) rename luascripts/commands/{ => admin}/kickbots.lua (87%) rename luascripts/commands/{ => admin}/listaliases.lua (92%) rename luascripts/commands/{ => admin}/listlevels.lua (96%) rename luascripts/commands/{ => admin}/listmaps.lua (89%) rename luascripts/commands/{ => admin}/needbots.lua (87%) rename luascripts/commands/{ => admin}/plock.lua (91%) rename luascripts/commands/{ => admin}/punlock.lua (90%) rename luascripts/commands/{ => admin}/putbots.lua (88%) rename luascripts/commands/{ => admin}/readconfig.lua (86%) rename luascripts/commands/{ => admin}/resetsprees.lua (89%) rename luascripts/commands/{ => admin}/rules.lua (91%) rename luascripts/commands/{ => admin}/setlevel.lua (92%) rename luascripts/commands/{ => admin}/showwarns.lua (93%) rename luascripts/commands/{ => admin}/sprees.lua (92%) rename luascripts/commands/{ => admin}/stats.lua (95%) rename luascripts/commands/{ => admin}/vmute.lua (91%) rename luascripts/commands/{ => admin}/vunmute.lua (89%) rename luascripts/commands/{ => admin}/warn.lua (91%) rename luascripts/{ => commands}/commands.lua (87%) diff --git a/luascripts/commands/balance.lua b/luascripts/commands/admin/balance.lua similarity index 86% rename from luascripts/commands/balance.lua rename to luascripts/commands/admin/balance.lua index 603a184..7e35462 100644 --- a/luascripts/commands/balance.lua +++ b/luascripts/commands/admin/balance.lua @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local balancer = require "luascripts.wolfadmin.admin.balancer" function commandBalance(clientId, cmdArguments) @@ -23,4 +23,4 @@ function commandBalance(clientId, cmdArguments) return true end -commands.register("balance", commandBalance, "p", "either asks the players to even up or evens them by moving or shuffling players", "^2!balance ^9(^hforce^9)") \ No newline at end of file +commands.addadmin("balance", commandBalance, "p", "either asks the players to even up or evens them by moving or shuffling players", "^2!balance ^9(^hforce^9)") \ No newline at end of file diff --git a/luascripts/commands/dewarn.lua b/luascripts/commands/admin/dewarn.lua similarity index 91% rename from luascripts/commands/dewarn.lua rename to luascripts/commands/admin/dewarn.lua index a09a964..0445600 100644 --- a/luascripts/commands/dewarn.lua +++ b/luascripts/commands/admin/dewarn.lua @@ -16,7 +16,7 @@ -- along with this program. If not, see . local settings = require "luascripts.wolfadmin.util.settings" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local warns = require "luascripts.wolfadmin.admin.warns" function commandRemoveWarn(clientId, cmdArguments) @@ -25,7 +25,7 @@ function commandRemoveWarn(clientId, cmdArguments) return true elseif #cmdArguments < 2 or tonumber(cmdArguments[2]) == nil then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^ddewarn usage: "..commands.get("dewarn")["syntax"].."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^ddewarn usage: "..commands.getadmin("dewarn")["syntax"].."\";") return true elseif tonumber(cmdArguments[1]) == nil then @@ -56,4 +56,4 @@ function commandRemoveWarn(clientId, cmdArguments) return true end -commands.register("dewarn", commandRemoveWarn, "R", "remove a warning for a certain player", "^9[^3name|slot#^9] ^9[^3warn#^9]", function() return (settings.get("g_warnHistory") == 0 or settings.get("db_type") == "cfg") end) \ No newline at end of file +commands.addadmin("dewarn", commandRemoveWarn, "R", "remove a warning for a certain player", "^9[^3name|slot#^9] ^9[^3warn#^9]", function() return (settings.get("g_warnHistory") == 0 or settings.get("db_type") == "cfg") end) \ No newline at end of file diff --git a/luascripts/commands/enablevote.lua b/luascripts/commands/admin/enablevote.lua similarity index 87% rename from luascripts/commands/enablevote.lua rename to luascripts/commands/admin/enablevote.lua index e82d18e..b3ae804 100644 --- a/luascripts/commands/enablevote.lua +++ b/luascripts/commands/admin/enablevote.lua @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local voting = require "luascripts.wolfadmin.game.voting" function commandEnableVote(clientId, cmdArguments) @@ -25,4 +25,4 @@ function commandEnableVote(clientId, cmdArguments) return true end -commands.register("enablevote", commandEnableVote, "c", "enables next map voting") \ No newline at end of file +commands.addadmin("enablevote", commandEnableVote, "c", "enables next map voting") \ No newline at end of file diff --git a/luascripts/commands/greeting.lua b/luascripts/commands/admin/greeting.lua similarity index 88% rename from luascripts/commands/greeting.lua rename to luascripts/commands/admin/greeting.lua index 88fda18..8f995b7 100644 --- a/luascripts/commands/greeting.lua +++ b/luascripts/commands/admin/greeting.lua @@ -16,7 +16,7 @@ -- along with this program. If not, see . local util = require "luascripts.wolfadmin.util.util" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local settings = require "luascripts.wolfadmin.util.settings" local greetings = require "luascripts.wolfadmin.players.greetings" @@ -29,4 +29,4 @@ function commandGreeting(clientId, cmdArguments) et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dgreeting: ^9you do not have a personal greeting.\";") end end -commands.register("greeting", commandGreeting, "Q", "display your personal greeting, if you have one") \ No newline at end of file +commands.addadmin("greeting", commandGreeting, "Q", "display your personal greeting, if you have one") \ No newline at end of file diff --git a/luascripts/commands/help.lua b/luascripts/commands/admin/help.lua similarity index 94% rename from luascripts/commands/help.lua rename to luascripts/commands/admin/help.lua index 29a35b5..5906ca2 100644 --- a/luascripts/commands/help.lua +++ b/luascripts/commands/admin/help.lua @@ -15,10 +15,10 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" function commandHelp(clientId, cmdArguments) - local cmds = commands.get() + local cmds = commands.getadmin() if #cmdArguments == 0 then local availableCommands = {} @@ -66,4 +66,4 @@ function commandHelp(clientId, cmdArguments) return false end -commands.register("help", commandHelp, "h", "display commands available to you or help on a specific command", "^9(^hcommand^9)", true) \ No newline at end of file +commands.addadmin("help", commandHelp, "h", "display commands available to you or help on a specific command", "^9(^hcommand^9)", true) \ No newline at end of file diff --git a/luascripts/commands/incognito.lua b/luascripts/commands/admin/incognito.lua similarity index 95% rename from luascripts/commands/incognito.lua rename to luascripts/commands/admin/incognito.lua index a19c08a..8012e25 100644 --- a/luascripts/commands/incognito.lua +++ b/luascripts/commands/admin/incognito.lua @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local stats = require "luascripts.wolfadmin.players.stats" function commandIncognito(clientId, cmdArguments) @@ -74,4 +74,4 @@ function commandIncognito(clientId, cmdArguments) return true end -commands.register("incognito", commandIncognito, "s", "fakes your level to guest (no aka)") \ No newline at end of file +commands.addadmin("incognito", commandIncognito, "s", "fakes your level to guest (no aka)") \ No newline at end of file diff --git a/luascripts/commands/kickbots.lua b/luascripts/commands/admin/kickbots.lua similarity index 87% rename from luascripts/commands/kickbots.lua rename to luascripts/commands/admin/kickbots.lua index 533f31d..47b2084 100644 --- a/luascripts/commands/kickbots.lua +++ b/luascripts/commands/admin/kickbots.lua @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local bots = require "luascripts.wolfadmin.game.bots" function commandBotsOff(clientId, cmdArguments) @@ -25,4 +25,4 @@ function commandBotsOff(clientId, cmdArguments) return true end -commands.register("kickbots", commandBotsOff, "O", "kicks all bots from the game") \ No newline at end of file +commands.addadmin("kickbots", commandBotsOff, "O", "kicks all bots from the game") \ No newline at end of file diff --git a/luascripts/commands/listaliases.lua b/luascripts/commands/admin/listaliases.lua similarity index 92% rename from luascripts/commands/listaliases.lua rename to luascripts/commands/admin/listaliases.lua index f692031..631fae1 100644 --- a/luascripts/commands/listaliases.lua +++ b/luascripts/commands/admin/listaliases.lua @@ -18,7 +18,7 @@ local util = require "luascripts.wolfadmin.util.util" local settings = require "luascripts.wolfadmin.util.settings" local db = require "luascripts.wolfadmin.db.db" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local stats = require "luascripts.wolfadmin.players.stats" function commandListAliases(clientId, cmdArguments) @@ -27,7 +27,7 @@ function commandListAliases(clientId, cmdArguments) return true elseif cmdArguments[1] == nil then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistaliases usage: "..commands.get("listaliases")["syntax"].."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistaliases usage: "..commands.getadmin("listaliases")["syntax"].."\";") return true elseif tonumber(cmdArguments[1]) == nil then @@ -71,4 +71,4 @@ function commandListAliases(clientId, cmdArguments) return true end -commands.register("listaliases", commandListAliases, "f", "display all known aliases for a player", "^9[^3name|slot#^9]", function() return (settings.get("db_type") == "cfg") end) \ No newline at end of file +commands.addadmin("listaliases", commandListAliases, "f", "display all known aliases for a player", "^9[^3name|slot#^9]", function() return (settings.get("db_type") == "cfg") end) \ No newline at end of file diff --git a/luascripts/commands/listlevels.lua b/luascripts/commands/admin/listlevels.lua similarity index 96% rename from luascripts/commands/listlevels.lua rename to luascripts/commands/admin/listlevels.lua index 8f2f3b5..47e9cd2 100644 --- a/luascripts/commands/listlevels.lua +++ b/luascripts/commands/admin/listlevels.lua @@ -18,7 +18,7 @@ local util = require "luascripts.wolfadmin.util.util" local settings = require "luascripts.wolfadmin.util.settings" local db = require "luascripts.wolfadmin.db.db" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local stats = require "luascripts.wolfadmin.players.stats" function commandListLevels(clientId, cmdArguments) @@ -88,4 +88,4 @@ function commandListLevels(clientId, cmdArguments) return true end -commands.register("listlevels", commandListLevels, "s", "display all levels on the server") \ No newline at end of file +commands.addadmin("listlevels", commandListLevels, "s", "display all levels on the server") \ No newline at end of file diff --git a/luascripts/commands/listmaps.lua b/luascripts/commands/admin/listmaps.lua similarity index 89% rename from luascripts/commands/listmaps.lua rename to luascripts/commands/admin/listmaps.lua index 60a3efe..e352cdc 100644 --- a/luascripts/commands/listmaps.lua +++ b/luascripts/commands/admin/listmaps.lua @@ -16,7 +16,7 @@ -- along with this program. If not, see . local util = require "luascripts.wolfadmin.util.util" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local game = require "luascripts.wolfadmin.game.game" function commandListMaps(clientId, cmdArguments) @@ -35,4 +35,4 @@ function commandListMaps(clientId, cmdArguments) return true end -commands.register("listmaps", commandListMaps, "C", "display the maps in the rotation") \ No newline at end of file +commands.addadmin("listmaps", commandListMaps, "C", "display the maps in the rotation") \ No newline at end of file diff --git a/luascripts/commands/needbots.lua b/luascripts/commands/admin/needbots.lua similarity index 87% rename from luascripts/commands/needbots.lua rename to luascripts/commands/admin/needbots.lua index 0637541..9f8f077 100644 --- a/luascripts/commands/needbots.lua +++ b/luascripts/commands/admin/needbots.lua @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local bots = require "luascripts.wolfadmin.game.bots" function commandBotsOn(clientId, cmdArguments) @@ -25,4 +25,4 @@ function commandBotsOn(clientId, cmdArguments) return true end -commands.register("needbots", commandBotsOn, "O", "adds bots to the game") \ No newline at end of file +commands.addadmin("needbots", commandBotsOn, "O", "adds bots to the game") \ No newline at end of file diff --git a/luascripts/commands/plock.lua b/luascripts/commands/admin/plock.lua similarity index 91% rename from luascripts/commands/plock.lua rename to luascripts/commands/admin/plock.lua index 8910549..a3b56fd 100644 --- a/luascripts/commands/plock.lua +++ b/luascripts/commands/admin/plock.lua @@ -16,13 +16,13 @@ -- along with this program. If not, see . local util = require "luascripts.wolfadmin.util.util" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local admin = require "luascripts.wolfadmin.admin.admin" local stats = require "luascripts.wolfadmin.players.stats" function commandPlayerLock(clientId, cmdArguments) if cmdArguments[1] == nil then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock usage: "..commands.get("vmute")["syntax"].."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock usage: "..commands.getadmin("vmute")["syntax"].."\";") return true elseif tonumber(cmdArguments[1]) == nil then @@ -61,4 +61,4 @@ function commandPlayerLock(clientId, cmdArguments) return true end -commands.register("plock", commandPlayerLock, "K", "locks a player to a specific team", "^9[^3name|slot#^9]") \ No newline at end of file +commands.addadmin("plock", commandPlayerLock, "K", "locks a player to a specific team", "^9[^3name|slot#^9]") \ No newline at end of file diff --git a/luascripts/commands/punlock.lua b/luascripts/commands/admin/punlock.lua similarity index 90% rename from luascripts/commands/punlock.lua rename to luascripts/commands/admin/punlock.lua index 33afcad..2cbb898 100644 --- a/luascripts/commands/punlock.lua +++ b/luascripts/commands/admin/punlock.lua @@ -16,13 +16,13 @@ -- along with this program. If not, see . local util = require "luascripts.wolfadmin.util.util" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local admin = require "luascripts.wolfadmin.admin.admin" local stats = require "luascripts.wolfadmin.players.stats" function commandPlayerUnlock(clientId, cmdArguments) if cmdArguments[1] == nil then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dpunlock usage: "..commands.get("vmute")["syntax"].."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dpunlock usage: "..commands.getadmin("vmute")["syntax"].."\";") return true elseif tonumber(cmdArguments[1]) == nil then @@ -53,4 +53,4 @@ function commandPlayerUnlock(clientId, cmdArguments) return true end -commands.register("punlock", commandPlayerUnlock, "K", "unlocks a player", "^9[^3name|slot#^9]") \ No newline at end of file +commands.addadmin("punlock", commandPlayerUnlock, "K", "unlocks a player", "^9[^3name|slot#^9]") \ No newline at end of file diff --git a/luascripts/commands/putbots.lua b/luascripts/commands/admin/putbots.lua similarity index 88% rename from luascripts/commands/putbots.lua rename to luascripts/commands/admin/putbots.lua index 21345d6..7ce2cc9 100644 --- a/luascripts/commands/putbots.lua +++ b/luascripts/commands/admin/putbots.lua @@ -17,12 +17,12 @@ local constants = require "luascripts.wolfadmin.util.constants" local util = require "luascripts.wolfadmin.util.util" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local bots = require "luascripts.wolfadmin.game.bots" function commandPutBots(clientId, cmdArguments) if cmdArguments[1] == nil and cmdArguments[1] ~= constants.TEAM_AXIS_SC and cmdArguments[1] ~= constants.TEAM_ALLIES_SC and cmdArguments[1] ~= constants.TEAM_SPECTATORS_SC then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dputbots usage: "..commands.get("vmute")["syntax"].."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dputbots usage: "..commands.getadmin("vmute")["syntax"].."\";") return true end @@ -44,4 +44,4 @@ function commandPutBots(clientId, cmdArguments) return true end -commands.register("putbots", commandPutBots, "p", "puts all bots into a specific team", "^9[r|b|s]") \ No newline at end of file +commands.addadmin("putbots", commandPutBots, "p", "puts all bots into a specific team", "^9[r|b|s]") \ No newline at end of file diff --git a/luascripts/commands/readconfig.lua b/luascripts/commands/admin/readconfig.lua similarity index 86% rename from luascripts/commands/readconfig.lua rename to luascripts/commands/admin/readconfig.lua index dacf6d6..6baaff0 100644 --- a/luascripts/commands/readconfig.lua +++ b/luascripts/commands/admin/readconfig.lua @@ -16,7 +16,7 @@ -- along with this program. If not, see . local settings = require "luascripts.wolfadmin.util.settings" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local rules = require "luascripts.wolfadmin.admin.rules" local greetings = require "luascripts.wolfadmin.players.greetings" @@ -29,4 +29,4 @@ function commandReadconfig(clientId, cmdArguments) return false end -commands.register("readconfig", commandReadconfig, "G", "reloads the shrubbot config file and refreshes user flags", nil, true) \ No newline at end of file +commands.addadmin("readconfig", commandReadconfig, "G", "reloads the shrubbot config file and refreshes user flags", nil, true) \ No newline at end of file diff --git a/luascripts/commands/resetsprees.lua b/luascripts/commands/admin/resetsprees.lua similarity index 89% rename from luascripts/commands/resetsprees.lua rename to luascripts/commands/admin/resetsprees.lua index 590e4e5..c914f6c 100644 --- a/luascripts/commands/resetsprees.lua +++ b/luascripts/commands/admin/resetsprees.lua @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local game = require "luascripts.wolfadmin.game.game" local sprees = require "luascripts.wolfadmin.game.sprees" @@ -32,4 +32,4 @@ function commandResetSprees(clientId, cmdArguments) return true end -commands.register("resetsprees", commandResetSprees, "G", "resets the spree records") \ No newline at end of file +commands.addadmin("resetsprees", commandResetSprees, "G", "resets the spree records") \ No newline at end of file diff --git a/luascripts/commands/rules.lua b/luascripts/commands/admin/rules.lua similarity index 91% rename from luascripts/commands/rules.lua rename to luascripts/commands/admin/rules.lua index 07c8331..47d1ab6 100644 --- a/luascripts/commands/rules.lua +++ b/luascripts/commands/admin/rules.lua @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local rules = require "luascripts.wolfadmin.admin.rules" function commandRules(clientId, cmdArguments) @@ -42,4 +42,4 @@ function commandRules(clientId, cmdArguments) return true end -commands.register("rules", commandRules, "C", "display the rules on the server", "^9(^hrule^9)") \ No newline at end of file +commands.addadmin("rules", commandRules, "C", "display the rules on the server", "^9(^hrule^9)") \ No newline at end of file diff --git a/luascripts/commands/setlevel.lua b/luascripts/commands/admin/setlevel.lua similarity index 92% rename from luascripts/commands/setlevel.lua rename to luascripts/commands/admin/setlevel.lua index 4cbf946..3b78549 100644 --- a/luascripts/commands/setlevel.lua +++ b/luascripts/commands/admin/setlevel.lua @@ -16,7 +16,7 @@ -- along with this program. If not, see . local settings = require "luascripts.wolfadmin.util.settings" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local admin = require "luascripts.wolfadmin.admin.admin" function commandSetLevel(clientId, cmdArguments) @@ -45,4 +45,4 @@ function commandSetLevel(clientId, cmdArguments) return false end -commands.register("setlevel", commandSetLevel, "s", "sets the admin level of a player", "^9[^3name|slot#^9] ^9[^3level^9]", true) \ No newline at end of file +commands.addadmin("setlevel", commandSetLevel, "s", "sets the admin level of a player", "^9[^3name|slot#^9] ^9[^3level^9]", true) \ No newline at end of file diff --git a/luascripts/commands/showwarns.lua b/luascripts/commands/admin/showwarns.lua similarity index 93% rename from luascripts/commands/showwarns.lua rename to luascripts/commands/admin/showwarns.lua index 825f1ce..b44b9ff 100644 --- a/luascripts/commands/showwarns.lua +++ b/luascripts/commands/admin/showwarns.lua @@ -19,7 +19,7 @@ local util = require "luascripts.wolfadmin.util.util" local settings = require "luascripts.wolfadmin.util.settings" local db = require "luascripts.wolfadmin.db.db" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local warns = require "luascripts.wolfadmin.admin.warns" function commandShowWarns(clientId, cmdArguments) @@ -28,7 +28,7 @@ function commandShowWarns(clientId, cmdArguments) return true elseif cmdArguments[1] == nil then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowwarns usage: "..commands.get("showwarns")["syntax"].."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowwarns usage: "..commands.getadmin("showwarns")["syntax"].."\";") return true elseif tonumber(cmdArguments[1]) == nil then @@ -62,4 +62,4 @@ function commandShowWarns(clientId, cmdArguments) return true end -commands.register("showwarns", commandShowWarns, "R", "display warnings for a specific player", "^9[^3name|slot#^9]", function() return (settings.get("g_warnHistory") == 0 or settings.get("db_type") == "cfg") end) \ No newline at end of file +commands.addadmin("showwarns", commandShowWarns, "R", "display warnings for a specific player", "^9[^3name|slot#^9]", function() return (settings.get("g_warnHistory") == 0 or settings.get("db_type") == "cfg") end) \ No newline at end of file diff --git a/luascripts/commands/sprees.lua b/luascripts/commands/admin/sprees.lua similarity index 92% rename from luascripts/commands/sprees.lua rename to luascripts/commands/admin/sprees.lua index 1fc7dd8..7d713fa 100644 --- a/luascripts/commands/sprees.lua +++ b/luascripts/commands/admin/sprees.lua @@ -15,7 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local sprees = require "luascripts.wolfadmin.game.sprees" function commandShowSprees(clientId, cmdArguments) @@ -37,4 +37,4 @@ function commandShowSprees(clientId, cmdArguments) return true end -commands.register("sprees", commandShowSprees, "I", "display the current spree records") \ No newline at end of file +commands.addadmin("sprees", commandShowSprees, "I", "display the current spree records") \ No newline at end of file diff --git a/luascripts/commands/stats.lua b/luascripts/commands/admin/stats.lua similarity index 95% rename from luascripts/commands/stats.lua rename to luascripts/commands/admin/stats.lua index 59487d5..3433921 100644 --- a/luascripts/commands/stats.lua +++ b/luascripts/commands/admin/stats.lua @@ -16,11 +16,11 @@ -- along with this program. If not, see . local util = require "luascripts.wolfadmin.util.util" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" function commandShowStats(clientId, cmdArguments) if cmdArguments[1] == nil then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dstats usage: "..commands.get("stats")["syntax"].."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dstats usage: "..commands.getadmin("stats")["syntax"].."\";") return true elseif tonumber(cmdArguments[1]) == nil then @@ -94,4 +94,4 @@ function commandShowStats(clientId, cmdArguments) return true end -commands.register("stats", commandShowStats, "I", "display the statistics for a specific player", "^9[^3name|slot#^9]") \ No newline at end of file +commands.addadmin("stats", commandShowStats, "I", "display the statistics for a specific player", "^9[^3name|slot#^9]") \ No newline at end of file diff --git a/luascripts/commands/vmute.lua b/luascripts/commands/admin/vmute.lua similarity index 91% rename from luascripts/commands/vmute.lua rename to luascripts/commands/admin/vmute.lua index 43ede05..dd5f8ba 100644 --- a/luascripts/commands/vmute.lua +++ b/luascripts/commands/admin/vmute.lua @@ -16,12 +16,12 @@ -- along with this program. If not, see . local util = require "luascripts.wolfadmin.util.util" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local admin = require "luascripts.wolfadmin.admin.admin" function commandVoiceMute(clientId, cmdArguments) if cmdArguments[1] == nil then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute usage: "..commands.get("vmute")["syntax"].."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute usage: "..commands.getadmin("vmute")["syntax"].."\";") return true elseif tonumber(cmdArguments[1]) == nil then @@ -50,7 +50,7 @@ function commandVoiceMute(clientId, cmdArguments) elseif cmdArguments[2] then vmuteReason = table.concat(cmdArguments, " ", 2) elseif et.G_shrubbot_permission(clientId, "8") ~= 1 then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute usage: "..commands.get("vmute")["syntax"].."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute usage: "..commands.getadmin("vmute")["syntax"].."\";") return true end @@ -75,4 +75,4 @@ function commandVoiceMute(clientId, cmdArguments) return true end -commands.register("vmute", commandVoiceMute, "m", "voicemutes a player", "^9[^3name|slot#^9]") \ No newline at end of file +commands.addadmin("vmute", commandVoiceMute, "m", "voicemutes a player", "^9[^3name|slot#^9]") \ No newline at end of file diff --git a/luascripts/commands/vunmute.lua b/luascripts/commands/admin/vunmute.lua similarity index 89% rename from luascripts/commands/vunmute.lua rename to luascripts/commands/admin/vunmute.lua index 58e810f..5877309 100644 --- a/luascripts/commands/vunmute.lua +++ b/luascripts/commands/admin/vunmute.lua @@ -15,12 +15,12 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local admin = require "luascripts.wolfadmin.admin.admin" function commandVoiceUnmute(clientId, cmdArguments) if cmdArguments[1] == nil then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvunmute usage: "..commands.get("vunmute")["syntax"].."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvunmute usage: "..commands.getadmin("vunmute")["syntax"].."\";") return true elseif tonumber(cmdArguments[1]) == nil then @@ -51,4 +51,4 @@ function commandVoiceUnmute(clientId, cmdArguments) return true end -commands.register("vunmute", commandVoiceUnmute, "m", "unvoicemutes a player", "^9[^3name|slot#^9]") \ No newline at end of file +commands.addadmin("vunmute", commandVoiceUnmute, "m", "unvoicemutes a player", "^9[^3name|slot#^9]") \ No newline at end of file diff --git a/luascripts/commands/warn.lua b/luascripts/commands/admin/warn.lua similarity index 91% rename from luascripts/commands/warn.lua rename to luascripts/commands/admin/warn.lua index d199d20..5ae18d5 100644 --- a/luascripts/commands/warn.lua +++ b/luascripts/commands/admin/warn.lua @@ -16,7 +16,7 @@ -- along with this program. If not, see . local settings = require "luascripts.wolfadmin.util.settings" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local warns = require "luascripts.wolfadmin.admin.warns" function commandAddWarn(clientId, cmdArguments) @@ -40,4 +40,4 @@ function commandAddWarn(clientId, cmdArguments) return false end -commands.register("warn", commandAddWarn, "R", "warns a player by displaying the reason", "^9[^3name|slot#^9] ^9[^3reason^9]", true) \ No newline at end of file +commands.addadmin("warn", commandAddWarn, "R", "warns a player by displaying the reason", "^9[^3name|slot#^9] ^9[^3reason^9]", true) \ No newline at end of file diff --git a/luascripts/commands.lua b/luascripts/commands/commands.lua similarity index 87% rename from luascripts/commands.lua rename to luascripts/commands/commands.lua index ffc54b1..c415f84 100644 --- a/luascripts/commands.lua +++ b/luascripts/commands/commands.lua @@ -26,19 +26,51 @@ local stats = require "luascripts.wolfadmin.players.stats" local commands = {} -- available shrubflags: lqyFHY -local data = {} +local clientcmds = {} +local servercmds = {} +local admincmds = {} -function commands.get(command) +function commands.getclient(command) if command then - return data[command] + return clientcmds[command] end - return data + return clientcmds end -function commands.register(command, func, flag, help, syntax, hidden) - data[command] = { - ["function"] = func, +function commands.getserver(command) + if command then + return servercmds[command] + end + + return servercmds +end + +function commands.getadmin(command) + if command then + return admincmds[command] + end + + return admincmds +end + +function commands.addclient(command, func, flag, syntax) + clientcmds[command] = { + ["function"] = func, + ["flag"] = flag, + ["syntax"] = "^2!"..command..(syntax and " "..syntax or ""), + } +end + +function commands.addserver(command, func) + servercmds[command] = { + ["function"] = func, + } +end + +function commands.addadmin(command, func, flag, help, syntax, hidden) + admincmds[command] = { + ["function"] = func, ["flag"] = flag, ["help"] = help or "N/A", ["syntax"] = "^2!"..command..(syntax and " "..syntax or ""), @@ -46,24 +78,35 @@ function commands.register(command, func, flag, help, syntax, hidden) } end -function commands.load() - local functionStart = et.trap_Milliseconds() - local files = files.ls("commands/") +function commands.loadfiles(dir) local amount = 0 + local files = files.ls("commands/"..dir.."/") for _, file in pairs(files) do if string.match(string.lower(file), "^[a-z]+%.lua$") then - require("luascripts/wolfadmin/commands/"..string.sub(file, 1, string.len(file) - 4)) + require("luascripts/wolfadmin/commands/"..dir.."/"..string.sub(file, 1, string.len(file) - 4)) amount = amount + 1 end end - outputDebug("commands.load(): "..amount.." entries loaded in "..et.trap_Milliseconds() - functionStart.." ms") - return amount end +function commands.load() + local functionStart = et.trap_Milliseconds() + + local clientAmount = commands.loadfiles("client") + local serverAmount = commands.loadfiles("server") + local adminAmount = commands.loadfiles("admin") + + local totalAmount = clientAmount + serverAmount + adminAmount + + outputDebug("commands.load(): "..totalAmount.." entries loaded in "..et.trap_Milliseconds() - functionStart.." ms") + + return totalAmount +end + function commands.log(clientId, command, cmdArguments) local functionStart = et.trap_Milliseconds() local fileDescriptor = files.open(et.trap_Cvar_Get("g_logAdmin"), et.FS_APPEND) @@ -168,14 +211,14 @@ function commands.onservercommand(cmdText) shrubCmd = string.lower(string.sub(cmdText, 2, string.len(cmdText))) end - if data[shrubCmd] and data[shrubCmd]["function"] and data[shrubCmd]["flag"] then + if admincmds[shrubCmd] and admincmds[shrubCmd]["function"] and admincmds[shrubCmd]["flag"] then for i = 1, et.trap_Argc() - shrubArgumentsOffset do shrubArguments[i] = et.trap_Argv(i + shrubArgumentsOffset - 1) end - data[shrubCmd]["function"](-1337, shrubArguments) + admincmds[shrubCmd]["function"](-1337, shrubArguments) - if not data[shrubCmd]["hidden"] then + if not admincmds[shrubCmd]["hidden"] then commands.log(-1, shrubCmd, shrubArguments) end end @@ -326,12 +369,12 @@ function commands.onclientcommand(clientId, cmdText) if shrubCmd then shrubCmd = string.lower(shrubCmd) - if data[shrubCmd] and data[shrubCmd]["function"] and data[shrubCmd]["flag"] then + if admincmds[shrubCmd] and admincmds[shrubCmd]["function"] and admincmds[shrubCmd]["flag"] then if wolfCmd == "say" or (((wolfCmd == "say_team" and et.gentity_get(cmdClient, "sess.sessionTeam") ~= et.TEAM_SPECTATORS) or wolfCmd == "say_buddy") and et.G_shrubbot_permission(clientId, "9") == 1) or (wolfCmd == "!"..shrubCmd and et.G_shrubbot_permission(clientId, "3") == 1) then - if data[shrubCmd]["flag"] ~= "" and et.G_shrubbot_permission(clientId, data[shrubCmd]["flag"]) == 1 then - local isFinished = data[shrubCmd]["function"](clientId, shrubArguments) + if admincmds[shrubCmd]["flag"] ~= "" and et.G_shrubbot_permission(clientId, admincmds[shrubCmd]["flag"]) == 1 then + local isFinished = admincmds[shrubCmd]["function"](clientId, shrubArguments) - if not data[shrubCmd]["hidden"] then + if not admincmds[shrubCmd]["hidden"] then commands.log(clientId, shrubCmd, shrubArguments) end diff --git a/luascripts/main.lua b/luascripts/main.lua index ecceef1..84c06b9 100644 --- a/luascripts/main.lua +++ b/luascripts/main.lua @@ -30,7 +30,7 @@ local balancer = require "luascripts.wolfadmin.admin.balancer" local rules = require "luascripts.wolfadmin.admin.rules" local warns = require "luascripts.wolfadmin.admin.warns" -local commands = require "luascripts.wolfadmin.commands" +local commands = require "luascripts.wolfadmin.commands.commands" local game = require "luascripts.wolfadmin.game.game" local bots = require "luascripts.wolfadmin.game.bots"