api.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. if not minetest.global_exists("anticurse") then anticurse = {} end
  2. function anticurse.test(str, noreport)
  3. if anticurse.check_string(anticurse.foul, str) then
  4. if noreport == false then
  5. minetest.chat_send_player("MustTest", "# Server: String contains crudity!")
  6. end
  7. return false
  8. elseif anticurse.check_string(anticurse.curse, str) then
  9. if noreport == false then
  10. minetest.chat_send_player("MustTest", "# Server: String contains cursing!")
  11. end
  12. return false
  13. else
  14. if noreport == false then
  15. minetest.chat_send_player("MustTest", "# Server: String confirmed SJW-safe!")
  16. end
  17. end
  18. return true
  19. end
  20. function anticurse.dump_files()
  21. minetest.chat_send_player("MustTest", "# Server: Starting processing ...")
  22. local lines1, err1 = io.open(minetest.get_worldpath() .. "/ac_dump_bad.txt", "w")
  23. if err1 then return end
  24. local lines2, err2 = io.open(minetest.get_worldpath() .. "/ac_dump_good.txt", "w")
  25. if err2 then lines1:close() return end
  26. local lines3, err3 = io.open(minetest.get_worldpath() .. "/cursing.txt", "r")
  27. if err3 then lines1:close() lines2:close() return end
  28. local input = lines3:read("*all")
  29. if type(input) == "string" then
  30. local rows = string.split(input, "\n")
  31. for k, v in ipairs(rows) do
  32. local s = v:sub(v:find(">") + 1)
  33. local result = anticurse.test(s, true)
  34. if result then
  35. lines2:write(v .. "\n")
  36. else
  37. lines1:write(v .. "\n")
  38. end
  39. end
  40. end
  41. lines1:write("\n* * * DONE * * *\n")
  42. lines2:write("\n* * * DONE * * *\n")
  43. lines1:close()
  44. lines2:close()
  45. lines3:close()
  46. minetest.chat_send_player("MustTest", "# Server: Finished processing!")
  47. end
  48. -- Public API function.
  49. anticurse.check = function(name, string, type)
  50. -- Always check player chat, even if they anticurse privs.
  51. -- This way I can see what players *would have* been kicked for,
  52. -- even if they weren't kicked (priv checking is done in the kick
  53. -- function). This helps improve the anticurse mod.
  54. if type == "foul" then
  55. return anticurse.check_string(anticurse.foul, string)
  56. elseif type == "curse" then
  57. return anticurse.check_string(anticurse.curse, string)
  58. elseif type == "impersonate" then
  59. return anticurse.check_string(anticurse.impersonate, string)
  60. elseif type == "other" then
  61. return anticurse.check_string(anticurse.other, string)
  62. end
  63. return false -- Nothing strange found.
  64. end
  65. -- Public API function.
  66. anticurse.log = function(name, msg)
  67. if anticurse.logfile then
  68. anticurse.logfile:write("[" .. os.date("%Y-%m-%d, %H:%M:%S") .. "] <" .. name .. "> " .. msg .. "\r\n")
  69. anticurse.logfile:flush()
  70. end
  71. end
  72. -- Public API function.
  73. anticurse.kick = function(name, reason)
  74. local dname = rename.gpn(name)
  75. if reason == "foul" then
  76. local ext = anticurse.get_kick_message("foul")
  77. minetest.chat_send_all("# Server: <" .. dname .. ">, eeew, really? " .. ext)
  78. spam.block_playerjoin(name, 30)
  79. minetest.kick_player(name, ext)
  80. elseif reason == "curse" then
  81. local ext = anticurse.get_kick_message("curse")
  82. minetest.chat_send_all("# Server: Player <" .. dname .. "> cursed. " .. ext)
  83. spam.block_playerjoin(name, 30)
  84. minetest.kick_player(name, ext)
  85. end
  86. end
  87. -- Also used to check if a rename is valid (see rename mod).
  88. -- Return a string, to prevent player from connecting (with string as message).
  89. -- Or return nil to allow them to connect.
  90. local singleplayer = minetest.is_singleplayer()
  91. anticurse.on_prejoinplayer = function(name)
  92. if singleplayer then
  93. return
  94. end
  95. if minetest.check_player_privs(name, {anticurse_bypass=true}) or gdac.player_is_admin(name) then
  96. return
  97. end
  98. --[[if banned_names.guest_name(name) then
  99. --return "Guest names are forbidden, sorry!"
  100. -- This code has moved to the welcome message mod.
  101. --minetest.after(10, function() minetest.chat_send_player(name, "# Server: WARNING! You have logged in using a \"guest name\". Please be aware that such accounts are subject to deletion WITHOUT WARNING. You are still free to explore the server, though! If you want to play permanently, log in under another (non-guest) name and register the account by crafting and keeping a Proof of Citizenship item.") end)
  102. return
  103. else--]]if anticurse.check_string(anticurse.foul, name) then
  104. return "Eeeew, really? Pick a different username!"
  105. elseif anticurse.check_string(anticurse.curse, name) then
  106. return "Cursing. :-/ Remove the curse, please, and try again."
  107. elseif anticurse.check_string(anticurse.other, name) then
  108. return "That name is forbidden. Please pick something else."
  109. elseif banned_names.all_numeric(name) then
  110. return "All-numeric names are forbidden, sorry!"
  111. elseif banned_names.reserved_name(name) then
  112. return "That name is reserved by the server!"
  113. elseif anticurse.check_string(anticurse.impersonate, name) then
  114. return "That name is too similar to someone else!"
  115. end
  116. -- We are in maintenance mode.
  117. --if name ~= "MustTest" then
  118. -- return "The server is currently down for extended maintenance. It will be back up in a few hours."
  119. --end
  120. end