Skip to content

Commit

Permalink
Fixed many unused initializations (fixes #75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo Smit committed Feb 21, 2017
1 parent 3ed215e commit 6c95703
Show file tree
Hide file tree
Showing 31 changed files with 40 additions and 62 deletions.
15 changes: 7 additions & 8 deletions luamods/wolfadmin/admin/balancer.lua
Expand Up @@ -15,17 +15,15 @@
-- 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 teams = require (wolfa_getLuaPath()..".game.teams")

local constants = require (wolfa_getLuaPath()..".util.constants")
local util = require (wolfa_getLuaPath()..".util.util")
local bits = require (wolfa_getLuaPath()..".util.bits")
local tables = require (wolfa_getLuaPath()..".util.tables")
local events = require (wolfa_getLuaPath()..".util.events")
local timers = require (wolfa_getLuaPath()..".util.timers")
local settings = require (wolfa_getLuaPath()..".util.settings")

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

local teams = require (wolfa_getLuaPath()..".game.teams")
local tables = require (wolfa_getLuaPath()..".util.tables")
local timers = require (wolfa_getLuaPath()..".util.timers")
local util = require (wolfa_getLuaPath()..".util.util")

local balancer = {}

Expand All @@ -40,7 +38,6 @@ local lastJoined = {[constants.TEAM_AXIS] = {}, [constants.TEAM_ALLIES] = {}, [c
local evenerCount = 0

function balancer.balance(byAdmin, forceBalance)
local teamsData = teams.get()
local teamsDifference = teams.difference()

if teamsDifference == 0 then
Expand Down Expand Up @@ -78,6 +75,8 @@ function balancer.balance(byAdmin, forceBalance)
evenerCount = evenerCount + 1

if forceBalance or evenerCount >= 3 then
local teamsData = teams.get()

for i = 1, math.floor(teamsDifference / 2) do
local player = balancer.findPlayer(teamsData[teamGreater], teamGreater, teamSmaller)

Expand Down
3 changes: 0 additions & 3 deletions luamods/wolfadmin/admin/bans.lua
Expand Up @@ -19,9 +19,6 @@ local db = require (wolfa_getLuaPath()..".db.db")

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

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

local bans = {}

function bans.get(banId)
Expand Down
3 changes: 0 additions & 3 deletions luamods/wolfadmin/admin/history.lua
Expand Up @@ -19,9 +19,6 @@ local db = require (wolfa_getLuaPath()..".db.db")

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

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

local history = {}

function history.get(clientId, historyId)
Expand Down
2 changes: 1 addition & 1 deletion luamods/wolfadmin/admin/rules.lua
Expand Up @@ -42,7 +42,7 @@ function rules.load()

if amount == 0 then return 0 end

for id, rule in ipairs(array["rule"]) do
for _, rule in ipairs(array["rule"]) do
data[rule["shortcut"]] = rule["rule"]
end

Expand Down
1 change: 0 additions & 1 deletion luamods/wolfadmin/auth/auth.lua
Expand Up @@ -16,7 +16,6 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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

local auth = {}
Expand Down
3 changes: 0 additions & 3 deletions luamods/wolfadmin/auth/shrubbot.lua
Expand Up @@ -15,9 +15,6 @@
-- 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 events = require (wolfa_getLuaPath()..".util.events")
local files = require (wolfa_getLuaPath()..".util.files")

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

local shrubbot = {}
Expand Down
4 changes: 3 additions & 1 deletion luamods/wolfadmin/commands/admin/ban.lua
Expand Up @@ -47,14 +47,16 @@ function commandBan(clientId, command, victim, ...)
end

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

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])
reason = "banned by admin"
elseif args[1] then
duration = 600
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, command, ...)
function commandEnableVote(clientId, command)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^denablevote: ^9next map voting has been enabled.\";")

voting.force("nextmap")
Expand Down
1 change: 0 additions & 1 deletion luamods/wolfadmin/commands/admin/finger.lua
Expand Up @@ -22,7 +22,6 @@ local commands = require (wolfa_getLuaPath()..".commands.commands")
local players = require (wolfa_getLuaPath()..".players.players")

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

function commandFinger(clientId, command, victim)
if victim == nil then
Expand Down
4 changes: 2 additions & 2 deletions luamods/wolfadmin/commands/admin/greeting.lua
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 util = require (wolfa_getLuaPath()..".util.util")
local auth = require (wolfa_getLuaPath()..".auth.auth")

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

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

function commandGreeting(clientId, command)
Expand Down
5 changes: 2 additions & 3 deletions luamods/wolfadmin/commands/admin/incognito.lua
Expand Up @@ -23,7 +23,6 @@ local players = require (wolfa_getLuaPath()..".players.players")

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)

if fileLength == -1 then
Expand All @@ -36,7 +35,7 @@ function commandIncognito(clientId, command)

et.trap_FS_FCloseFile(fileDescriptor)

for entry, adminName, adminGUID, adminLevel, adminFlags in string.gmatch(fileString, "(%[admin%]\nname%s+=%s+([%a%d%p]+)\nguid%s+=%s+([%u%d]+)\nlevel%s+=%s+([%d]+)\nflags%s+=%s+([%a%d%p]*)\n\n)") do
for _, adminName, adminGUID, adminLevel, adminFlags in string.gmatch(fileString, "(%[admin%]\nname%s+=%s+([%a%d%p]+)\nguid%s+=%s+([%u%d]+)\nlevel%s+=%s+([%d]+)\nflags%s+=%s+([%a%d%p]*)\n\n)") do
-- et.G_Print(string.format("%s %s %d %s\n", adminName, adminGUID, adminLevel, adminFlags))

if players.getGUID(clientId) == adminGUID then
Expand All @@ -63,7 +62,7 @@ function commandIncognito(clientId, command)
end
end

local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_WRITE)
local fileDescriptor, _ = et.trap_FS_FOpenFile(fileName, et.FS_WRITE)

local writeCount = et.trap_FS_Write(fileString, string.len(fileString), fileDescriptor)

Expand Down
1 change: 0 additions & 1 deletion luamods/wolfadmin/commands/admin/listaliases.lua
Expand Up @@ -24,7 +24,6 @@ local commands = require (wolfa_getLuaPath()..".commands.commands")
local players = require (wolfa_getLuaPath()..".players.players")

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

function commandListAliases(clientId, command, victim, offset)
Expand Down
5 changes: 2 additions & 3 deletions luamods/wolfadmin/commands/admin/listlevels.lua
Expand Up @@ -35,7 +35,6 @@ function commandListLevels(clientId, command, victim, offset)
return true
else
local fileName = et.trap_Cvar_Get("g_shrubbot")
local functionStart = et.trap_Milliseconds()
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_READ)
local levelsCount = 0

Expand All @@ -49,7 +48,7 @@ function commandListLevels(clientId, command, victim, offset)

et.trap_FS_FCloseFile(fileDescriptor)

for entry, levelNr, levelName, levelFlags in string.gmatch(fileString, "(%[level%]\nlevel%s+=%s+(-?[0-9]+)\nname%s+=%s+([%a%d%p ]+)\nflags%s+=%s+([%a%d%p]*)\n\n)") do
for _, levelNr, levelName, levelFlags in string.gmatch(fileString, "(%[level%]\nlevel%s+=%s+(-?[0-9]+)\nname%s+=%s+([%a%d%p ]+)\nflags%s+=%s+([%a%d%p]*)\n\n)") do
-- et.G_Print(string.format("%d %s %s\n", levelNr, levelName, levelFlags))

local numberOfSpaces = 24 - string.len(util.removeColors(levelName))
Expand Down Expand Up @@ -94,7 +93,7 @@ function commandListLevels(clientId, command, victim, offset)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels: ^9there are no recorded levels for player ^7"..et.gentity_get(cmdClient, "pers.netname").."^9.\";")
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dLevels for ^7"..et.gentity_get(cmdClient, "pers.netname").."^d:\";")
for id, level in pairs(levels) do
for _, level in pairs(levels) do
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^f"..string.format("%4s", level["id"]).." ^7"..string.format("%-20s", util.removeColors(db.getlastalias(level["invoker_id"])["alias"])).." ^f"..os.date("%d/%m/%Y", level["datetime"]).." ^7"..level["level_id"].."\";")
end

Expand Down
3 changes: 2 additions & 1 deletion luamods/wolfadmin/commands/admin/listmaps.lua
Expand Up @@ -16,8 +16,9 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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

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

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

function commandListMaps(clientId, command)
Expand Down
2 changes: 0 additions & 2 deletions luamods/wolfadmin/commands/admin/listplayers.lua
Expand Up @@ -19,12 +19,10 @@ local auth = require (wolfa_getLuaPath()..".auth.auth")

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

local game = require (wolfa_getLuaPath()..".game.game")
local fireteams = require (wolfa_getLuaPath()..".game.fireteams")

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

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

Expand Down
5 changes: 3 additions & 2 deletions luamods/wolfadmin/commands/admin/mute.lua
Expand Up @@ -17,7 +17,6 @@

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

local admin = require (wolfa_getLuaPath()..".admin.admin")
local history = require (wolfa_getLuaPath()..".admin.history")
local mutes = require (wolfa_getLuaPath()..".admin.mutes")

Expand Down Expand Up @@ -50,14 +49,16 @@ function commandMute(clientId, command, victim, ...)
end

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

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])
reason = "muted by admin"
elseif args[1] then
duration = 600
reason = table.concat(args, " ")
elseif not auth.isPlayerAllowed(clientId, "8") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute usage: "..commands.getadmin("mute")["syntax"].."\";")
Expand Down
3 changes: 2 additions & 1 deletion luamods/wolfadmin/commands/admin/pause.lua
Expand Up @@ -16,8 +16,9 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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

local commands = require (wolfa_getLuaPath()..".commands.commands")
local game = require (wolfa_getLuaPath()..".game.game")

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

function commandPause(clientId, command)
Expand Down
2 changes: 0 additions & 2 deletions luamods/wolfadmin/commands/admin/plock.lua
Expand Up @@ -21,8 +21,6 @@ local commands = require (wolfa_getLuaPath()..".commands.commands")

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

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

function commandPlayerLock(clientId, command, victim)
if victim == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock usage: "..commands.getadmin("plock")["syntax"].."\";")
Expand Down
2 changes: 0 additions & 2 deletions luamods/wolfadmin/commands/admin/punlock.lua
Expand Up @@ -21,8 +21,6 @@ local commands = require (wolfa_getLuaPath()..".commands.commands")

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

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

function commandPlayerUnlock(clientId, command, victim)
if victim == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dpunlock usage: "..commands.getadmin("punlock")["syntax"].."\";")
Expand Down
3 changes: 2 additions & 1 deletion luamods/wolfadmin/commands/admin/unpause.lua
Expand Up @@ -16,8 +16,9 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

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

local commands = require (wolfa_getLuaPath()..".commands.commands")
local game = require (wolfa_getLuaPath()..".game.game")

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

function commandUnpause(clientId, command)
Expand Down
4 changes: 3 additions & 1 deletion luamods/wolfadmin/commands/admin/vmute.lua
Expand Up @@ -48,14 +48,16 @@ function commandVoiceMute(clientId, command, victim, ...)
end

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

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])
reason = "muted by admin"
elseif args[1] then
duration = 600
reason = table.concat(args, " ")
elseif not auth.isPlayerAllowed(clientId, "8") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute usage: "..commands.getadmin("vmute")["syntax"].."\";")
Expand Down
2 changes: 1 addition & 1 deletion luamods/wolfadmin/commands/server/acl.lua
Expand Up @@ -21,7 +21,7 @@ local commands = require (wolfa_getLuaPath()..".commands.commands")

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

function commandAclListLevels(...)
function commandAclListLevels()
for _, level in ipairs(acl.getLevels()) do
et.G_Print(string.format("%5d %30s %6d players", level["id"], level["name"], level["players"]).."\n")
end
Expand Down
1 change: 0 additions & 1 deletion luamods/wolfadmin/db/db.lua
Expand Up @@ -15,7 +15,6 @@
-- 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 util = require (wolfa_getLuaPath()..".util.util")
local events = require (wolfa_getLuaPath()..".util.events")
local settings = require (wolfa_getLuaPath()..".util.settings")

Expand Down
1 change: 0 additions & 1 deletion luamods/wolfadmin/db/mysql.lua
Expand Up @@ -17,7 +17,6 @@

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

local constants = require (wolfa_getLuaPath()..".util.constants")
local util = require (wolfa_getLuaPath()..".util.util")
local settings = require (wolfa_getLuaPath()..".util.settings")
local tables = require (wolfa_getLuaPath()..".util.tables")
Expand Down
4 changes: 0 additions & 4 deletions luamods/wolfadmin/game/fireteams.lua
Expand Up @@ -15,11 +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 teams = require (wolfa_getLuaPath()..".game.teams")

local bits = require (wolfa_getLuaPath()..".util.bits")
local constants = require (wolfa_getLuaPath()..".util.constants")
local events = require (wolfa_getLuaPath()..".util.events")

local fireteams = {}

Expand Down
2 changes: 0 additions & 2 deletions luamods/wolfadmin/util/debug.lua
Expand Up @@ -15,8 +15,6 @@
-- 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 constants = require (wolfa_getLuaPath()..".util.constants")
local util = require (wolfa_getLuaPath()..".util.util")
local settings = require (wolfa_getLuaPath()..".util.settings")

local SEVERITY_LEVELS = {
Expand Down
9 changes: 5 additions & 4 deletions luamods/wolfadmin/util/files.lua
Expand Up @@ -73,7 +73,7 @@ function files.loadFromCFG(fileName, idExpr)
end

function files.saveToCFG(fileName, array)
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_WRITE)
local fileDescriptor, _ = et.trap_FS_FOpenFile(fileName, et.FS_WRITE)
local arrayCount = 0

for id, subdata in pairs(array) do
Expand All @@ -82,11 +82,12 @@ function files.saveToCFG(fileName, array)
et.trap_FS_Write(blockId, string.len(blockId), fileDescriptor)

local maxKeyLength = 0
for k, v in pairs(data) do

for k, _ in pairs(data) do
maxKeyLength = math.max(maxKeyLength, string.len(k))
end


local dataLine
for k, v in pairs(data) do
dataLine = string.format("%-"..maxKeyLength.."s = %s\n", k, v)
et.trap_FS_Write(dataLine, string.len(dataLine), fileDescriptor)
Expand Down
4 changes: 2 additions & 2 deletions luamods/wolfadmin/util/logs.lua
Expand Up @@ -26,7 +26,7 @@ function logs.writeChat(clientId, type, ...)
return
end

local fileDescriptor, fileLength = et.trap_FS_FOpenFile(settings.get("g_logChat"), et.FS_APPEND)
local fileDescriptor, _ = et.trap_FS_FOpenFile(settings.get("g_logChat"), et.FS_APPEND)

local logLine

Expand All @@ -52,7 +52,7 @@ function logs.writeAdmin(clientId, command, victimId, ...)
return
end

local fileDescriptor, fileLength = et.trap_FS_FOpenFile(settings.get("g_logAdmin"), et.FS_APPEND)
local fileDescriptor, _ = et.trap_FS_FOpenFile(settings.get("g_logAdmin"), et.FS_APPEND)

local logLine

Expand Down

0 comments on commit 6c95703

Please sign in to comment.