Skip to content

Commit

Permalink
load client and server commands dynamically (issue #51)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo Smit committed Feb 18, 2016
1 parent f883b92 commit ae8ae5a
Show file tree
Hide file tree
Showing 26 changed files with 123 additions and 80 deletions.
Expand Up @@ -15,12 +15,12 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local commands = require "luascripts.wolfadmin.commands"
local commands = require "luascripts.wolfadmin.commands.commands"
local balancer = require "luascripts.wolfadmin.admin.balancer"

function commandBalance(clientId, cmdArguments)
balancer.balance(true, (cmdArguments[1] and cmdArguments[1] == "force"))

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)")
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)")
Expand Up @@ -16,7 +16,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
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)
Expand Up @@ -15,7 +15,7 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local commands = require "luascripts.wolfadmin.commands"
local commands = require "luascripts.wolfadmin.commands.commands"
local voting = require "luascripts.wolfadmin.game.voting"

function commandEnableVote(clientId, cmdArguments)
Expand All @@ -25,4 +25,4 @@ function commandEnableVote(clientId, cmdArguments)

return true
end
commands.register("enablevote", commandEnableVote, "c", "enables next map voting")
commands.addadmin("enablevote", commandEnableVote, "c", "enables next map voting")
Expand Up @@ -16,7 +16,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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"

Expand All @@ -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")
commands.addadmin("greeting", commandGreeting, "Q", "display your personal greeting, if you have one")
Expand Up @@ -15,10 +15,10 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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 = {}
Expand Down Expand Up @@ -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)
commands.addadmin("help", commandHelp, "h", "display commands available to you or help on a specific command", "^9(^hcommand^9)", true)
Expand Up @@ -15,7 +15,7 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local commands = require "luascripts.wolfadmin.commands"
local commands = require "luascripts.wolfadmin.commands.commands"
local stats = require "luascripts.wolfadmin.players.stats"

function commandIncognito(clientId, cmdArguments)
Expand Down Expand Up @@ -74,4 +74,4 @@ function commandIncognito(clientId, cmdArguments)

return true
end
commands.register("incognito", commandIncognito, "s", "fakes your level to guest (no aka)")
commands.addadmin("incognito", commandIncognito, "s", "fakes your level to guest (no aka)")
Expand Up @@ -15,7 +15,7 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local commands = require "luascripts.wolfadmin.commands"
local commands = require "luascripts.wolfadmin.commands.commands"
local bots = require "luascripts.wolfadmin.game.bots"

function commandBotsOff(clientId, cmdArguments)
Expand All @@ -25,4 +25,4 @@ function commandBotsOff(clientId, cmdArguments)

return true
end
commands.register("kickbots", commandBotsOff, "O", "kicks all bots from the game")
commands.addadmin("kickbots", commandBotsOff, "O", "kicks all bots from the game")
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
commands.addadmin("listaliases", commandListAliases, "f", "display all known aliases for a player", "^9[^3name|slot#^9]", function() return (settings.get("db_type") == "cfg") end)
Expand Up @@ -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)
Expand Down Expand Up @@ -88,4 +88,4 @@ function commandListLevels(clientId, cmdArguments)

return true
end
commands.register("listlevels", commandListLevels, "s", "display all levels on the server")
commands.addadmin("listlevels", commandListLevels, "s", "display all levels on the server")
Expand Up @@ -16,7 +16,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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)
Expand All @@ -35,4 +35,4 @@ function commandListMaps(clientId, cmdArguments)

return true
end
commands.register("listmaps", commandListMaps, "C", "display the maps in the rotation")
commands.addadmin("listmaps", commandListMaps, "C", "display the maps in the rotation")
Expand Up @@ -15,7 +15,7 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local commands = require "luascripts.wolfadmin.commands"
local commands = require "luascripts.wolfadmin.commands.commands"
local bots = require "luascripts.wolfadmin.game.bots"

function commandBotsOn(clientId, cmdArguments)
Expand All @@ -25,4 +25,4 @@ function commandBotsOn(clientId, cmdArguments)

return true
end
commands.register("needbots", commandBotsOn, "O", "adds bots to the game")
commands.addadmin("needbots", commandBotsOn, "O", "adds bots to the game")
Expand Up @@ -16,13 +16,13 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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
Expand Down Expand Up @@ -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]")
commands.addadmin("plock", commandPlayerLock, "K", "locks a player to a specific team", "^9[^3name|slot#^9]")
Expand Up @@ -16,13 +16,13 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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
Expand Down Expand Up @@ -53,4 +53,4 @@ function commandPlayerUnlock(clientId, cmdArguments)

return true
end
commands.register("punlock", commandPlayerUnlock, "K", "unlocks a player", "^9[^3name|slot#^9]")
commands.addadmin("punlock", commandPlayerUnlock, "K", "unlocks a player", "^9[^3name|slot#^9]")
Expand Up @@ -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
Expand All @@ -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]")
commands.addadmin("putbots", commandPutBots, "p", "puts all bots into a specific team", "^9[r|b|s]")
Expand Up @@ -16,7 +16,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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"

Expand All @@ -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)
commands.addadmin("readconfig", commandReadconfig, "G", "reloads the shrubbot config file and refreshes user flags", nil, true)
Expand Up @@ -15,7 +15,7 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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"

Expand All @@ -32,4 +32,4 @@ function commandResetSprees(clientId, cmdArguments)

return true
end
commands.register("resetsprees", commandResetSprees, "G", "resets the spree records")
commands.addadmin("resetsprees", commandResetSprees, "G", "resets the spree records")
Expand Up @@ -15,7 +15,7 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local commands = require "luascripts.wolfadmin.commands"
local commands = require "luascripts.wolfadmin.commands.commands"
local rules = require "luascripts.wolfadmin.admin.rules"

function commandRules(clientId, cmdArguments)
Expand All @@ -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)")
commands.addadmin("rules", commandRules, "C", "display the rules on the server", "^9(^hrule^9)")
Expand Up @@ -16,7 +16,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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)
Expand Down Expand Up @@ -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)
commands.addadmin("setlevel", commandSetLevel, "s", "sets the admin level of a player", "^9[^3name|slot#^9] ^9[^3level^9]", true)
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
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)
Expand Up @@ -15,7 +15,7 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local commands = require "luascripts.wolfadmin.commands"
local commands = require "luascripts.wolfadmin.commands.commands"
local sprees = require "luascripts.wolfadmin.game.sprees"

function commandShowSprees(clientId, cmdArguments)
Expand All @@ -37,4 +37,4 @@ function commandShowSprees(clientId, cmdArguments)

return true
end
commands.register("sprees", commandShowSprees, "I", "display the current spree records")
commands.addadmin("sprees", commandShowSprees, "I", "display the current spree records")

0 comments on commit ae8ae5a

Please sign in to comment.