init empty files if there's no one present
* provide a way to initialize files if there is not one currently doe snot touch the auth.txt file neither converted * solves: close: https://codeberg.org/minenux/minetest-mod-auth_rx/issues/6 * solved: close: https://bitbucket.org/sorcerykid/auth_rx/issues/7 * init the files when are fresh install, still do not convert from auth.txt
This commit is contained in:
parent
8b82b4b58f
commit
6f500a53d8
34
db.lua
34
db.lua
@ -411,3 +411,37 @@ function AuthDatabase( path, name )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
----------------------------
|
||||
-- AuthInitFile Class
|
||||
----------------------------
|
||||
|
||||
function AuthInitFile( path, name)
|
||||
|
||||
local file, err = io.open( path .. "/" .. name, "r+b" )
|
||||
|
||||
-- init empty files if not present
|
||||
if file then
|
||||
file:close( )
|
||||
return
|
||||
end
|
||||
file = io.open( path .. "/" .. name, "w+")
|
||||
if not file then
|
||||
minetest.log( "error", "Cannot init file " .. path .. "/" .. name .. " for writing." )
|
||||
error( "Fatal exception in InitFiles( ), aborting." )
|
||||
end
|
||||
if name == "auth.db" then
|
||||
file:write("auth_rx/2.1 @0")
|
||||
AuthInitFile( path, name .. "x")
|
||||
end
|
||||
file:write("")
|
||||
file:close( )
|
||||
|
||||
-- convert present txt file if present or autentications, after convert, change extension to auth.txt.converted
|
||||
-- TODO: made a conversion in lua line by line, after rename , delete it
|
||||
|
||||
-- provide a way to rollback to a txt file if there already a auth db file, to stay in sync
|
||||
-- TODO way to get sync with txt file
|
||||
|
||||
end
|
||||
|
@ -485,7 +485,13 @@ function AuthFilter( path, name, debug )
|
||||
self.refresh = function ( )
|
||||
local file = io.open( path .. "/" .. name, "r" )
|
||||
if not file then
|
||||
error( "The specified ruleset file does not exist." )
|
||||
file = io.open( path .. "/" .. name, "w+")
|
||||
file:write("pass now")
|
||||
if not file then
|
||||
error( "The specified ruleset file does not exist." )
|
||||
end
|
||||
file:close( file )
|
||||
file = io.open( path .. "/" .. name, "r" )
|
||||
end
|
||||
src = { }
|
||||
for line in file:lines( ) do
|
||||
|
7
init.lua
7
init.lua
@ -6,7 +6,8 @@
|
||||
--------------------------------------------------------
|
||||
|
||||
local world_path = minetest.get_worldpath( )
|
||||
local mod_path = minetest.get_modpath( "auth_rx" )
|
||||
local mod_name = minetest.get_current_modname() or "auth_rx"
|
||||
local mod_path = minetest.get_modpath( mod_name )
|
||||
|
||||
dofile( mod_path .. "/helpers.lua" )
|
||||
dofile( mod_path .. "/filter.lua" )
|
||||
@ -14,10 +15,12 @@ dofile( mod_path .. "/db.lua" )
|
||||
dofile( mod_path .. "/watchdog.lua" )
|
||||
local __commands = dofile( mod_path .. "/commands.lua" )
|
||||
|
||||
AuthInitFile( world_path, "auth.db" )
|
||||
AuthInitFile( world_path, "greenlist.mt" )
|
||||
|
||||
-----------------------------------------------------
|
||||
-- Registered Authentication Handler
|
||||
-----------------------------------------------------
|
||||
|
||||
local auth_filter = AuthFilter( world_path, "greenlist.mt" )
|
||||
local auth_db = AuthDatabase( world_path, "auth.db" )
|
||||
local auth_watchdog = AuthWatchdog( )
|
||||
|
Loading…
x
Reference in New Issue
Block a user