123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- if not minetest.global_exists("anticurse") then anticurse = {} end
- function anticurse.test(str, noreport)
- if anticurse.check_string(anticurse.foul, str) then
- if noreport == false then
- local pref = utility.get_first_available_admin()
- if pref then
- minetest.chat_send_player(pref:get_player_name(), "# Server: String contains crudity!")
- end
- end
- return false
- elseif anticurse.check_string(anticurse.curse, str) then
- if noreport == false then
- local pref = utility.get_first_available_admin()
- if pref then
- minetest.chat_send_player(pref:get_player_name(), "# Server: String contains cursing!")
- end
- end
- return false
- else
- if noreport == false then
- local pref = utility.get_first_available_admin()
- if pref then
- minetest.chat_send_player(pref:get_player_name(), "# Server: String confirmed SJW-safe!")
- end
- end
- end
- return true
- end
- function anticurse.dump_files()
- local pref = utility.get_first_available_admin()
- if pref then
- minetest.chat_send_player(pref:get_player_name(), "# Server: Starting processing ...")
- end
- local lines1, err1 = io.open(minetest.get_worldpath() .. "/ac_dump_bad.txt", "w")
- if err1 then return end
- local lines2, err2 = io.open(minetest.get_worldpath() .. "/ac_dump_good.txt", "w")
- if err2 then lines1:close() return end
- local lines3, err3 = io.open(minetest.get_worldpath() .. "/cursing.txt", "r")
- if err3 then lines1:close() lines2:close() return end
- local input = lines3:read("*all")
- if type(input) == "string" then
- local rows = string.split(input, "\n")
- for k, v in ipairs(rows) do
- local s = v:sub(v:find(">") + 1)
- local result = anticurse.test(s, true)
- if result then
- lines2:write(v .. "\n")
- else
- lines1:write(v .. "\n")
- end
- end
- end
- lines1:write("\n* * * DONE * * *\n")
- lines2:write("\n* * * DONE * * *\n")
- lines1:close()
- lines2:close()
- lines3:close()
- if pref then
- minetest.chat_send_player(pref:get_player_name(), "# Server: Finished processing!")
- end
- end
- -- Public API function.
- anticurse.check = function(name, string, type)
- -- Always check player chat, even if they anticurse privs.
- -- This way I can see what players *would have* been kicked for,
- -- even if they weren't kicked (priv checking is done in the kick
- -- function). This helps improve the anticurse mod.
- if type == "foul" then
- return anticurse.check_string(anticurse.foul, string)
- elseif type == "curse" then
- return anticurse.check_string(anticurse.curse, string)
- elseif type == "impersonate" then
- return anticurse.check_string(anticurse.impersonate, string)
- elseif type == "other" then
- return anticurse.check_string(anticurse.other, string)
- end
- return false -- Nothing strange found.
- end
- -- Public API function.
- anticurse.log = function(name, msg)
- if anticurse.logfile then
- anticurse.logfile:write("[" .. os.date("%Y-%m-%d, %H:%M:%S") .. "] <" .. name .. "> " .. msg .. "\r\n")
- anticurse.logfile:flush()
- end
- end
- -- Public API function.
- anticurse.kick = function(name, reason)
- local dname = rename.gpn(name)
- if reason == "foul" then
- local ext = anticurse.get_kick_message("foul")
- minetest.chat_send_all("# Server: <" .. dname .. ">, eeew, really? " .. ext)
- spam.block_playerjoin(name, 30)
- minetest.kick_player(name, ext)
- elseif reason == "curse" then
- local ext = anticurse.get_kick_message("curse")
- minetest.chat_send_all("# Server: Player <" .. dname .. "> cursed. " .. ext)
- spam.block_playerjoin(name, 30)
- minetest.kick_player(name, ext)
- end
- end
- -- Also used to check if a rename is valid (see rename mod).
- -- Return a string, to prevent player from connecting (with string as message).
- -- Or return nil to allow them to connect.
- local singleplayer = minetest.is_singleplayer()
- anticurse.on_prejoinplayer = function(name)
- if singleplayer then
- return
- end
- if minetest.check_player_privs(name, {anticurse_bypass=true}) or gdac.player_is_admin(name) then
- return
- end
- if anticurse.check_string(anticurse.foul, name) then
- return "Eeeew, really? Pick a different username!"
- elseif anticurse.check_string(anticurse.curse, name) then
- return "Cursing. :-/ Remove the curse, please, and try again."
- elseif anticurse.check_string(anticurse.other, name) then
- return "That name is forbidden. Please pick something else."
- elseif banned_names.all_numeric(name) then
- return "All-numeric names are forbidden, sorry!"
- elseif banned_names.reserved_name(name) then
- return "That name is reserved by the server!"
- elseif anticurse.check_string(anticurse.impersonate, name) then
- return "That name is too similar to someone else!"
- end
- end
|