commit d84538601d78365141937feb742dd42ccf6ed6da Author: AndrejIT Date: Sun Jun 14 19:58:46 2015 +0300 Curse filter works for chat /me and /msg diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..a069982 --- /dev/null +++ b/README.txt @@ -0,0 +1,15 @@ +Minetest 0.4.10+ mod: chat_anticurse +========================= + +License of source code: +----------------------- +Andrey's mod for minetest game + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +http://www.gnu.org/licenses/lgpl-2.1.html + +Kick player out when curse word is said. diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..21c2521 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default? \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..ab6b64b --- /dev/null +++ b/init.lua @@ -0,0 +1,128 @@ +-- Minetest 0.4.10+ mod: chat_anticurse +-- punish player for cursing by disconnecting them +-- +-- See README.txt for licensing and other information. + +chat_anticurse = {} +chat_anticurse.simplemask = {} +-- some english and some russian curse words +-- i don't want to keep these words as cleartext in code, so they are stored like this. +local x1="a" +local x2="i" +local x3="u" +local x4="e" +local x5="o" +local y1="y" +local y2="и" +local y3="о" +local y4="е" +local y5="я" + +chat_anticurse.simplemask[1] = " "..x1.."s" .. "s " +chat_anticurse.simplemask[2] = " d" .. ""..x2.."ck" +chat_anticurse.simplemask[3] = " p"..x4.."n" .. "is" +chat_anticurse.simplemask[4] = " p" .. ""..x3.."ssy" +chat_anticurse.simplemask[5] = " h"..x5.."" .. "r".."ny " +chat_anticurse.simplemask[6] = " b"..x2.."" .. "tch " +chat_anticurse.simplemask[7] = " b"..x2.."" .. "tche" +chat_anticurse.simplemask[8] = " s"..x4.."" .. "x" +chat_anticurse.simplemask[9] = " "..y4.."б" .. "а" +chat_anticurse.simplemask[10] = " бл"..y5.."" .. " " +chat_anticurse.simplemask[11] = " ж" .. ""..y3.."п" +chat_anticurse.simplemask[12] = " х" .. ""..y1.."й" +chat_anticurse.simplemask[13] = " ч" .. "л"..y4.."н" +chat_anticurse.simplemask[14] = " п"..y2.."" .. "зд" +chat_anticurse.simplemask[15] = " в"..y3.."" .. "збуд" +chat_anticurse.simplemask[16] = " в"..y3.."з" .. "б"..y1.."ж" +chat_anticurse.simplemask[17] = " сп"..y4.."" .. "рм" +chat_anticurse.simplemask[18] = " бл"..y5.."" .. "д" +chat_anticurse.simplemask[19] = " бл"..y5.."" .. "ть" +chat_anticurse.simplemask[20] = " с" .. ""..y4.."кс" +chat_anticurse.simplemask[21] = " f" .. ""..x3.."ck" +chat_anticurse.simplemask[22] = ""..x1.."rs"..x4.."h"..x5.."l"..x4.."" +chat_anticurse.simplemask[23] = " c"..x3.."nt " + + + +chat_anticurse.check_message = function(name, message) + local checkingmessage=string.lower( name.." "..message .." " ) + local uncensored = 0 + for i=1, #chat_anticurse.simplemask do + if string.find(checkingmessage, chat_anticurse.simplemask[i], 1, plain) ~=nil then + uncensored = 2 + break + end + end + + --additional checks + if + string.find(checkingmessage, " c"..x3.."" .. "m ", 1, plain) ~=nil and + not (string.find(checkingmessage, " c"..x3.."" .. "m " .. "se", 1, plain) ~=nil) and + not (string.find(checkingmessage, " c"..x3.."" .. "m " .. "to", 1, plain) ~=nil) + then + uncensored = 2 + end + return uncensored +end + +minetest.register_on_chat_message(function(name, message) + local uncensored = chat_anticurse.check_message(name, message) + + if uncensored == 1 then + minetest.kick_player(name, "Hey! Was there a bad word?") + minetest.log("action", "Player "..name.." warned for cursing") + return true + end + + if uncensored == 2 then + minetest.kick_player(name, "Cursing or words, inappropriate to game server. Kids may be playing here!") + minetest.chat_send_all("Player <"..name.."> warned for cursing" ) + minetest.log("action", "Player "..name.." warned for cursing") + return true + end + +end) + +if minetest.chatcommands["me"] then + local old_command = minetest.chatcommands["me"].func + minetest.chatcommands["me"].func = function(name, param) + local uncensored = chat_anticurse.check_message(name, param) + + if uncensored == 1 then + minetest.kick_player(name, "Hey! Was there a bad word?") + minetest.log("action", "Player "..name.." warned for cursing") + return + end + + if uncensored == 2 then + minetest.kick_player(name, "Cursing or words, inappropriate to game server. Kids may be playing here!") + minetest.chat_send_all("Player <"..name.."> warned for cursing" ) + minetest.log("action", "Player "..name.." warned for cursing") + return + end + + return old_command(name, param) + end +end + +if minetest.chatcommands["msg"] then + local old_command = minetest.chatcommands["msg"].func + minetest.chatcommands["msg"].func = function(name, param) + local uncensored = chat_anticurse.check_message(name, param) + + if uncensored == 1 then + minetest.kick_player(name, "Hey! Was there a bad word?") + minetest.log("action", "Player "..name.." warned for cursing") + return + end + + if uncensored == 2 then + minetest.kick_player(name, "Cursing or words, inappropriate to game server. Kids may be playing here!") + minetest.chat_send_all("Player <"..name.."> warned for cursing" ) + minetest.log("action", "Player "..name.." warned for cursing") + return + end + + return old_command(name, param) + end +end \ No newline at end of file