mirror of
https://github.com/etlegacy/wolfadmin.git
synced 2025-04-18 14:50:49 +00:00
Implemented a basic censor module (refs #87)
* implemented chat message censor * created settings * created constants for chat type commands
This commit is contained in:
parent
48a1375396
commit
4e917f7229
8 changed files with 163 additions and 2 deletions
|
@ -37,6 +37,12 @@ maxdif = 5
|
|||
selection = 0
|
||||
interval = 30
|
||||
|
||||
[censor]
|
||||
file = "censor.toml"
|
||||
mode = 1
|
||||
mute = 60
|
||||
kick = 1
|
||||
|
||||
[game]
|
||||
announcerevives = 1
|
||||
|
||||
|
|
110
luascripts/wolfadmin/admin/censor.lua
Normal file
110
luascripts/wolfadmin/admin/censor.lua
Normal file
|
@ -0,0 +1,110 @@
|
|||
|
||||
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
|
||||
-- Copyright (C) 2015-2019 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 mutes = wolfa_requireModule("admin.mutes")
|
||||
local history = wolfa_requireModule("admin.history")
|
||||
|
||||
local players = wolfa_requireModule("players.players")
|
||||
|
||||
local events = wolfa_requireModule("util.events")
|
||||
local settings = wolfa_requireModule("util.settings")
|
||||
|
||||
local toml = wolfa_requireLib("toml")
|
||||
|
||||
local censor = {}
|
||||
|
||||
local words = {}
|
||||
local names = {}
|
||||
|
||||
function censor.filterMessage(message)
|
||||
local censored = false
|
||||
|
||||
for _, word in ipairs(words) do
|
||||
local occurrences
|
||||
|
||||
message, occurrences = string.gsub(message, word["pattern"], "*censor*")
|
||||
|
||||
censored = (censored or occurrences > 0) and true or false
|
||||
end
|
||||
|
||||
return censored, message
|
||||
end
|
||||
|
||||
function censor.punishClient(clientId)
|
||||
if settings.get("g_censorMute") > 0 then
|
||||
mutes.add(clientId, -1337, players.MUTE_CHAT + players.MUTE_VOICE, settings.get("g_censorMute"), "censor")
|
||||
|
||||
if settings.get("g_playerHistory") ~= 0 then
|
||||
history.add(clientId, -1337, "mute", "censor")
|
||||
end
|
||||
|
||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dmute: ^7"..players.getName(clientId).." ^9has been muted for "..settings.get("g_censorMute").." seconds\";")
|
||||
end
|
||||
end
|
||||
|
||||
function censor.load()
|
||||
local fileName = settings.get("g_fileCensor")
|
||||
|
||||
if fileName == "" then
|
||||
return 0
|
||||
end
|
||||
|
||||
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_READ)
|
||||
|
||||
if fileLength == -1 then
|
||||
return 0
|
||||
end
|
||||
|
||||
-- in case someone issued a !readconfig, make sure the old data is removed
|
||||
censor.clear()
|
||||
|
||||
local fileString = et.trap_FS_Read(fileDescriptor, fileLength)
|
||||
|
||||
et.trap_FS_FCloseFile(fileDescriptor)
|
||||
|
||||
local fileTable = toml.parse(fileString)
|
||||
|
||||
if fileTable["word"] then
|
||||
for _, word in ipairs(fileTable["word"]) do
|
||||
if word["pattern"] then
|
||||
table.insert(words, word)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if fileTable["name"] then
|
||||
for _, name in ipairs(fileTable["name"]) do
|
||||
if name["pattern"] then
|
||||
table.insert(names, name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return #words + #names
|
||||
end
|
||||
|
||||
function censor.clear()
|
||||
words = {}
|
||||
names = {}
|
||||
end
|
||||
|
||||
function censor.oninit(levelTime, randomSeed, restartMap)
|
||||
censor.load()
|
||||
end
|
||||
events.handle("onGameInit", censor.oninit)
|
||||
|
||||
return censor
|
|
@ -15,6 +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 censor = require (wolfa_getLuaPath()..".admin.censor")
|
||||
local rules = require (wolfa_getLuaPath()..".admin.rules")
|
||||
|
||||
local auth = require (wolfa_getLuaPath()..".auth.auth")
|
||||
|
@ -41,12 +42,12 @@ commands.addadmin("readconfig", commandReadconfig, auth.PERM_READCONFIG, "reload
|
|||
|
||||
function commandReadconfig(clientId, command)
|
||||
settings.load()
|
||||
local censorCount = censor.load()
|
||||
local rulesCount = rules.load()
|
||||
local greetingsCount = greetings.load()
|
||||
local spreesCount = sprees.load()
|
||||
|
||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"readconfig: loaded "..greetingsCount.." greetings, "..rulesCount.." rules, "..spreesCount.." sprees\";")
|
||||
|
||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"readconfig: loaded "..censorCount.." censor patterns, loaded "..greetingsCount.." greetings, "..rulesCount.." rules, "..spreesCount.." sprees\";")
|
||||
return false
|
||||
end
|
||||
commands.addadmin("readconfig", commandReadconfig, auth.PERM_READCONFIG, "reloads the config file", nil, nil, (settings.get("g_standalone") == 0))
|
||||
|
|
|
@ -15,12 +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 censor = require (wolfa_getLuaPath()..".admin.censor")
|
||||
|
||||
local commands = require (wolfa_getLuaPath()..".commands.commands")
|
||||
|
||||
local players = require (wolfa_getLuaPath()..".players.players")
|
||||
|
||||
local logs = require (wolfa_getLuaPath()..".util.logs")
|
||||
local settings = require (wolfa_getLuaPath()..".util.settings")
|
||||
local util = require (wolfa_getLuaPath()..".util.util")
|
||||
|
||||
local types = {
|
||||
["say"] = "chat",
|
||||
|
@ -39,6 +42,16 @@ function commandSay(clientId, command, ...)
|
|||
return true
|
||||
end
|
||||
|
||||
local censored, message = censor.filterMessage(...)
|
||||
|
||||
if censored and settings.get("g_censorMode") ~= 0 then
|
||||
censor.punishClient(clientId)
|
||||
|
||||
et.G_Say(clientId, util.getChatFromCommand(command), message)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
logs.writeChat(clientId, types[command], ...)
|
||||
end
|
||||
commands.addclient("say", commandSay, "", "", false, (settings.get("g_standalone") == 0))
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
local admin
|
||||
local balancer
|
||||
local bans
|
||||
local censor
|
||||
local history
|
||||
local mutes
|
||||
local rules
|
||||
|
@ -90,6 +91,7 @@ function et_InitGame(levelTime, randomSeed, restartMap)
|
|||
admin = require (wolfa_getLuaPath()..".admin.admin")
|
||||
balancer = require (wolfa_getLuaPath()..".admin.balancer")
|
||||
bans = require (wolfa_getLuaPath()..".admin.bans")
|
||||
censor = require (wolfa_getLuaPath()..".admin.censor")
|
||||
history = require (wolfa_getLuaPath()..".admin.history")
|
||||
mutes = require (wolfa_getLuaPath()..".admin.mutes")
|
||||
rules = require (wolfa_getLuaPath()..".admin.rules")
|
||||
|
|
|
@ -46,6 +46,11 @@ constants.TEAM_SPECTATORS_COLOR = "^2"
|
|||
constants.TEAM_AXIS_COLOR_NAME = "red"
|
||||
constants.TEAM_ALLIES_COLOR_NAME = "blue"
|
||||
|
||||
constants.SAY_ALL_CMD = "say"
|
||||
constants.SAY_TEAM_CMD = "say_team"
|
||||
constants.SAY_BUDDY_CMD = "say_buddy"
|
||||
constants.SAY_TEAMNL_CMD = "say_teamnl"
|
||||
|
||||
constants.CLASS_SOLDIER = 0
|
||||
constants.CLASS_MEDIC = 1
|
||||
constants.CLASS_ENGINEER = 2
|
||||
|
|
|
@ -23,10 +23,14 @@ local settings = {}
|
|||
local data = {
|
||||
["g_logChat"] = "chat.log",
|
||||
["g_logAdmin"] = "admin.log",
|
||||
["g_fileCensor"] = "censor.toml",
|
||||
["g_fileGreetings"] = "greetings.toml",
|
||||
["g_fileRules"] = "rules.toml",
|
||||
["g_fileSprees"] = "sprees.toml",
|
||||
["g_playerHistory"] = 1,
|
||||
["g_censorMode"] = 1,
|
||||
["g_censorMute"] = 60,
|
||||
["g_censorKick"] = 1,
|
||||
["g_spreeMessages"] = 7,
|
||||
["g_spreeRecords"] = 1,
|
||||
["g_botRecords"] = 1,
|
||||
|
@ -86,6 +90,12 @@ local cfgStructure = {
|
|||
["selection"] = "g_evenerPlayerSelection",
|
||||
["interval"] = "g_evenerInterval"
|
||||
},
|
||||
["censor"] = {
|
||||
["file"] = "g_fileCensor",
|
||||
["mode"] = "g_censorMode",
|
||||
["mute"] = "g_censorMute",
|
||||
["kick"] = "g_censorKick"
|
||||
},
|
||||
["game"] = {
|
||||
["announcerevives"] = "g_announceRevives"
|
||||
},
|
||||
|
|
|
@ -84,6 +84,20 @@ function util.getTeamFromCode(teamCode)
|
|||
end
|
||||
end
|
||||
|
||||
function util.getChatFromCommand(chatCommand)
|
||||
if chatCommand == constants.SAY_ALL_CMD then
|
||||
return et.SAY_ALL
|
||||
elseif chatCommand == constants.SAY_TEAM_CMD then
|
||||
return et.SAY_TEAM
|
||||
elseif chatCommand == constants.SAY_BUDDY_CMD then
|
||||
return et.SAY_BUDDY
|
||||
elseif chatCommand == constants.SAY_TEAMNL_CMD then
|
||||
return et.SAY_TEAMNL
|
||||
else
|
||||
return et.SAY_ALL
|
||||
end
|
||||
end
|
||||
|
||||
function util.getTeamColor(teamId)
|
||||
if teamId == constants.TEAM_AXIS then
|
||||
return constants.TEAM_AXIS_COLOR
|
||||
|
|
Loading…
Reference in a new issue