diff --git a/mods/auth_rx/init.lua b/mods/auth_rx/init.lua index e4e9c8e..0de9252 100644 --- a/mods/auth_rx/init.lua +++ b/mods/auth_rx/init.lua @@ -24,7 +24,7 @@ local auth_filter = AuthFilter( world_path, "greenlist.mt" ) local auth_db = AuthDatabase( world_path, "auth.db" ) local auth_watchdog = AuthWatchdog( ) local is_50 = minetest.has_feature("object_use_texture_alpha") -local is_54 = minetest.has_feature("object_use_texture_alpha") +local is_54 = minetest.has_feature("direct_velocity_on_players") if is_50 then if minetest.register_on_auth_fail then @@ -128,15 +128,15 @@ end ) minetest.register_authentication_handler( { -- translate old auth hooks to new database backend get_auth = function( username ) + minetest.log( "verbose" , "[auth_rx] get_auth handler access to some resource for " .. username ) local rec = auth_db.select_record( username ) if rec then local assigned_privs = rec.assigned_privs if get_minetest_config( "name" ) == username then -- grant server operator all privileges - -- (TODO: implement as function that honors give_to_admin flag) assigned_privs = { } - for priv in pairs( core.registered_privileges ) do + for priv in pairs( minetest.registered_privileges ) do table.insert( assigned_privs, priv ) end end @@ -145,28 +145,52 @@ minetest.register_authentication_handler( { end end, create_auth = function( username, password ) - if auth_db.create_record( username, password ) then - auth_db.set_assigned_privs( username, get_default_privs( ) ) - minetest.log( "info", "Created player '" .. username .. "' in authentication database" ) + minetest.log( "verbose" , "[auth_rx] create_auth handler new user over server for " .. username ) + local rec = auth_db.create_record( username, password ) + if rec then + local assigned_privs = get_default_privs( ) + + if get_minetest_config( "name" ) == username then + -- grant server operator all privileges + assigned_privs = { } + for priv in pairs( minetest.registered_privileges ) do + table.insert( assigned_privs, priv ) + end + end + + auth_db.set_assigned_privs( username, assigned_privs ) end end, delete_auth = function( username ) - if auth_db.delete_record( username ) then - minetest.log( "info", "Deleted player '" .. username .. "' in authenatication database" ) + minetest.log( "verbose" , "[auth_rx] delete_auth handler for " .. username ) + -- server operator's privileges are immutable + if get_minetest_config( "name" ) ~= username then + local rec = auth_db.delete_record( username ) + if rec then + minetest.log( "info", "Deleted player '" .. username .. "' in authenatication database" ) + end end end, set_password = function ( username, password ) - if auth_db.set_password( username, password ) then + minetest.log( "verbose" , "[auth_rx] set_password handler for " .. username ) + local rec = auth_db.set_password( username, password ) + if rec then minetest.log( "info", "Reset password of player '" .. username .. "' in authentication database" ) end end, set_privileges = function ( username, privileges ) + minetest.log( "verbose" , "[auth_rx] set_privileges handler grants for " .. username ) + local assigned_privs = pack_privileges( privileges ) -- server operator's privileges are immutable - if get_minetest_config( "name" ) == username then return end + if get_minetest_config( "name" ) == username then + assigned_privs = { } + for priv in pairs( minetest.registered_privileges ) do + table.insert( assigned_privs, priv ) + end + end - if auth_db.set_assigned_privs( username, pack_privileges( privileges ) ) then + if auth_db.set_assigned_privs( username, assigned_privs ) then minetest.notify_authentication_modified( username ) - minetest.log( "info", "Reset privileges of player '" .. username .. "' in authentication database" ) end end, record_login = function ( ) end,