api.lua 4.6 KB

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