init.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. auth2 = auth2 or {}
  2. auth2.modpath = minetest.get_modpath("auth2")
  3. if not auth2.run_once then
  4. -- Override this function before 'sauth' calls it.
  5. -- Sauth must depend on this mod for this to work.
  6. local old_auth_register = minetest.register_authentication_handler
  7. function minetest.register_authentication_handler(handler)
  8. local get_auth = handler.get_auth
  9. function handler.get_auth(name)
  10. return get_auth(rename.grn(name))
  11. end
  12. local create_auth = handler.create_auth
  13. function handler.create_auth(name, password)
  14. return create_auth(rename.grn(name), password)
  15. end
  16. local delete_auth = handler.delete_auth
  17. function handler.delete_auth(name)
  18. return delete_auth(rename.grn(name))
  19. end
  20. local set_password = handler.set_password
  21. function handler.set_password(name, password)
  22. return set_password(rename.grn(name), password)
  23. end
  24. local set_privileges = handler.set_privileges
  25. function handler.set_privileges(name, privileges)
  26. return set_privileges(rename.grn(name), privileges)
  27. end
  28. local reload = handler.reload
  29. function handler.reload()
  30. return reload()
  31. end
  32. local record_login = handler.record_login
  33. function handler.record_login(name)
  34. -- Delay the login record so that we can get the previous login
  35. -- time from within another `on_playerjoin` handler.
  36. minetest.after(0.5, function() record_login(rename.grn(name)) end)
  37. end
  38. local name_search = handler.name_search
  39. function handler.name_search(name)
  40. return name_search(rename.grn(name))
  41. end
  42. -- Log activity.
  43. minetest.log("action", "Wrapped auth handler in live-rename functions!")
  44. -- Call the original engine function.
  45. return old_auth_register(handler)
  46. end
  47. -- Override some global functions, for completeness.
  48. local set_password = core.set_player_password
  49. function core.set_player_password(name, password)
  50. return set_password(rename.grn(name), password)
  51. end
  52. local set_privileges = core.set_player_privs
  53. function core.set_player_privs(name, privileges)
  54. return set_privileges(rename.grn(name), privileges)
  55. end
  56. local c = "auth2:core"
  57. local f = auth2.modpath .. "/init.lua"
  58. reload.register_file(c, f, false)
  59. auth2.run_once = true
  60. end