Skip to content

Commit

Permalink
Commands now make use of lua's ellipsis instead of cmdArguments (refs…
Browse files Browse the repository at this point in the history
… #62)
  • Loading branch information
Timo Smit committed Jan 26, 2017
1 parent 5df8c28 commit ad7b7c6
Show file tree
Hide file tree
Showing 61 changed files with 335 additions and 371 deletions.
2 changes: 1 addition & 1 deletion luamods/wolfadmin/commands/admin/admintest.lua
Expand Up @@ -23,7 +23,7 @@ local players = require (wolfa_getLuaPath()..".players.players")

local settings = require (wolfa_getLuaPath()..".util.settings")

function commandAdminTest(clientId, cmdArguments)
function commandAdminTest(clientId, command)
local level = auth.getPlayerLevel(clientId)
local levelName = auth.getLevelName(level)

Expand Down
8 changes: 4 additions & 4 deletions luamods/wolfadmin/commands/admin/balance.lua
Expand Up @@ -19,24 +19,24 @@ local commands = require (wolfa_getLuaPath()..".commands.commands")
local auth = require (wolfa_getLuaPath()..".auth.auth")
local balancer = require (wolfa_getLuaPath()..".admin.balancer")

function commandBalance(clientId, cmdArguments)
if cmdArguments[1] == "enable" then
function commandBalance(clientId, command, action)
if action == "enable" then
if not balancer.isRunning() then
balancer.enable()

et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dbalancer: ^9balancer enabled.\";")
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dbalancer: ^9balancer is already running.\";")
end
elseif cmdArguments[1] == "disable" then
elseif action == "disable" then
if balancer.isRunning() then
balancer.disable()

et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dbalancer: ^9balancer disabled.\";")
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dbalancer: ^9balancer was not running.\";")
end
elseif cmdArguments[1] == "force" then
elseif action == "force" then
balancer.balance(true, true)
else
balancer.balance(true, false)
Expand Down
27 changes: 14 additions & 13 deletions luamods/wolfadmin/commands/admin/ban.lua
Expand Up @@ -25,19 +25,19 @@ local commands = require (wolfa_getLuaPath()..".commands.commands")
local util = require (wolfa_getLuaPath()..".util.util")
local settings = require (wolfa_getLuaPath()..".util.settings")

function commandBan(clientId, cmdArguments)
if cmdArguments[1] == nil then
function commandBan(clientId, command, victim, ...)
if victim == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban usage: "..commands.getadmin("ban")["syntax"].."\";")

return true
elseif tonumber(cmdArguments[1]) == nil or tonumber(cmdArguments[1]) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
cmdClient = et.ClientNumberFromString(cmdArguments[1])
elseif tonumber(victim) == nil or tonumber(victim) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
cmdClient = et.ClientNumberFromString(victim)
else
cmdClient = tonumber(cmdArguments[1])
cmdClient = tonumber(victim)
end

if cmdClient == -1 or cmdClient == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban: ^9no or multiple matches for '^7"..victim.."^9'.\";")

return true
elseif not et.gentity_get(cmdClient, "pers.netname") then
Expand All @@ -46,15 +46,16 @@ function commandBan(clientId, cmdArguments)
return true
end

local args = {...}
local duration, reason = 600, "banned by admin"

if cmdArguments[2] and util.getTimeFromString(cmdArguments[2]) and cmdArguments[3] then
duration = util.getTimeFromString(cmdArguments[2])
reason = table.concat(cmdArguments, " ", 3)
elseif cmdArguments[2] and util.getTimeFromString(cmdArguments[2]) then
duration = util.getTimeFromString(cmdArguments[2])
elseif cmdArguments[2] then
reason = table.concat(cmdArguments, " ", 2)
if args[1] and util.getTimeFromString(args[1]) and args[2] then
duration = util.getTimeFromString(args[1])
reason = table.concat(args, " ", 2)
elseif args[1] and util.getTimeFromString(args[1]) then
duration = util.getTimeFromString(args[1])
elseif args[1] then
reason = table.concat(args, " ")
elseif not auth.isPlayerAllowed(clientId, "8") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban usage: "..commands.getadmin("ban")["syntax"].."\";")

Expand Down
2 changes: 1 addition & 1 deletion luamods/wolfadmin/commands/admin/enablevote.lua
Expand Up @@ -19,7 +19,7 @@ local commands = require (wolfa_getLuaPath()..".commands.commands")
local auth = require (wolfa_getLuaPath()..".auth.auth")
local voting = require (wolfa_getLuaPath()..".game.voting")

function commandEnableVote(clientId, cmdArguments)
function commandEnableVote(clientId, command, ...)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^denablevote: ^9next map voting has been enabled.\";")

voting.force("nextmap")
Expand Down
12 changes: 6 additions & 6 deletions luamods/wolfadmin/commands/admin/finger.lua
Expand Up @@ -24,19 +24,19 @@ local players = require (wolfa_getLuaPath()..".players.players")
local settings = require (wolfa_getLuaPath()..".util.settings")
local util = require (wolfa_getLuaPath()..".util.util")

function commandFinger(clientId, cmdArguments)
if cmdArguments[1] == nil then
function commandFinger(clientId, command, victim)
if victim == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dfinger usage: "..commands.getadmin("finger")["syntax"].."\";")

return true
elseif tonumber(cmdArguments[1]) == nil or tonumber(cmdArguments[1]) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
cmdClient = et.ClientNumberFromString(cmdArguments[1])
elseif tonumber(victim) == nil or tonumber(victim) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
cmdClient = et.ClientNumberFromString(victim)
else
cmdClient = tonumber(cmdArguments[1])
cmdClient = tonumber(victim)
end

if cmdClient == -1 or cmdClient == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dfinger: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dfinger: ^9no or multiple matches for '^7"..victim.."^9'.\";")

return true
elseif not et.gentity_get(cmdClient, "pers.netname") then
Expand Down
12 changes: 6 additions & 6 deletions luamods/wolfadmin/commands/admin/gib.lua
Expand Up @@ -23,19 +23,19 @@ local players = require (wolfa_getLuaPath()..".players.players")

local settings = require (wolfa_getLuaPath()..".util.settings")

function commandGib(clientId, cmdArguments)
if cmdArguments[1] == nil then
function commandGib(clientId, command, victim)
if victim == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dgib usage: "..commands.getadmin("gib")["syntax"].."\";")

return true
elseif tonumber(cmdArguments[1]) == nil or tonumber(cmdArguments[1]) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
cmdClient = et.ClientNumberFromString(cmdArguments[1])
elseif tonumber(victim) == nil or tonumber(victim) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
cmdClient = et.ClientNumberFromString(victim)
else
cmdClient = tonumber(cmdArguments[1])
cmdClient = tonumber(victim)
end

if cmdClient == -1 or cmdClient == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dgib: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dgib: ^9no or multiple matches for '^7"..victim.."^9'.\";")

return true
elseif not et.gentity_get(cmdClient, "pers.netname") then
Expand Down
2 changes: 1 addition & 1 deletion luamods/wolfadmin/commands/admin/greeting.lua
Expand Up @@ -21,7 +21,7 @@ local commands = require (wolfa_getLuaPath()..".commands.commands")
local settings = require (wolfa_getLuaPath()..".util.settings")
local greetings = require (wolfa_getLuaPath()..".players.greetings")

function commandGreeting(clientId, cmdArguments)
function commandGreeting(clientId, command)
local greeting = greetings.get(clientId)

if greeting then
Expand Down
18 changes: 9 additions & 9 deletions luamods/wolfadmin/commands/admin/help.lua
Expand Up @@ -19,10 +19,10 @@ local auth = require (wolfa_getLuaPath()..".auth.auth")
local commands = require (wolfa_getLuaPath()..".commands.commands")
local settings = require (wolfa_getLuaPath()..".util.settings")

function commandHelp(clientId, cmdArguments)
function commandHelp(clientId, command, cmd)
local cmds = commands.getadmin()

if #cmdArguments == 0 then
if not cmd then
local availableCommands = {}

for command, data in pairs(cmds) do
Expand Down Expand Up @@ -53,14 +53,14 @@ function commandHelp(clientId, cmdArguments)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9Type ^2!help ^d[command] ^9for help with a specific command.\";")

return false
elseif #cmdArguments > 0 then
local helpCmd = string.lower(cmdArguments[1])
else
cmd = string.lower(cmd)

if cmds[helpCmd] ~= nil and (not cmds[helpCmd]["hidden"] or (type(cmds[helpCmd]["hidden"]) == "function" and not cmds[helpCmd]["hidden"]())) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dhelp: ^9help for '^2"..helpCmd.."^9':\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dfunction: ^9"..cmds[helpCmd]["help"].."\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsyntax: ^9"..cmds[helpCmd]["syntax"].."\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dflag: ^9'^2"..cmds[helpCmd]["flag"].."^9'\";")
if cmds[cmd] ~= nil and (not cmds[cmd]["hidden"] or (type(cmds[cmd]["hidden"]) == "function" and not cmds[cmd]["hidden"]())) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dhelp: ^9help for '^2".. cmd .."^9':\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dfunction: ^9"..cmds[cmd]["help"].."\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsyntax: ^9"..cmds[cmd]["syntax"].."\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dflag: ^9'^2"..cmds[cmd]["flag"].."^9'\";")

return true
end
Expand Down
2 changes: 1 addition & 1 deletion luamods/wolfadmin/commands/admin/incognito.lua
Expand Up @@ -21,7 +21,7 @@ local commands = require (wolfa_getLuaPath()..".commands.commands")

local players = require (wolfa_getLuaPath()..".players.players")

function commandIncognito(clientId, cmdArguments)
function commandIncognito(clientId, command)
local fileName = et.trap_Cvar_Get("g_shrubbot")
local functionStart = et.trap_Milliseconds()
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_READ)
Expand Down
14 changes: 7 additions & 7 deletions luamods/wolfadmin/commands/admin/kick.lua
Expand Up @@ -24,19 +24,19 @@ local commands = require (wolfa_getLuaPath()..".commands.commands")

local settings = require (wolfa_getLuaPath()..".util.settings")

function commandKick(clientId, cmdArguments)
if cmdArguments[1] == nil then
function commandKick(clientId, command, victim, ...)
if victim == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dkick usage: "..commands.getadmin("kick")["syntax"].."\";")

return true
elseif tonumber(cmdArguments[1]) == nil or tonumber(cmdArguments[1]) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
cmdClient = et.ClientNumberFromString(cmdArguments[1])
elseif tonumber(victim) == nil or tonumber(victim) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
cmdClient = et.ClientNumberFromString(victim)
else
cmdClient = tonumber(cmdArguments[1])
cmdClient = tonumber(victim)
end

if cmdClient == -1 or cmdClient == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dkick: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dkick: ^9no or multiple matches for '^7"..victim.."^9'.\";")

return true
elseif not et.gentity_get(cmdClient, "pers.netname") then
Expand All @@ -55,7 +55,7 @@ function commandKick(clientId, cmdArguments)
return true
end

local reason = table.concat(cmdArguments, " ", 2)
local reason = table.concat({...}, " ")

admin.kickPlayer(cmdClient, clientId, reason)
history.add(cmdClient, clientId, "kick", reason)
Expand Down
2 changes: 1 addition & 1 deletion luamods/wolfadmin/commands/admin/kickbots.lua
Expand Up @@ -19,7 +19,7 @@ local auth = require (wolfa_getLuaPath()..".auth.auth")
local commands = require (wolfa_getLuaPath()..".commands.commands")
local bots = require (wolfa_getLuaPath()..".game.bots")

function commandBotsOff(clientId, cmdArguments)
function commandBotsOff(clientId, command)
bots.enable(false)

et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dkickbots: ^9bots were toggled off.\";")
Expand Down
14 changes: 7 additions & 7 deletions luamods/wolfadmin/commands/admin/listaliases.lua
Expand Up @@ -27,23 +27,23 @@ local pagination = require (wolfa_getLuaPath()..".util.pagination")
local settings = require (wolfa_getLuaPath()..".util.settings")
local util = require (wolfa_getLuaPath()..".util.util")

function commandListAliases(clientId, cmdArguments)
function commandListAliases(clientId, command, victim, offset)
if not db.isconnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistaliases: ^9alias history is disabled.\";")

return true
elseif cmdArguments[1] == nil then
elseif victim == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistaliases usage: "..commands.getadmin("listaliases")["syntax"].."\";")

return true
elseif tonumber(cmdArguments[1]) == nil or tonumber(cmdArguments[1]) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
cmdClient = et.ClientNumberFromString(cmdArguments[1])
elseif tonumber(victim) == nil or tonumber(victim) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
cmdClient = et.ClientNumberFromString(victim)
else
cmdClient = tonumber(cmdArguments[1])
cmdClient = tonumber(victim)
end

if cmdClient == -1 or cmdClient == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistaliases: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistaliases: ^9no or multiple matches for '^7"..victim.."^9'.\";")

return true
elseif not et.gentity_get(cmdClient, "pers.netname") then
Expand All @@ -65,7 +65,7 @@ function commandListAliases(clientId, cmdArguments)
local player = db.getplayer(players.getGUID(cmdClient))["id"]

local count = db.getaliasescount(player)
local limit, offset = pagination.calculate(count, 30, tonumber(cmdArguments[2]))
local limit, offset = pagination.calculate(count, 30, tonumber(offset))
local aliases = db.getaliases(player, limit, offset)

et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dAliases for ^7"..et.gentity_get(cmdClient, "pers.netname").."^d:\";")
Expand Down
14 changes: 7 additions & 7 deletions luamods/wolfadmin/commands/admin/listlevels.lua
Expand Up @@ -27,8 +27,8 @@ local pagination = require (wolfa_getLuaPath()..".util.pagination")
local settings = require (wolfa_getLuaPath()..".util.settings")
local util = require (wolfa_getLuaPath()..".util.util")

function commandListLevels(clientId, cmdArguments)
if cmdArguments[1] == nil then
function commandListLevels(clientId, command, victim, offset)
if victim == nil then
if settings.get("g_standalone") ~= 0 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels usage: "..commands.getadmin("listlevels")["syntax"].."\";")

Expand Down Expand Up @@ -68,14 +68,14 @@ function commandListLevels(clientId, cmdArguments)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels: ^9level history is disabled.\";")

return true
elseif tonumber(cmdArguments[1]) == nil or tonumber(cmdArguments[1]) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
cmdClient = et.ClientNumberFromString(cmdArguments[1])
elseif tonumber(victim) == nil or tonumber(victim) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
cmdClient = et.ClientNumberFromString(victim)
else
cmdClient = tonumber(cmdArguments[1])
cmdClient = tonumber(victim)
end

if cmdClient == -1 or cmdClient == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels: ^9no or multiple matches for '^7"..victim.."^9'.\";")

return true
elseif not et.gentity_get(cmdClient, "pers.netname") then
Expand All @@ -87,7 +87,7 @@ function commandListLevels(clientId, cmdArguments)
local player = db.getplayer(players.getGUID(cmdClient))["id"]

local count = db.getlevelscount(player)
local limit, offset = pagination.calculate(count, 30, tonumber(cmdArguments[2]))
local limit, offset = pagination.calculate(count, 30, tonumber(offset))
local levels = db.getlevels(player, limit, offset)

if not (levels and #levels > 0) then
Expand Down
2 changes: 1 addition & 1 deletion luamods/wolfadmin/commands/admin/listmaps.lua
Expand Up @@ -20,7 +20,7 @@ local util = require (wolfa_getLuaPath()..".util.util")
local commands = require (wolfa_getLuaPath()..".commands.commands")
local game = require (wolfa_getLuaPath()..".game.game")

function commandListMaps(clientId, cmdArguments)
function commandListMaps(clientId, command)
local output = ""

local maps = game.getMaps()
Expand Down
2 changes: 1 addition & 1 deletion luamods/wolfadmin/commands/admin/listplayers.lua
Expand Up @@ -28,7 +28,7 @@ local constants = require (wolfa_getLuaPath()..".util.constants")
local settings = require (wolfa_getLuaPath()..".util.settings")
local util = require (wolfa_getLuaPath()..".util.util")

function commandListPlayers(clientId, cmdArguments)
function commandListPlayers(clientId, command)
local playersOnline = {}

for playerId = 0, et.trap_Cvar_Get("sv_maxclients") - 1 do
Expand Down
16 changes: 8 additions & 8 deletions luamods/wolfadmin/commands/admin/lock.lua
Expand Up @@ -25,33 +25,33 @@ local util = require (wolfa_getLuaPath()..".util.util")
local constants = require (wolfa_getLuaPath()..".util.constants")
local settings = require (wolfa_getLuaPath()..".util.settings")

function commandLock(clientId, cmdArguments)
if cmdArguments[1] == nil or (cmdArguments[1] ~= constants.TEAM_AXIS_SC and cmdArguments[1] ~= constants.TEAM_ALLIES_SC and cmdArguments[1] ~= constants.TEAM_SPECTATORS_SC and cmdArguments[1] ~= "all") then
function commandLock(clientId, command, team)
if team == nil or (team ~= constants.TEAM_AXIS_SC and team ~= constants.TEAM_ALLIES_SC and team ~= constants.TEAM_SPECTATORS_SC and team ~= "all") then
return false
end

if cmdArguments[1] == "all" then
if team == "all" then
teams.lock(constants.TEAM_AXIS)
teams.lock(constants.TEAM_ALLIES)
teams.lock(constants.TEAM_SPECTATORS)

return false
end

teams.lock(util.getTeamFromCode(cmdArguments[1]))
teams.lock(util.getTeamFromCode(team))

return false
end
commands.addadmin("lock", commandLock, auth.PERM_LOCKTEAM, "lock one or all of the teams from players joining", "^9[^3r|b|s|all#^9]", true, (settings.get("g_standalone") == 1))

function commandLock(clientId, cmdArguments)
if cmdArguments[1] == nil or (cmdArguments[1] ~= constants.TEAM_AXIS_SC and cmdArguments[1] ~= constants.TEAM_ALLIES_SC and cmdArguments[1] ~= constants.TEAM_SPECTATORS_SC and cmdArguments[1] ~= "all") then
function commandLock(clientId, command, team)
if team == nil or (team ~= constants.TEAM_AXIS_SC and team ~= constants.TEAM_ALLIES_SC and team ~= constants.TEAM_SPECTATORS_SC and team ~= "all") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlock usage: "..commands.getadmin("lock")["syntax"].."\";")

return true
end

if cmdArguments[1] == "all" then
if team == "all" then
teams.lock(constants.TEAM_AXIS)
teams.lock(constants.TEAM_ALLIES)
teams.lock(constants.TEAM_SPECTATORS)
Expand All @@ -61,7 +61,7 @@ function commandLock(clientId, cmdArguments)
return false
end

local team = util.getTeamFromCode(cmdArguments[1])
local team = util.getTeamFromCode(team)
teams.lock(team)

et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dlock: "..util.getTeamColor(team)..util.getTeamName(team).." ^9team has been locked.\";")
Expand Down

0 comments on commit ad7b7c6

Please sign in to comment.