Skip to content

Commit

Permalink
Replaced output commands with calls to output module
Browse files Browse the repository at this point in the history
  • Loading branch information
timosmit committed May 12, 2020
1 parent 0e21cbb commit f612180
Show file tree
Hide file tree
Showing 73 changed files with 492 additions and 445 deletions.
6 changes: 4 additions & 2 deletions luascripts/wolfadmin/admin/admin.lua
Expand Up @@ -17,6 +17,8 @@

local db = wolfa_requireModule("db.db")
local config = wolfa_requireModule("config.config")
local output = wolfa_requireModule("game.output")
local server = wolfa_requireModule("game.server")
local players = wolfa_requireModule("players.players")
local constants = wolfa_requireModule("util.constants")
local events = wolfa_requireModule("util.events")
Expand Down Expand Up @@ -68,7 +70,7 @@ function admin.slapPlayer(clientId, damage)

et.gentity_set(clientId, "health", newHealth)

et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound "..clientId.." \"sound/player/land_hurt.wav\";")
server.exec(string.format("playsound %d \"sound/player/land_hurt.wav\";", clientId))
end

function admin.killPlayer(clientId)
Expand Down Expand Up @@ -205,7 +207,7 @@ function admin.onClientNameChange(clientId, oldName, newName)
-- on some mods, this message is already printed
-- known: old NQ versions, Legacy
if et.trap_Cvar_Get("fs_game") ~= "legacy" then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay -1 \""..oldName.." ^7is now known as "..newName.."\";")
output.clientConsole(oldName.." ^7is now known as "..newName)
end

-- update database
Expand Down
18 changes: 10 additions & 8 deletions luascripts/wolfadmin/admin/balancer.lua
Expand Up @@ -15,8 +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 teams = wolfa_requireModule("game.teams")
local config = wolfa_requireModule("config.config")
local teams = wolfa_requireModule("game.teams")
local output = wolfa_requireModule("game.output")
local server = wolfa_requireModule("game.server")
local constants = wolfa_requireModule("util.constants")
local bits = wolfa_requireModule("util.bits")
local events = wolfa_requireModule("util.events")
Expand All @@ -43,7 +45,7 @@ function balancer.balance(byAdmin, forceBalance)
evenerCount = 0

if byAdmin then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dbalancer: ^9teams are even.\";")
output.clientChat("^dbalancer: ^9teams are even.")
end

return
Expand All @@ -63,12 +65,12 @@ function balancer.balance(byAdmin, forceBalance)
evenerCount = evenerCount + 1

if forceBalance or evenerCount >= 2 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "!shuffle;")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cpm \"^dbalancer: ^7THE TEAMS HAVE BEEN ^qSHUFFLED^7!\";")
server.exec("!shuffle;")
output.clientPopup("^dbalancer: ^7THE TEAMS HAVE BEEN ^1SHUFFLED^7!")

evenerCount = 0
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cpm \"^dbalancer: ^1EVEN THE TEAMS ^7OR ^1SHUFFLE\";")
output.clientPopup("^dbalancer: ^1EVEN THE TEAMS ^7OR ^1SHUFFLE")
end
elseif teamsDifference >= config.get("g_evenerMinDifference") then
evenerCount = evenerCount + 1
Expand All @@ -79,8 +81,8 @@ function balancer.balance(byAdmin, forceBalance)
for i = 1, math.floor(teamsDifference / 2) do
local player = balancer.findPlayer(teamsData[teamGreater], teamGreater, teamSmaller)

et.trap_SendConsoleCommand(et.EXEC_APPEND, "!put "..player.." "..(teamGreater == constants.TEAM_AXIS and constants.TEAM_ALLIES_SC or constants.TEAM_AXIS_SC)..";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dbalancer: ^9thank you, ^7"..et.gentity_get(player, "pers.netname").."^9, for helping to even the teams.\";")
server.exec("!put "..player.." "..(teamGreater == constants.TEAM_AXIS and constants.TEAM_ALLIES_SC or constants.TEAM_AXIS_SC)..";")
output.clientChat("^dbalancer: ^9thank you, ^7"..et.gentity_get(player, "pers.netname").."^9, for helping to even the teams.")

teamsData = teams.get()
end
Expand All @@ -90,7 +92,7 @@ function balancer.balance(byAdmin, forceBalance)
local teamGreaterName, teamSmallerName = util.getTeamName(teamGreater), util.getTeamName(teamSmaller)
local teamGreaterColor, teamSmallerColor = util.getTeamColor(teamGreater), util.getTeamColor(teamSmaller)

et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dbalancer: ^9teams seem unfair, would someone from "..teamGreaterColor..teamGreaterName.." ^9please switch to "..teamSmallerColor..teamSmallerName.."^9?\";")
output.clientChat("^dbalancer: ^9teams seem unfair, would someone from "..teamGreaterColor..teamGreaterName.." ^9please switch to "..teamSmallerColor..teamSmallerName.."^9?")
end
end
end
Expand Down
11 changes: 6 additions & 5 deletions luascripts/wolfadmin/admin/banners.lua
Expand Up @@ -16,11 +16,11 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local config = wolfa_requireModule("config.config")
local output = wolfa_requireModule("game.output")
local bits = wolfa_requireModule("util.bits")
local events = wolfa_requireModule("util.events")
local timers = wolfa_requireModule("util.timers")
local constants = wolfa_requireModule("util.constants")
local util = wolfa_requireModule("util.util")

local toml = wolfa_requireLib("toml")

Expand All @@ -36,10 +36,11 @@ local welcomeBanners = {}
local infoBanners = {}

function banners.print(clientId, banner)
local prefix = (config.get("g_bannerArea") ~= constants.AREA_CHAT) and "^7" or "^dbanner: ^9"
local target = clientId and clientId or -1
et.trap_SendConsoleCommand(et.EXEC_APPEND,
string.format("%s %i \"%s%s\";", util.getCommandForArea(config.get("g_bannerArea")), target, prefix, banner["text"]))
local area = config.get("g_bannerArea")
local prefix = area == constants.AREA_CHAT and "^dbanner: ^9" or "^7"
local text = prefix..banner["text"]

output.client(area, text, clientId)
end

function banners.nextBanner(random)
Expand Down
11 changes: 6 additions & 5 deletions luascripts/wolfadmin/admin/censor.lua
Expand Up @@ -20,6 +20,7 @@ local mutes = wolfa_requireModule("admin.mutes")
local history = wolfa_requireModule("admin.history")
local auth = wolfa_requireModule("auth.auth")
local config = wolfa_requireModule("config.config")
local output = wolfa_requireModule("game.output")
local players = wolfa_requireModule("players.players")
local events = wolfa_requireModule("util.events")
local toml = wolfa_requireLib("toml")
Expand Down Expand Up @@ -59,25 +60,25 @@ function censor.punishClient(clientId)
if config.get("g_censorBurn") ~= 0 then
admin.burnPlayer(clientId)

et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dburn: ^7"..players.getName(clientId).." ^9burnt his tongue.\";")
output.clientChat("^dburn: ^7"..players.getName(clientId).." ^9burnt his tongue.")
end

if config.get("g_censorSlap") ~= 0 then
admin.slapPlayer(clientId, 20)

et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dslap: ^7"..players.getName(clientId).." ^9was slapped for his foul language.\";")
output.clientChat("^dslap: ^7"..players.getName(clientId).." ^9was slapped for his foul language.")
end

if config.get("g_censorKill") ~= 0 and config.get("g_censorGib") == 0 then
admin.killPlayer(clientId)

et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dkill: ^7"..players.getName(clientId).." ^9stumbled over his words.\";")
output.clientChat("^dkill: ^7"..players.getName(clientId).." ^9stumbled over his words.")
end

if config.get("g_censorGib") ~= 0 then
admin.gibPlayer(clientId)

et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dgib: ^7"..players.getName(clientId).." ^9should not have said that.\";")
output.clientChat("^dgib: ^7"..players.getName(clientId).." ^9should not have said that.")
end

if config.get("g_censorMute") > 0 then
Expand All @@ -87,7 +88,7 @@ function censor.punishClient(clientId)
history.add(clientId, -1337, "mute", "censor")
end

et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dmute: ^7"..players.getName(clientId).." ^9has been muted for "..config.get("g_censorMute").." seconds\";")
output.clientChat("^dmute: ^7"..players.getName(clientId).." ^9has been muted for "..config.get("g_censorMute").." seconds")
end
end

Expand Down
7 changes: 3 additions & 4 deletions luascripts/wolfadmin/admin/mutes.lua
Expand Up @@ -16,9 +16,8 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local db = wolfa_requireModule("db.db")

local output = wolfa_requireModule("game.output")
local players = wolfa_requireModule("players.players")

local events = wolfa_requireModule("util.events")
local timers = wolfa_requireModule("util.timers")

Expand All @@ -43,7 +42,7 @@ function mutes.add(victimId, invokerId, type, duration, reason)
local victimPlayerId = db.getPlayer(players.getGUID(victimId))["id"]
local invokerPlayerId = db.getPlayer(players.getGUID(invokerId))["id"]

local reason = reason and reason or "muted by admin"
reason = reason and reason or "muted by admin"

players.setMuted(victimId, true, type, os.time(), os.time() + duration)
db.addMute(victimPlayerId, invokerPlayerId, type, os.time(), duration, reason)
Expand Down Expand Up @@ -74,7 +73,7 @@ function mutes.checkLiveMutes()
if players.isMuted(clientId) and players.getMuteExpiresAt(clientId) < os.time() then
mutes.removeByClient(clientId)

et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dunmute: ^7"..et.gentity_get(clientId, "pers.netname").." ^9has been automatically unmuted\";")
output.clientChat("^dunmute: ^7"..et.gentity_get(clientId, "pers.netname").." ^9has been automatically unmuted.")
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion luascripts/wolfadmin/commands/admin/admintest.lua
Expand Up @@ -18,13 +18,14 @@
local auth = wolfa_requireModule("auth.auth")
local commands = wolfa_requireModule("commands.commands")
local config = wolfa_requireModule("config.config")
local output = wolfa_requireModule("game.output")
local players = wolfa_requireModule("players.players")

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

et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dadmintest: ^7"..players.getName(clientId).." ^9is a level "..level.." user (^7"..levelName.."^9).\";")
output.clientChat("^dadmintest: ^7"..players.getName(clientId).." ^9is a level "..level.." user (^7"..levelName.."^9).")

return true
end
Expand Down
11 changes: 6 additions & 5 deletions luascripts/wolfadmin/commands/admin/balance.lua
Expand Up @@ -17,6 +17,7 @@

local auth = wolfa_requireModule("auth.auth")
local balancer = wolfa_requireModule("admin.balancer")
local output = wolfa_requireModule("game.output")
local commands = wolfa_requireModule("commands.commands")
local config = wolfa_requireModule("config.config")

Expand All @@ -25,24 +26,24 @@ function commandBalance(clientId, command, action)
if not balancer.isRunning() then
balancer.enable()

et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dbalancer: ^9balancer enabled.\";")
output.clientChat("^dbalancer: ^9balancer enabled.")
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dbalancer: ^9balancer is already running.\";")
output.clientConsole("^dbalancer: ^9balancer is already running.", clientId)
end
elseif action == "disable" then
if balancer.isRunning() then
balancer.disable()

et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dbalancer: ^9balancer disabled.\";")
output.clientChat("^dbalancer: ^9balancer disabled.")
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dbalancer: ^9balancer was not running.\";")
output.clientConsole("^dbalancer: ^9balancer was not running.", clientId)
end
elseif action == "force" then
balancer.balance(true, true)
elseif not action then
balancer.balance(true, false)
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dbalance usage: "..commands.getadmin("balance")["syntax"].."\";")
output.clientConsole("^dbalance usage: "..commands.getadmin("balance")["syntax"], clientId)
end

return true
Expand Down
15 changes: 8 additions & 7 deletions luascripts/wolfadmin/commands/admin/ban.lua
Expand Up @@ -18,6 +18,7 @@
local auth = wolfa_requireModule("auth.auth")
local bans = wolfa_requireModule("admin.bans")
local history = wolfa_requireModule("admin.history")
local output = wolfa_requireModule("game.output")
local commands = wolfa_requireModule("commands.commands")
local config = wolfa_requireModule("config.config")
local util = wolfa_requireModule("util.util")
Expand All @@ -26,7 +27,7 @@ function commandBan(clientId, command, victim, ...)
local cmdClient

if victim == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban usage: "..commands.getadmin("ban")["syntax"].."\";")
output.clientConsole("^dban usage: "..commands.getadmin("ban")["syntax"], clientId)

return true
elseif tonumber(victim) == nil or tonumber(victim) < 0 or tonumber(victim) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
Expand All @@ -36,11 +37,11 @@ function commandBan(clientId, command, victim, ...)
end

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

return true
elseif not et.gentity_get(cmdClient, "pers.netname") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban: ^9no connected player by that name or slot #\";")
output.clientConsole("^dban: ^9no connected player by that name or slot #", clientId)

return true
end
Expand All @@ -60,17 +61,17 @@ function commandBan(clientId, command, victim, ...)
elseif auth.isPlayerAllowed(clientId, auth.PERM_PERMA) and auth.isPlayerAllowed(clientId, auth.PERM_NOREASON) then
reason = "banned by admin"
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban usage: "..commands.getadmin("ban")["syntax"].."\";")
output.clientConsole("^dban usage: "..commands.getadmin("ban")["syntax"], clientId)

return true
end

if auth.isPlayerAllowed(cmdClient, auth.PERM_IMMUNE) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";")
output.clientConsole("^dban: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.", clientId)

return true
elseif auth.getPlayerLevel(cmdClient) > auth.getPlayerLevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban: ^9sorry, but your intended victim has a higher admin level than you do.\";")
output.clientConsole("^dban: ^9sorry, but your intended victim has a higher admin level than you do.", clientId)

return true
end
Expand All @@ -85,7 +86,7 @@ function commandBan(clientId, command, victim, ...)
durationText = "for "..duration.." seconds"
end

et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dban: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been banned "..durationText.."\";")
output.clientChat("^dban: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been banned "..durationText)

bans.add(cmdClient, clientId, duration, reason)

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

local auth = wolfa_requireModule("auth.auth")

local commands = wolfa_requireModule("commands.commands")

local output = wolfa_requireModule("game.output")
local players = wolfa_requireModule("players.players")

function commandCoinToss(clientId, command)
Expand All @@ -37,7 +36,7 @@ function commandCoinToss(clientId, command)
result = "the coin got lost."
end

et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dcointoss: ^7"..players.getName(clientId).." ^9tossed a coin..."..result.."\";")
output.clientChat("^dcointoss: ^7"..players.getName(clientId).." ^9tossed a coin... "..result)

return true
end
Expand Down
3 changes: 2 additions & 1 deletion luascripts/wolfadmin/commands/admin/enablevote.lua
Expand Up @@ -17,10 +17,11 @@

local commands = wolfa_requireModule("commands.commands")
local auth = wolfa_requireModule("auth.auth")
local output = wolfa_requireModule("game.output")
local voting = wolfa_requireModule("game.voting")

function commandEnableVote(clientId, command)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^denablevote: ^9next map voting has been enabled.\";")
output.clientChat("^denablevote: ^9next map voting has been enabled.")

voting.force("nextmap")

Expand Down
19 changes: 10 additions & 9 deletions luascripts/wolfadmin/commands/admin/finger.lua
Expand Up @@ -18,14 +18,15 @@
local auth = wolfa_requireModule("auth.auth")
local commands = wolfa_requireModule("commands.commands")
local config = wolfa_requireModule("config.config")
local output = wolfa_requireModule("game.output")
local players = wolfa_requireModule("players.players")
local util = wolfa_requireModule("util.util")

function commandFinger(clientId, command, victim)
local cmdClient

if victim == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dfinger usage: "..commands.getadmin("finger")["syntax"].."\";")
output.clientConsole("^dfinger usage: "..commands.getadmin("finger")["syntax"], clientId)

return true
elseif tonumber(victim) == nil or tonumber(victim) < 0 or tonumber(victim) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then
Expand All @@ -35,11 +36,11 @@ function commandFinger(clientId, command, victim)
end

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

return true
elseif not et.gentity_get(cmdClient, "pers.netname") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dfinger: ^9no connected player by that name or slot #\";")
output.clientConsole("^dfinger: ^9no connected player by that name or slot #", clientId)

return true
end
Expand All @@ -53,12 +54,12 @@ function commandFinger(clientId, command, victim)
local guid = players.getGUID(cmdClient)
local ip = players.getIP(cmdClient)

et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dInformation about ^7"..name.."^d:\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dName: ^2"..cleanname.." ("..codedname..")\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dSlot: ^2"..slot..(slot < tonumber(et.trap_Cvar_Get("sv_privateClients")) and " ^9(private)" or "").."\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dLevel: ^2"..level.." ("..levelName..")\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dGUID: ^2"..guid.."\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dIP: ^2"..ip.."\";")
output.clientConsole("^dInformation about ^7"..name.."^d:", clientId)
output.clientConsole("^dName: ^2"..cleanname.." ("..codedname..")", clientId)
output.clientConsole("^dSlot: ^2"..slot..(slot < tonumber(et.trap_Cvar_Get("sv_privateClients")) and " ^9(private)" or ""), clientId)
output.clientConsole("^dLevel: ^2"..level.." ("..levelName..")", clientId)
output.clientConsole("^dGUID: ^2"..guid.."", clientId)
output.clientConsole("^dIP: ^2"..ip.."", clientId)

return true
end
Expand Down

0 comments on commit f612180

Please sign in to comment.