Advanced player punishments (issue #55)

Warns, mutes and bans are stored in the database. A history is available through !showhistory [player] and !showwarns has been merged into this.
This commit is contained in:
Timo Smit 2017-01-12 18:26:45 +01:00
parent f0af3cfe03
commit f8cbba943f
16 changed files with 539 additions and 177 deletions

View file

@ -15,16 +15,19 @@
-- 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 "luascripts.wolfadmin.util.constants"
local events = require "luascripts.wolfadmin.util.events"
local settings = require "luascripts.wolfadmin.util.settings"
local files = require "luascripts.wolfadmin.util.files"
local util = require "luascripts.wolfadmin.util.util"
local db = require "luascripts.wolfadmin.db.db"
local warns = require "luascripts.wolfadmin.admin.warns"
local players = require "luascripts.wolfadmin.players.players"
-- local stats = require "luascripts.wolfadmin.players.stats"
local constants = require "luascripts.wolfadmin.util.constants"
local events = require "luascripts.wolfadmin.util.events"
local files = require "luascripts.wolfadmin.util.files"
local settings = require "luascripts.wolfadmin.util.settings"
local util = require "luascripts.wolfadmin.util.util"
local admin = {}
local teamLocks = {
@ -37,6 +40,18 @@ function admin.putPlayer(clientId, teamId)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "forceteam "..clientId.." "..util.getTeamCode(teamId)..";")
end
function admin.mutePlayer(victimId, invokerId, type, duration, reason)
players.setMuted(victimId, true, type, os.time(), duration)
db.addMute(victimId, invokerId, type, os.time(), duration, reason)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "ccp "..victimId.." \"^7You have been muted by "..players.getName(invokerId)..": ^7"..reason..".\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay -1 \"^dmute: ^7"..players.getName(victimId).." ^9has been muted.\";")
end
function admin.kickPlayer(victimId, invokerId, reason)
et.trap_DropClient(victimId, "You have been kicked, Reason: "..(reason and reason or "kicked by admin"), 0)
end
function admin.lockTeam(teamId)
teamLocks[teamId] = false
end
@ -60,6 +75,12 @@ function admin.onconnectattempt(clientId, firstTime, isBot)
if guid == "NO_GUID" or guid == "unknown" then
return "\n\nIt appears you do not have a ^7GUID^9/^7etkey^9. In order to play on this server, enable ^7PunkBuster ^9(use ^7\\pb_cl_enable^9) ^9and/or create an ^7etkey^9.\n\nMore info: ^7www.etkey.org"
end
local playerId = db.getplayer(guid)["id"]
local ban = db.getBanByPlayer(playerId)
if ban then
return "\n\nYou have been banned for "..ban["duration"].." seconds, Reason: "..ban["reason"]
end
end
events.trigger("onClientConnect", clientId, firstTime, isBot)

54
luascripts/admin/bans.lua Normal file
View file

@ -0,0 +1,54 @@
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2017 Timo 'Timothy' Smit
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- 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 db = require "luascripts.wolfadmin.db.db"
local players = require "luascripts.wolfadmin.players.players"
local events = require "luascripts.wolfadmin.util.events"
local settings = require "luascripts.wolfadmin.util.settings"
local bans = {}
function bans.get(banId)
return db.getBan(banId)
end
function bans.getCount()
return db.getBansCount()
end
function bans.getList(start, limit)
return db.getBans(start, limit)
end
function bans.add(victimId, invokerId, duration, reason)
local victimPlayerId = db.getplayer(players.getGUID(victimId))["id"]
local invokerPlayerId = db.getplayer(players.getGUID(invokerId))["id"]
local reason = reason and reason or "banned by admin"
db.addBan(victimPlayerId, invokerPlayerId, os.time(), duration, reason)
et.trap_DropClient(victimId, "You have been banned for "..duration.." seconds, Reason: "..reason, 0)
end
function bans.remove(banId)
db.removeBan(banId)
end
return bans

View file

@ -22,43 +22,33 @@ local players = require "luascripts.wolfadmin.players.players"
local events = require "luascripts.wolfadmin.util.events"
local settings = require "luascripts.wolfadmin.util.settings"
local warns = {}
local history = {}
function warns.get(clientId, warnId)
if warnId then
return db.getwarn(warnId)
else
local playerid = db.getplayer(players.getGUID(clientId))["id"]
return db.getwarns(playerid)
end
function history.get(clientId, historyId)
return db.getHistoryItem(historyId)
end
function warns.getcount(clientId)
local playerid = db.getplayer(players.getGUID(clientId))["id"]
function history.getCount(clientId)
local playerId = db.getplayer(players.getGUID(clientId))["id"]
return db.getwarnscount(playerid)
return db.getHistoryCount(playerId)
end
function warns.getlimit(clientId, start, limit)
local playerid = db.getplayer(players.getGUID(clientId))["id"]
function history.getList(clientId, start, limit)
local playerId = db.getplayer(players.getGUID(clientId))["id"]
return db.getwarns(playerid, start, limit)
return db.getHistory(playerId, start, limit)
end
function warns.add(clientId, reason, adminId, datetime)
local playerid = db.getplayer(players.getGUID(clientId))["id"]
local adminid = db.getplayer(players.getGUID(adminId))["id"]
function history.add(victimId, invokerId, type, reason)
local victimPlayerId = db.getplayer(players.getGUID(victimId))["id"]
local invokerPlayerId = db.getplayer(players.getGUID(invokerId))["id"]
db.addwarn(playerid, reason, adminid, datetime)
db.addHistory(victimPlayerId, invokerPlayerId, type, os.time(), reason)
end
function warns.remove(clientId, warnId)
if not warns.get(clientId, warnId) then
return
function history.remove(clientId, historyId)
db.removeHistory(historyId)
end
db.removewarn(warnId)
end
return warns
return history

View file

@ -39,6 +39,10 @@ end
function acl.isallowed(clientId, permission)
-- stub function, reads from cache
if permission == auth.PERM_IMMUNE or permission == "!" then
return 0
end
return 1
end

View file

@ -33,6 +33,7 @@ auth.PERM_LISTTEAMS = "listteams"
auth.PERM_LISTMAPS = "listmaps"
auth.PERM_LISTSPREES = "listsprees"
auth.PERM_LISTRULES = "listrules"
auth.PERM_LISTHISTORY = "listhistory"
auth.PERM_LISTWARNS = "listwarns"
auth.PERM_LISTBANS = "listbans"
auth.PERM_LISTALIASES = "listaliases"

View file

@ -33,6 +33,7 @@ local flags = {
[auth.PERM_LISTMAPS] = "C",
[auth.PERM_LISTSPREES] = "I",
[auth.PERM_LISTRULES] = "C",
[auth.PERM_LISTHISTORY] = "f",
[auth.PERM_LISTWARNS] = "R",
[auth.PERM_LISTBANS] = "B",
[auth.PERM_LISTALIASES] = "f",

View file

@ -0,0 +1,81 @@
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2017 Timo 'Timothy' Smit
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- 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 auth = require "luascripts.wolfadmin.auth.auth"
local bans = require "luascripts.wolfadmin.admin.bans"
local history = require "luascripts.wolfadmin.admin.history"
local commands = require "luascripts.wolfadmin.commands.commands"
local util = require "luascripts.wolfadmin.util.util"
local settings = require "luascripts.wolfadmin.util.settings"
function commandBan(clientId, cmdArguments)
if cmdArguments[1] == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban usage: "..commands.getadmin("ban")["syntax"].."\";")
return true
elseif tonumber(cmdArguments[1]) == nil then
cmdClient = et.ClientNumberFromString(cmdArguments[1])
else
cmdClient = tonumber(cmdArguments[1])
end
if cmdClient == -1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";")
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 #\";")
return true
end
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)
elseif auth.isallowed(clientId, "8") ~= 1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban usage: "..commands.getadmin("ban")["syntax"].."\";")
return true
end
if auth.isallowed(cmdClient, "!") == 1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";")
return true
elseif auth.getlevel(cmdClient) > auth.getlevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true
end
bans.add(cmdClient, clientId, duration, reason)
history.add(cmdClient, clientId, "ban", reason)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dban: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been banned for "..duration.." seconds\";")
return true
end
commands.addadmin("ban", commandBan, auth.PERM_BAN, "ban a player with an optional duration and reason", "^9[^3name|slot#^9] ^9(^3duration^9) ^9(^3reason^9)", (settings.get("g_standalone") == 0))

View file

@ -1,61 +0,0 @@
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2017 Timo 'Timothy' Smit
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- 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 db = require "luascripts.wolfadmin.db.db"
local settings = require "luascripts.wolfadmin.util.settings"
local commands = require "luascripts.wolfadmin.commands.commands"
local auth = require "luascripts.wolfadmin.auth.auth"
local warns = require "luascripts.wolfadmin.admin.warns"
function commandRemoveWarn(clientId, cmdArguments)
if settings.get("g_warnHistory") == 0 or not db.isconnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^ddewarn: ^9warn history is disabled.\";")
return true
elseif #cmdArguments < 2 or tonumber(cmdArguments[2]) == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^ddewarn usage: "..commands.getadmin("dewarn")["syntax"].."\";")
return true
elseif tonumber(cmdArguments[1]) == nil then
cmdClient = et.ClientNumberFromString(cmdArguments[1])
else
cmdClient = tonumber(cmdArguments[1])
end
if cmdClient == -1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^ddewarn: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";")
return true
elseif not et.gentity_get(cmdClient, "pers.netname") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^ddewarn: ^9no connected player by that name or slot #\";")
return true
end
local playerWarn = warns.get(cmdClient, tonumber(cmdArguments[2]))
if not playerWarn then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^ddewarn: ^9warn #"..cmdArguments[2].." does not exist for ^7"..et.gentity_get(cmdClient, "pers.netname").."^9.\";")
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^ddewarn: ^9warn #"..cmdArguments[2].." removed for ^7"..et.gentity_get(cmdClient, "pers.netname").."^9.\";")
warns.remove(cmdClient, tonumber(cmdArguments[2]))
end
return true
end
commands.addadmin("dewarn", commandRemoveWarn, auth.PERM_WARN, "remove a warning for a certain player", "^9[^3name|slot#^9] ^9[^3warn#^9]", function() return (settings.get("g_warnHistory") == 0 or not db.isconnected()) end)

View file

@ -16,9 +16,14 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local auth = require "luascripts.wolfadmin.auth.auth"
local settings = require "luascripts.wolfadmin.util.settings"
local admin = require "luascripts.wolfadmin.admin.admin"
local history = require "luascripts.wolfadmin.admin.history"
local commands = require "luascripts.wolfadmin.commands.commands"
local settings = require "luascripts.wolfadmin.util.settings"
function commandKick(clientId, cmdArguments)
if cmdArguments[1] == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dkick usage: "..commands.getadmin("kick")["syntax"].."\";")
@ -50,8 +55,11 @@ function commandKick(clientId, cmdArguments)
return true
end
et.trap_DropClient(cmdClient, "You have been kicked, Reason: "..(cmdArguments[2] and cmdArguments[2] or "kicked by admin"), 0)
local reason = table.concat(cmdArguments, " ", 2)
return false
admin.kickPlayer(cmdClient, clientId, reason)
history.add(cmdClient, clientId, "kick", reason)
return true
end
commands.addadmin("kick", commandKick, auth.PERM_KICK, "kick a player with an optional reason", "^9[^3name|slot#^9] ^9(^3reason^9)", (settings.get("g_standalone") == 0))

View file

@ -17,6 +17,9 @@
local auth = require "luascripts.wolfadmin.auth.auth"
local admin = require "luascripts.wolfadmin.admin.admin"
local history = require "luascripts.wolfadmin.admin.history"
local commands = require "luascripts.wolfadmin.commands.commands"
local players = require "luascripts.wolfadmin.players.players"
@ -45,15 +48,15 @@ function commandMute(clientId, cmdArguments)
return true
end
local muteTime, muteReason = 600, "muted by admin"
local duration, reason = 600, "muted by admin"
if cmdArguments[2] and util.getTimeFromString(cmdArguments[2]) and cmdArguments[3] then
muteTime = util.getTimeFromString(cmdArguments[2])
muteReason = table.concat(cmdArguments, " ", 3)
duration = util.getTimeFromString(cmdArguments[2])
reason = table.concat(cmdArguments, " ", 3)
elseif cmdArguments[2] and util.getTimeFromString(cmdArguments[2]) then
muteTime = util.getTimeFromString(cmdArguments[2])
duration = util.getTimeFromString(cmdArguments[2])
elseif cmdArguments[2] then
muteReason = table.concat(cmdArguments, " ", 2)
reason = table.concat(cmdArguments, " ", 2)
elseif auth.isallowed(clientId, "8") ~= 1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute usage: "..commands.getadmin("mute")["syntax"].."\";")
@ -74,9 +77,10 @@ function commandMute(clientId, cmdArguments)
return true
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been muted for "..muteTime.." seconds\";")
admin.mutePlayer(cmdClient, clientId, players.MUTE_CHAT + players.MUTE_VOICE, duration, reason)
history.add(cmdClient, clientId, "mute", reason)
players.setMuted(cmdClient, true, players.MUTE_CHAT + players.MUTE_VOICE, os.time(), muteTime)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been muted for "..duration.." seconds\";")
return true
end

View file

@ -0,0 +1,55 @@
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2017 Timo 'Timothy' Smit
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- 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 auth = require "luascripts.wolfadmin.auth.auth"
local bans = require "luascripts.wolfadmin.admin.bans"
local db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands"
local pagination = require "luascripts.wolfadmin.util.pagination"
local settings = require "luascripts.wolfadmin.util.settings"
local util = require "luascripts.wolfadmin.util.util"
function commandShowBans(clientId, cmdArguments)
if not db.isconnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowbans: ^9bans are disabled.\";")
return true
end
local count = bans.getCount()
local limit, offset = pagination.calculate(count, 30, tonumber(cmdArguments[2]))
local bans = bans.getList(limit, offset)
if not (bans and #bans > 0) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowbans: ^9there are no bans.\";")
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^d"..count.." bans:\";")
for _, ban in pairs(bans) do
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^f"..string.format("%4s", ban["id"]).." ^7"..string.format("%-20s", util.removeColors(db.getlastalias(ban["victim_id"])["alias"])).." ^f"..os.date("%d/%m/%Y", ban["issued"]).." ^7"..string.format("%-20s", util.removeColors(db.getlastalias(ban["invoker_id"])["alias"])).." ^f"..os.date("%d/%m/%Y", ban["expires"]).." ^7"..ban["reason"].."\";")
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9Showing results ^7"..(offset + 1).." ^9- ^7"..limit.." ^9of ^7"..count.."^9.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dshowbans: ^9bans were printed to the console.\";")
end
return true
end
commands.addadmin("showbans", commandShowBans, auth.PERM_LISTBANS, "display a (partial) list of active bans", "(^hstart at ban#^9) ((^hbanner^9) (^3banner's name^9)) ((^3find^9) (^hbanned player^9)) ((^3reason^9) (^hreason for ban^9))", function() return (not db.isconnected()) end)

View file

@ -16,21 +16,24 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local auth = require "luascripts.wolfadmin.auth.auth"
local util = require "luascripts.wolfadmin.util.util"
local settings = require "luascripts.wolfadmin.util.settings"
local pagination = require "luascripts.wolfadmin.util.pagination"
local history = require "luascripts.wolfadmin.admin.history"
local db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands"
local warns = require "luascripts.wolfadmin.admin.warns"
function commandShowWarns(clientId, cmdArguments)
if settings.get("g_warnHistory") == 0 or not db.isconnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowwarns: ^9warn history is disabled.\";")
local util = require "luascripts.wolfadmin.util.util"
local pagination = require "luascripts.wolfadmin.util.pagination"
local settings = require "luascripts.wolfadmin.util.settings"
function commandListHistory(clientId, cmdArguments)
if settings.get("g_standalone") == 0 or not db.isconnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowhistory: ^9warn history is disabled.\";")
return true
elseif cmdArguments[1] == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowwarns usage: "..commands.getadmin("showwarns")["syntax"].."\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowhistory usage: "..commands.getadmin("showwarns")["syntax"].."\";")
return true
elseif tonumber(cmdArguments[1]) == nil then
@ -40,31 +43,31 @@ function commandShowWarns(clientId, cmdArguments)
end
if cmdClient == -1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowwarns: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowhistory: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";")
return true
elseif not et.gentity_get(cmdClient, "pers.netname") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowwarns: ^9no connected player by that name or slot #\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowhistory: ^9no connected player by that name or slot #\";")
return true
end
local count = warns.getcount(cmdClient)
local count = history.getCount(cmdClient)
local limit, offset = pagination.calculate(count, 30, tonumber(cmdArguments[2]))
local playerWarns = warns.getlimit(cmdClient, limit, offset)
local playerHistory = history.getList(cmdClient, limit, offset)
if not (playerWarns and #playerWarns > 0) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowwarns: ^9there are no warnings for player ^7"..et.gentity_get(cmdClient, "pers.netname").."^9.\";")
if not (playerHistory and #playerHistory > 0) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowhistory: ^9there is no history for player ^7"..et.gentity_get(cmdClient, "pers.netname").."^9.\";")
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dWarns for ^7"..et.gentity_get(cmdClient, "pers.netname").."^d:\";")
for _, warn in pairs(playerWarns) do
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^f"..string.format("%4s", warn["id"]).." ^7"..string.format("%-20s", util.removeColors(db.getlastalias(warn["admin_id"])["alias"])).." ^f"..os.date("%d/%m/%Y", warn["datetime"]).." ^7"..warn["reason"].."\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dHistory for ^7"..et.gentity_get(cmdClient, "pers.netname").."^d:\";")
for _, history in pairs(playerHistory) do
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^f"..string.format("%4s", history["id"]).." ^7"..string.format("%-20s", util.removeColors(db.getlastalias(history["invoker_id"])["alias"])).." ^f"..os.date("%d/%m/%Y", history["datetime"]).." ^7"..string.format("%-8s", history["type"]..":").." "..history["reason"].."\";")
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9Showing results ^7"..(offset + 1).." ^9- ^7"..limit.." ^9of ^7"..count.."^9.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dshowwarns: ^9warnings for ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9were printed to the console.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dshowhistory: ^9history for ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9was printed to the console.\";")
end
return true
end
commands.addadmin("showwarns", commandShowWarns, auth.PERM_LISTWARNS, "display warnings for a specific player", "^9[^3name|slot#^9] ^9(^hoffset^9)", function() return (settings.get("g_warnHistory") == 0 or not db.isconnected()) end)
commands.addadmin("showhistory", commandListHistory, auth.PERM_LISTHISTORY, "display history for a specific player", "^9[^3name|slot#^9] ^9(^hoffset^9)", function() return (settings.get("g_standalone") == 0 or not db.isconnected()) end)

View file

@ -0,0 +1,51 @@
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2017 Timo 'Timothy' Smit
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- 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 auth = require "luascripts.wolfadmin.auth.auth"
local bans = require "luascripts.wolfadmin.admin.bans"
local commands = require "luascripts.wolfadmin.commands.commands"
local db = require "luascripts.wolfadmin.db.db"
local settings = require "luascripts.wolfadmin.util.settings"
function commandRemoveBan(clientId, cmdArguments)
if settings.get("g_standalone") == 0 or not db.isconnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dunban: ^9bans are disabled.\";")
return true
elseif #cmdArguments < 1 or tonumber(cmdArguments[1]) == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dunban usage: "..commands.getadmin("unban")["syntax"].."\";")
return true
end
local ban = bans.get(tonumber(cmdArguments[1]))
if not ban then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dunban: ^9ban #"..cmdArguments[1].." does not exist.\";")
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dunban: ^9ban #"..cmdArguments[1].." removed.\";")
bans.remove(tonumber(cmdArguments[1]))
end
return true
end
commands.addadmin("unban", commandRemoveBan, auth.PERM_BAN, "unbans a player specified ban number as seen in ^2!showbans^9", "^9[^3ban#^9]", function() return (settings.get("g_standalone") == 0 or not db.isconnected()) end)

View file

@ -17,6 +17,9 @@
local auth = require "luascripts.wolfadmin.auth.auth"
local admin = require "luascripts.wolfadmin.admin.admin"
local history = require "luascripts.wolfadmin.admin.history"
local commands = require "luascripts.wolfadmin.commands.commands"
local players = require "luascripts.wolfadmin.players.players"
@ -44,15 +47,15 @@ function commandVoiceMute(clientId, cmdArguments)
return true
end
local vmuteTime, vmuteReason = 600, "muted by admin"
local duration, reason = 600, "muted by admin"
if cmdArguments[2] and util.getTimeFromString(cmdArguments[2]) and cmdArguments[3] then
vmuteTime = util.getTimeFromString(cmdArguments[2])
vmuteReason = table.concat(cmdArguments, " ", 3)
duration = util.getTimeFromString(cmdArguments[2])
reason = table.concat(cmdArguments, " ", 3)
elseif cmdArguments[2] and util.getTimeFromString(cmdArguments[2]) then
vmuteTime = util.getTimeFromString(cmdArguments[2])
duration = util.getTimeFromString(cmdArguments[2])
elseif cmdArguments[2] then
vmuteReason = table.concat(cmdArguments, " ", 2)
reason = table.concat(cmdArguments, " ", 2)
elseif auth.isallowed(clientId, "8") ~= 1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute usage: "..commands.getadmin("vmute")["syntax"].."\";")
@ -73,9 +76,10 @@ function commandVoiceMute(clientId, cmdArguments)
return true
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been voicemuted for "..vmuteTime.." seconds\";")
admin.mutePlayer(cmdClient, clientId, players.MUTE_VOICE, duration, reason)
history.add(cmdClient, clientId, "mute", reason)
players.setMuted(cmdClient, true, players.MUTE_VOICE, os.time(), vmuteTime)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been voicemuted for "..vmuteTime.." seconds\";")
return true
end

View file

@ -16,12 +16,19 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local auth = require "luascripts.wolfadmin.auth.auth"
local settings = require "luascripts.wolfadmin.util.settings"
local db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands"
local warns = require "luascripts.wolfadmin.admin.warns"
function commandAddWarn(clientId, cmdArguments)
local admin = require "luascripts.wolfadmin.admin.admin"
local history = require "luascripts.wolfadmin.admin.history"
local db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands"
local players = require "luascripts.wolfadmin.players.players"
local settings = require "luascripts.wolfadmin.util.settings"
function commandWarn(clientId, cmdArguments)
if settings.get("g_warnHistory") == 0 or not db.isconnected() then
return false
elseif #cmdArguments < 2 then
@ -38,8 +45,46 @@ function commandAddWarn(clientId, cmdArguments)
return false
end
warns.add(cmdClient, table.concat(cmdArguments, " ", 2), clientId, os.time())
history.add(cmdClient, clientId, os.time(), "warn", table.concat(cmdArguments, " ", 2))
return false
end
commands.addadmin("warn", commandAddWarn, auth.PERM_WARN, "warns a player by displaying the reason", "^9[^3name|slot#^9] ^9[^3reason^9]", true)
commands.addadmin("warn", commandWarn, auth.PERM_WARN, "warns a player by displaying the reason", "^9[^3name|slot#^9] ^9[^3reason^9]", true)
function commandWarn(clientId, cmdArguments)
if #cmdArguments < 2 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dwarn usage: "..commands.getadmin("warn")["syntax"].."\";")
return true
elseif tonumber(cmdArguments[1]) == nil then
cmdClient = et.ClientNumberFromString(cmdArguments[1])
else
cmdClient = tonumber(cmdArguments[1])
end
if cmdClient == -1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dwarn: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";")
return true
elseif not et.gentity_get(cmdClient, "pers.netname") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dwarn: ^9no connected player by that name or slot #\";")
return true
end
if auth.getlevel(cmdClient) > auth.getlevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dwarn: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true
end
local reason = table.concat(cmdArguments, " ", 2)
history.add(cmdClient, clientId, "warn", reason)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "ccp "..cmdClient.." \"^7You have been warned by "..players.getName(clientId)..": ^7"..reason..".\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay -1 \"^dwarn: ^7"..players.getName(cmdClient).." ^9has been warned.\";")
return true
end
commands.addadmin("warn", commandWarn, auth.PERM_WARN, "warns a player by displaying the reason", "^9[^3name|slot#^9] ^9[^3reason^9]", (settings.get("g_standalone") == 0 and db.isconnected()))

View file

@ -171,17 +171,17 @@ function sqlite3.getlevels(playerid, limit, offset)
return levels
end
-- warns
function sqlite3.addwarn(playerid, reason, adminid, datetime)
cur = assert(con:execute("INSERT INTO `warn` (`player_id`, `reason`, `admin_id`, `datetime`) VALUES ("..tonumber(playerid)..", '"..util.escape(reason).."', "..tonumber(adminid)..", "..tonumber(datetime)..")"))
-- history
function sqlite3.addHistory(victimId, invokerId, type, datetime, reason)
cur = assert(con:execute("INSERT INTO `history` (`victim_id`, `invoker_id`, `type`, `datetime`, `reason`) VALUES ("..tonumber(victimId)..", "..tonumber(invokerId)..", '"..util.escape(type).."', "..tonumber(datetime)..", '"..util.escape(reason).."')"))
end
function sqlite3.removewarn(warnid)
cur = assert(con:execute("DELETE FROM `warn` WHERE `id`="..tonumber(warnid)..""))
function sqlite3.removeHistory(historyId)
cur = assert(con:execute("DELETE FROM `history` WHERE `id`="..tonumber(historyId)..""))
end
function sqlite3.getwarnscount(playerid)
cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `warn` WHERE `player_id`="..tonumber(playerid)..""))
function sqlite3.getHistoryCount(playerId)
cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `history` WHERE `victim_id`="..tonumber(playerId)..""))
local count = tonumber(cur:fetch({}, "a")["count"])
cur:close()
@ -189,11 +189,11 @@ function sqlite3.getwarnscount(playerid)
return count
end
function sqlite3.getwarns(playerid, limit, offset)
function sqlite3.getHistory(playerId, limit, offset)
limit = limit or 30
offset = offset or 0
cur = assert(con:execute("SELECT * FROM `warn` WHERE `player_id`="..tonumber(playerid).." LIMIT "..tonumber(limit).." OFFSET "..tonumber(offset)))
cur = assert(con:execute("SELECT * FROM `history` WHERE `victim_id`="..tonumber(playerId).." LIMIT "..tonumber(limit).." OFFSET "..tonumber(offset)))
local warns = {}
local row = cur:fetch({}, "a")
@ -208,13 +208,114 @@ function sqlite3.getwarns(playerid, limit, offset)
return warns
end
function sqlite3.getwarn(warnid)
cur = assert(con:execute("SELECT * FROM `warn` WHERE `id`="..tonumber(warnid)..""))
function sqlite3.getHistoryItem(historyId)
cur = assert(con:execute("SELECT * FROM `history` WHERE `id`="..tonumber(historyId)..""))
local warn = cur:fetch({}, "a")
local history = cur:fetch({}, "a")
cur:close()
return warn
return history
end
-- mutes
function sqlite3.addMute(victimId, invokerId, type, issued, duration, reason)
cur = assert(con:execute("INSERT INTO `mute` (`victim_id`, `invoker_id`, `type`, `issued`, `expires`, `duration`, `reason`) VALUES ("..tonumber(victimId)..", "..tonumber(invokerId)..", '"..util.escape(type).."', "..tonumber(issued)..", "..tonumber(issued + duration)..", "..tonumber(duration)..", '"..util.escape(reason).."')"))
end
function sqlite3.removeMute(muteId)
cur = assert(con:execute("DELETE FROM `mute` WHERE `id`="..tonumber(muteId)..""))
end
function sqlite3.getMutesCount()
cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `mute`"))
local count = tonumber(cur:fetch({}, "a")["count"])
cur:close()
return count
end
function sqlite3.getMutes(limit, offset)
limit = limit or 30
offset = offset or 0
cur = assert(con:execute("SELECT * FROM `mute` LIMIT "..tonumber(limit).." OFFSET "..tonumber(offset)))
local mutes = {}
local row = cur:fetch({}, "a")
while row do
table.insert(mutes, tables.copy(row))
row = cur:fetch(row, "a")
end
cur:close()
return mutes
end
function sqlite3.getMute(muteId)
cur = assert(con:execute("SELECT * FROM `mute` WHERE `id`="..tonumber(muteId)..""))
local mute = cur:fetch({}, "a")
cur:close()
return mute
end
-- bans
function sqlite3.addBan(victimId, invokerId, issued, duration, reason)
cur = assert(con:execute("INSERT INTO `ban` (`victim_id`, `invoker_id`, `issued`, `expires`, `duration`, `reason`) VALUES ("..tonumber(victimId)..", "..tonumber(invokerId)..", "..tonumber(issued)..", "..(tonumber(issued) + tonumber(duration))..", "..tonumber(duration)..", '"..util.escape(reason).."')"))
end
function sqlite3.removeBan(banId)
cur = assert(con:execute("DELETE FROM `ban` WHERE `id`="..tonumber(banId)..""))
end
function sqlite3.getBansCount()
cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `ban`"))
local count = tonumber(cur:fetch({}, "a")["count"])
cur:close()
return count
end
function sqlite3.getBans(limit, offset)
limit = limit or 30
offset = offset or 0
cur = assert(con:execute("SELECT * FROM `ban` LIMIT "..tonumber(limit).." OFFSET "..tonumber(offset)))
local bans = {}
local row = cur:fetch({}, "a")
while row do
table.insert(bans, tables.copy(row))
row = cur:fetch(row, "a")
end
cur:close()
return bans
end
function sqlite3.getBan(banId)
cur = assert(con:execute("SELECT * FROM `ban` WHERE `id`="..tonumber(banId)..""))
local ban = cur:fetch({}, "a")
cur:close()
return ban
end
function sqlite3.getBanByPlayer(playerId)
cur = assert(con:execute("SELECT * FROM `ban` WHERE `victim_id`="..tonumber(playerId).." AND `expires`>"..os.time()))
local ban = cur:fetch({}, "a")
cur:close()
return ban
end
-- maps