Auth Redux is a drop-in replacement for the builtin authentication handler of Minetest.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

helpers.lua 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --------------------------------------------------------
  2. -- Minetest :: Auth Redux Mod v2.10 (auth_rx)
  3. --
  4. -- See README.txt for licensing and release notes.
  5. -- Copyright (c) 2017-2018, Leslie E. Krause
  6. --------------------------------------------------------
  7. -----------------------------------------------------
  8. -- Global Helper Functions
  9. -----------------------------------------------------
  10. get_minetest_config = core.setting_get -- backwards compatibility
  11. function convert_ipv4( str )
  12. local ref = string.split( str, ".", false )
  13. return tonumber( ref[ 1 ] ) * 16777216 + tonumber( ref[ 2 ] ) * 65536 + tonumber( ref[ 3 ] ) * 256 + tonumber( ref[ 4 ] )
  14. end
  15. function unpack_address( addr )
  16. return { math.floor( addr / 16777216 ), math.floor( ( addr % 16777216 ) / 65536 ), math.floor( ( addr % 65536 ) / 256 ), addr % 256 }
  17. end
  18. function get_default_privs( )
  19. local default_privs = { }
  20. for _, p in pairs( string.split( get_minetest_config( "default_privs" ), "," ) ) do
  21. table.insert( default_privs, string.trim( p ) )
  22. end
  23. return default_privs
  24. end
  25. function unpack_privileges( assigned_privs )
  26. local privileges = { }
  27. for _, p in ipairs( assigned_privs ) do
  28. privileges[ p ] = true
  29. end
  30. return privileges
  31. end
  32. function pack_privileges( privileges )
  33. local assigned_privs = { }
  34. for p, _ in pairs( privileges ) do
  35. table.insert( assigned_privs, p )
  36. end
  37. return assigned_privs
  38. end