Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ADMIN_GROUP = "Admin"
- local MAX_PASSWORD_CHARS = 30
- local g_console = getElementsByType"console"[1]
- local g_inWizard,g_wizardCR,g_pattern,g_inputIgnore
- function aStartWizard ()
- --Check if they have any admins
- for i,object in ipairs(aclGroupListObjects ( aclGetGroup(ADMIN_GROUP) )) do
- if string.find(object,"user.") == 1 then
- return
- end
- end
- outputServerLog ( "-> It appears your server lacks any Administrators." )
- outputServerLog ( "-> An Administrator is required in order to manage a server. Please use the command 'adminwizard' to setup an admin." )
- end
- addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), aStartWizard);
- local function input(message)
- if message == "adminwizard" then return end
- if not g_pattern then return end
- -- outputServerLog ( " "..tostring(message) )
- if g_pattern(message) then
- g_wizardCR(false)
- return
- end
- g_wizardCR(message)
- -- outputServerLog ( "|"..tostring( coroutine.resume(g_wizardCR,message) ) )
- end
- local wizard = {}
- wizard[1] = function()
- outputServerLog ( "-> Please enter the default USERNAME for the account. This may be any alphanumerical name." )
- g_pattern = function(msg) return string.find(msg,"%W") end
- local message = coroutine.yield()
- g_pattern = nil
- -- outputServerLog ( "message: "..tostring(message) )
- if not message then
- outputServerLog ( "-> The username was invalid." )
- g_wizardCR = coroutine.wrap(wizard[1])
- g_wizardCR()
- return
- end
- -- outputServerLog ( "-> Here "..tostring(wizard[2]) )
- wizard.username = message
- g_wizardCR = coroutine.wrap(wizard[2])
- g_wizardCR()
- end
- wizard[2] = function()
- outputServerLog ( "-> Please enter the default PASSWORD for the account. This may be up to "..MAX_PASSWORD_CHARS.." characters in length." )
- g_pattern = function(msg) return #msg > MAX_PASSWORD_CHARS end
- -- addEventHandler ( "onConsole", g_console, input )
- local message = coroutine.yield()
- g_pattern = nil
- -- removeEventHandler ( "onConsole", g_console, input )
- if not message then
- outputServerLog ( "-> The password was invalid." )
- g_wizardCR = coroutine.wrap(wizard[2])
- g_wizardCR()
- return
- end
- wizard.password = message
- g_wizardCR = coroutine.wrap(wizard[3])
- g_wizardCR()
- end
- wizard[3] = function()
- outputServerLog ( "-> You have chosen to create an admin account with username '"..wizard.username.."' and password '"..wizard.password.."'. Is this correct? (y/n)" )
- g_pattern = function(msg)
- if msg == "y" or msg == "yes" then
- return false
- end
- return true
- end
- local message = coroutine.yield()
- g_pattern = nil
- -- outputServerLog ( " -> debug " .. tostring(message) )
- if message then
- if addAccount ( wizard.username, wizard.password ) then
- outputServerLog ( "-> The admin account has been added successfully. Please use the 'login' command ingame to log in. Syntax: login <username> <password>" )
- g_wizardCR = coroutine.wrap(wizard[4])
- g_wizardCR()
- return
- -- now add the acl for it.
- -- local adminAclGroup = aclGetGroup(ADMIN_GROUP)
- -- aclGroupAddObject(adminAclGroup, "user." .. wizard.username)
- -- aclSave()
- -- aclReload()
- -- outputServerLog ( "-> Your account is directly added to the admin acl group." )
- -- outputServerLog ( "-> You can use this wizard again anytime by typing 'adminwizard' in the server console." )
- else
- outputServerLog ( "-> The account could not be created. It may exist already. Please type 'adminwizard' to run the wizard again." )
- end
- else
- outputServerLog ( "-> Please type 'adminwizard' to run the wizard again." )
- end
- -- Remove also the event handler for onConsole. Why, if we put adminwizard again, then we get an error. We don't want that.
- removeEventHandler ( "onConsole", g_console, input )
- g_wizardCR,g_inWizard = nil,nil
- end
- wizard[4] = function()
- outputServerLog ( "-> Do you want to make this account an admin account? (y for yes i will, n for no i don't)" )
- g_pattern = function(msg)
- if msg == "y" or msg == "yes" then
- return false
- end
- return true
- end
- local message = coroutine.yield()
- g_pattern = nil
- if message then
- local adminAclGroup = aclGetGroup(ADMIN_GROUP)
- aclGroupAddObject(adminAclGroup, "user." .. wizard.username)
- aclSave()
- aclReload()
- outputServerLog ( "-> The account is now an admin account!" )
- end
- outputServerLog ( "-> Please type 'adminwizard' to run the wizard again." )
- removeEventHandler ( "onConsole", g_console, input )
- g_wizardCR, g_inWizard = nil, nil
- end
- addCommandHandler ( "adminwizard",
- function(source)
- if source ~= g_console then return end
- if g_inWizard then
- outputServerLog ( "-> You are already in an admin wizard." )
- return
- end
- addEventHandler ( "onConsole", g_console, input )
- g_wizardCR = coroutine.wrap(wizard[1])
- g_wizardCR()
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement