Jump to content

Login Panel by NeXtreme


Recommended Posts

Server----

-- Login handling 
function loginPlayer(username,password,enableKickPlayer,attemptedLogins,maxLoginAttempts) 
    if not (username == "") then 
        if not (password == "") then 
            local account = getAccount ( username, password ) 
            if ( account ~= false ) then 
                logIn (source, account, password) 
                outputChatBox ("#0000FF* #FFFFFFYou have sucessfully logged in!",source,255,255,255,true) 
                setTimer(outputChatBox,700,1,"#0000FF* #FFFFFFTo enable auto-login, use #ABCDEF/enableauto#FFFFFF!",source,255,255,255,true) 
                triggerClientEvent (source,"hideLoginWindow",getRootElement()) 
            else 
                if enableKickPlayer == true then 
                    if (attemptedLogins >= maxLoginAttempts-1) then 
                        outputChatBox ("#0000FF* #FFFFFFError! Wrong username and/or password!",source,255,255,255,true) 
                        setTimer(outputChatBox,500,1,"#0000FF* #FFFFFFWarning! Maximum login attempts reached! [#008AFF"..attemptedLogins+1 .."/"..maxLoginAttempts.."#FFFFFF]",source,255,255,255,true) 
                        setTimer(outputChatBox,1000,1,"#0000FF* #FFFFFFYou will be kicked in #008AFF5 seconds#FFFFFF!",source,255,255,255,true) 
                        setTimer(kickPlayer,5000,1,source,"Failed to login") 
                    else 
                        outputChatBox ("#0000FF* #FFFFFFError! Wrong username and/or password!",source,255,255,255,true) 
                        setTimer(outputChatBox,500,1,"#0000FF* #FFFFFFLogin attempts: [#008AFF"..attemptedLogins+1 .."/"..maxLoginAttempts.."#FFFFFF]",source,255,255,255,true) 
                        triggerClientEvent(source,"onRequestIncreaseAttempts",source) 
                    end 
                else 
                    outputChatBox ("#0000FF* #FFFFFFError! Wrong username and/or password!",source,255,255,255,true) 
                end 
            end 
        else 
            outputChatBox ("#0000FF* #FFFFFFError! Please enter your password!",source,255,255,255,true) 
        end 
    else 
        outputChatBox ("#0000FF* #FFFFFFError! Please enter your username!",source,255,255,255,true) 
    end 
end 
  
  
  
-- Registration here 
function registerPlayer(username,password,passwordConfirm) 
    if not (username == "") then 
        if not (password == "") then 
            if not (passwordConfirm == "") then 
                if password == passwordConfirm then 
                    local account = getAccount (username,password) 
                    if (account == false) then 
                        local accountAdded = addAccount(tostring(username),tostring(password)) 
                        if (accountAdded) then 
                            triggerClientEvent(source,"hideRegisterWindow",getRootElement()) 
                            outputChatBox ("#0000FF* #FFFFFFYou have sucessfuly registered! [username: #ABCDEF" .. username .. " #FF0000| #FFFFFFPassword: #ABCDEF" .. password .. "#FFFFFF]",source,255,255,255,true ) 
                            setTimer(outputChatBox,800,1,"#0000FF* #FFFFFFYou can now login with your new account.",source,255,255,255,true ) 
                        else 
                            outputChatBox ("#0000FF* #FFFFFFAn unknown error has occured! Please choose a different username/password and try again.",source,255,255,255,true ) 
                        end 
                    else 
                        outputChatBox ("#0000FF* #FFFFFFError! An account with this username already exists!",source,255,255,255,true ) 
                    end 
                else 
                    outputChatBox ("#0000FF* #FFFFFFError! Passwords do not match!",source,255,255,255,true) 
                end 
            else 
                outputChatBox ("#0000FF* #FFFFFFError! Please confirm your password!",source,255,255,255,true) 
            end 
        else 
            outputChatBox ("#0000FF* #FFFFFFError! Please enter a password!",source,255,255,255,true) 
        end 
    else 
        outputChatBox ("#0000FF* #FFFFFFError! Please enter a username you would like to register with!",source,255,255,255,true) 
    end 
end 
  
  
  
-- Auto-login handling 
function autologinPlayer(username,password) 
    if not (username == "") then 
        if not (password == "") then 
            local account = getAccount ( username, password ) 
            if not (account == false) then 
                logIn (source, account, password) 
                outputChatBox("#0000FF* #FFFFFFYou have been automatically logged in.",source,255,255,255,true) 
                setTimer(outputChatBox,1000,1,"#0000FF* #FFFFFFTo disable auto-login, use #ABCDEF/disableauto.",source,255,255,255,true) 
                triggerClientEvent ( source, "hideLoginWindow", getRootElement()) 
            else 
                outputChatBox ("#FF0000* #FFFFFFAuto-login error - Username & password do not match",source,255,255,255,true) 
            end 
        else 
            outputChatBox ("#FF0000* #FFFFFFAuto-login error - Failed to retrieve password",source,255,255,255,true) 
        end 
    else 
        outputChatBox ("#FF0000* #FFFFFFAuto-login error - Failed to retrieve username",source,255,255,255,true) 
    end 
end 
  
  
  
-- When the player logs out, trigger the client event to check if the login panel will request them to login again 
function logoutHandler() 
    triggerClientEvent(source,"onRequestDisplayPanel",source) 
end 
addEventHandler("onPlayerLogout",getRootElement(),logoutHandler) 
  
  
  
  
-- Get the server's name 
function getData() 
    local sName = md5(getServerName()) 
    local sName = string.sub(sName,0,15) 
    triggerClientEvent(source,"onGetServerData",getRootElement(),sName) 
end 
  
  
  
  
addEvent("onRequestLogin",true) 
addEvent("onRequestRegister",true) 
addEvent("onRequestAutologin",true) 
addEvent("onClientLoginLoaded",true) 
addEventHandler("onRequestLogin",getRootElement(),loginPlayer) 
addEventHandler("onRequestRegister",getRootElement(),registerPlayer) 
addEventHandler("onRequestAutologin",getRootElement(),autologinPlayer) 
addEventHandler("onClientLoginLoaded",getRootElement(),getData) 
  
  

Client---

  
----------------------------------
-----------| Settings |-----------
----------------------------------
 
blackLoginScreen = true         -- Set to 'true' to display a black screen to the player untill they log in or choose to play as a guest.
 
enableKickPlayer = true         -- Set whether to kick the player after they fail to login specified amount of times.
 
disallowLogout = false          -- Set whether to show the userpanel to the players if they log out of their accounts.
 
removeBlackScreenTime = 4       -- The time it takes for the black screen to dissapear - If you choose to display the black screen. [iN SECONDS]
 
maxLoginAttempts = 5            -- Set the maximum incorrect login attempts before the player gets kicked - If player kicking is enabled.
 
----------------------------------
 
 
 
-- Set the text you want displayed in the "rules" window here - use '\n' to go into the next line
infoText = "------ Rules ------ \n\n* No cheating!\n* No insulting and spamming!\n* No vehicle mods\n\nEdit the text however you like\n\n\n\n\n\n\n\nLogin panel by NeXTreme"
 
 
 
-- Screen and GUI window sizes
screenWidth,screenHeight = guiGetScreenSize()
mainWidth,mainHeight = 749,472
regWidth,regHeight = 439,344
 
 
-- Generate the XML file name
function getServerName()
    triggerServerEvent("onClientLoginLoaded",getLocalPlayer())
end
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),getServerName)
 
function setXmlFileName(sName)
    xmlFileName = tostring("login_"..sName..".xml")
    loginPanel()
end
addEvent("onGetServerData",true)
addEventHandler("onGetServerData",getRootElement(),setXmlFileName)
 
 
 
 
 
----------------------------------
 
addEvent("onRequestIncreaseAttempts",true)
addEvent("onRequestDisplayPanel",true)
 
function loginPanel()
        -- Check if autologin is enabled - If yes, then log the player in, else create and show the userpanel
        local xmlFile = xmlLoadFile(xmlFileName)
        if xmlFile then
            status = xmlNodeGetAttribute(xmlFile,"autologin")
            if (status == "true") then
                local username = tostring(xmlNodeGetAttribute(xmlFile,"username"))
                local password = tostring(xmlNodeGetAttribute(xmlFile,"password"))
                if not (username == "") and not (password == "") then
                    triggerServerEvent("onRequestAutologin",getLocalPlayer(),username,password)
                end
            else
                if blackLoginScreen == true then
                    fadeCamera(false,0,0,0,0)
                end
                mainWindow = guiCreateWindow(screenWidth/2-mainWidth/2,screenHeight/2-mainHeight/2,mainWidth,mainHeight,"Login panel",false)
                guiWindowSetSizable(mainWindow,false)
 
                mInfo = guiCreateMemo(21,36,411,278,infoText,false,mainWindow)
                guiMemoSetReadOnly(mInfo,true)
 
                editUsername = guiCreateEdit(53,364,187,25,"",false,mainWindow)
                guiEditSetMaxLength(editUsername,30)
 
                editPassword = guiCreateEdit(53,421,187,25,"",false,mainWindow)
                guiEditSetMaxLength(editPassword,30)
                guiEditSetMasked(editPassword,true)
 
                lblUsername = guiCreateLabel(67,330,158,38,"Username:",false,mainWindow)
                guiLabelSetColor(lblUsername,0,85,255)
                guiLabelSetVerticalAlign(lblUsername,"center")
                guiLabelSetHorizontalAlign(lblUsername,"center",false)
                guiSetFont(lblUsername,"default-bold-small")
 
                lblPassword = guiCreateLabel(67,389,158,38,"Password:",false,mainWindow)
                guiLabelSetColor(lblPassword,0,85,255)
                guiLabelSetVerticalAlign(lblPassword,"center")
                guiLabelSetHorizontalAlign(lblPassword,"center",false)
                guiSetFont(lblPassword,"default-bold-small")
 
                btnPlayAsGuest = guiCreateButton(548,368,168,74,"Play as guest",false,mainWindow)
                guiSetFont(btnPlayAsGuest,"default-bold-small")
 
                btnLogin = guiCreateButton(280,368,242,74,"Login",false,mainWindow)
                guiSetFont(btnLogin,"sa-header")
 
                btnToggleRegister = guiCreateButton(490,246,206,68,"Register an account",false,mainWindow)
                guiSetFont(btnToggleRegister,"default-bold-small")
 
                registerWindow = guiCreateWindow(screenWidth/2-regWidth/2,screenHeight/2-regHeight/2,regWidth,regHeight,"Registration",false)
                guiWindowSetSizable(registerWindow,false)
 
                editRegistrationUsername = guiCreateEdit(98,138,242,25,"",false,registerWindow)
 
                editRegistrationPassword = guiCreateEdit(98,195,242,25,"",false,registerWindow)
                guiEditSetMasked(editRegistrationPassword,true)
 
                editRegistrationRepeatPassword = guiCreateEdit(99,252,242,25,"",false,registerWindow)
                guiEditSetMasked(editRegistrationRepeatPassword,true)
 
                lblRegister = guiCreateLabel(24,24,391,97,"Register",false,registerWindow)
                guiLabelSetColor(lblRegister,0,85,255)
                guiLabelSetVerticalAlign(lblRegister,"center")
                guiLabelSetHorizontalAlign(lblRegister,"center",false)
                guiSetFont(lblRegister,"sa-gothic")
 
                lblRUsername = guiCreateLabel(98,113,242,17,"Username:",false,registerWindow)
                guiLabelSetColor(lblRUsername,0,85,255)
                guiLabelSetVerticalAlign(lblRUsername,"center")
                guiLabelSetHorizontalAlign(lblRUsername,"center",false)
                guiSetFont(lblRUsername,"default-bold-small")
 
                lblRPassword = guiCreateLabel(98,171,242,17,"Password:",false,registerWindow)
                guiLabelSetColor(lblRPassword,0,85,255)
                guiLabelSetVerticalAlign(lblRPassword,"center")
                guiLabelSetHorizontalAlign(lblRPassword,"center",false)
                guiSetFont(lblRPassword,"default-bold-small")
 
                lblRepeatPassword = guiCreateLabel(98,230,242,17,"Repeat password:",false,registerWindow)
                guiLabelSetColor(lblRepeatPassword,0,85,255)
                guiLabelSetVerticalAlign(lblRepeatPassword,"center")
                guiLabelSetHorizontalAlign(lblRepeatPassword,"center",false)
                guiSetFont(lblRepeatPassword,"default-bold-small")
 
                btnCancel = guiCreateButton(232,292,179,38,"Cancel",false,registerWindow)
                guiSetFont(btnCancel,"default-bold-small")
 
                btnConfirmRegistration = guiCreateButton(29,292,179,38,"Confirm & register!",false,registerWindow)
                guiSetFont(btnConfirmRegistration,"default-bold-small")
 
                guiCreateStaticImage(440,23,300,225,"logo.png",false,mainWindow)
 
                guiSetVisible(mainWindow, true)
                guiSetVisible(registerWindow, false)
                guiSetInputEnabled(true)
                showCursor(true)
                addEventHandler("onClientGUIClick",btnLogin,onClickLogin)
                addEventHandler("onClientGUIClick",btnToggleRegister,onClickRegisterToggle)
                addEventHandler("onClientGUIClick",btnPlayAsGuest,onClickGuest)
                addEventHandler("onClientGUIClick",btnConfirmRegistration,onClickRegisterConfirm)
                addEventHandler("onClientGUIClick",btnCancel,onClickCancel)
                addEventHandler("onRequestIncreaseAttempts",getRootElement(),increaseAttempts)
                attemptedLogins = 0
            end
            xmlUnloadFile(xmlFile)
        else
            xmlFileHandler(true)
        end
        addEventHandler("onRequestDisplayPanel",getRootElement(),logoutHandler)
end
--addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),loginPanel)
 
 
 
-- Disable autologin
function removeAutoLogin()
    local xmlFile = xmlLoadFile(xmlFileName)
    if xmlFile then
        local status = xmlNodeGetAttribute(xmlFile,"autologin")
        if status == "true" then
            xmlNodeSetAttribute(xmlFile,"autologin","false")
            outputChatBox("#0000FF* #FFFFFFAuto-login is now #FF0000DISABLED#FFFFFF!",255,255,255,true)
            xmlSaveFile(xmlFile)
            xmlUnloadFile(xmlFile)
        else
            outputChatBox("#0000FF* #FFFFFFAuto-login is already #FF0000DISABLED#FFFFFF!",255,255,255,true)
            xmlUnloadFile(xmlFile)
        end
    end
end
addCommandHandler("disableauto", removeAutoLogin)
 
 
 
-- Enable autologin
function addAutoLogin()
    local xmlFile = xmlLoadFile(xmlFileName)
    if xmlFile then
        local status  = xmlNodeGetAttribute(xmlFile,"autologin")
        if status == "false" then
            xmlNodeSetAttribute(xmlFile,"autologin","true")
            outputChatBox("#0000FF* #FFFFFFAuto-login is now #00FF00ENABLED#FFFFFF! You will be automatically logged in every time you join the server.",255,255,255,true)
            setTimer(outputChatBox,1000,1,"#0000FF* #FFFFFFTo #FF0000DISABLE#FFFFFF auto-login, use #ABCDEF/disableauto#FFFFFF!",255,255,255,true)
            xmlSaveFile(xmlFile)
            xmlUnloadFile(xmlFile)
        else
            outputChatBox("#0000FF* #FFFFFFAuto-login is already #00FF00ENABLED#FFFFFF!",255,255,255,true)
            xmlUnloadFile(xmlFile)
        end
    end
end
addCommandHandler("enableauto", addAutoLogin)
 
 
 
-- LOGIN PLAYER
function onClickLogin(button,state)
    if(button == "left" and state == "up") then
        if (source == btnLogin) then
            username = guiGetText(editUsername)
            password = guiGetText(editPassword)
            triggerServerEvent("onRequestLogin",getLocalPlayer(),username,password,enableKickPlayer,attemptedLogins,maxLoginAttempts)
            xmlFileHandler()
        end
    end
end
 
 
 
-- REGISTER PLAYER
function onClickRegisterConfirm(button,state)
    if(button == "left" and state == "up") then
        if (source == btnConfirmRegistration) then
            username = guiGetText(editRegistrationUsername)
            password = guiGetText(editRegistrationPassword)
            passwordConfirm = guiGetText(editRegistrationRepeatPassword)
            triggerServerEvent("onRequestRegister",getLocalPlayer(),username,password,passwordConfirm)
        end
    end
end
 
 
 
-- Open registration window
function onClickRegisterToggle(button,state)
    if(button == "left" and state == "up") then
        if (source == btnToggleRegister) then
            guiSetVisible(registerWindow, true)
            guiBringToFront(registerWindow)
            guiSetInputEnabled(true)
            showCursor(true)
        end
    end
end
 
 
 
-- Cancel registration
function onClickCancel(button,state)
   
Link to comment

If you didn't understand what the don said,i will try to be clear with you,

To give the accountaccess you've to add your script name (filename) to Acl.xml ,so where exactly? thats what i will show you

Open your your ACL.xml and add the line under the admin section:

"resource.fillename"> 

Or you can do it in game if you want, go to your ACL on the admin panel and add object to the admin section and call it resource.fillename

Link to comment

Of course I did understand that, I know can be used when its a zip file a located at resources. But I extracted the client & server lua scripts which are located on this ==server > mods > deathmatch > resources > RPG (meta.xml located here) > LoginSystem (client & server scripts here). There, what im just trying to say is how can i add the accountaccess If its not located on the resources file.

But thanks anyway for your comments :)

Its just that I want all the scripts on my Folder so that i`ll just start all scripts with just 1 command. /start RPG

But I now used the resource.login_panel :)

Link to comment
Of course I did understand that, I know can be used when its a zip file a located at resources. But I extracted the client & server lua scripts which are located on this ==server > mods > deathmatch > resources > RPG (meta.xml located here) > LoginSystem (client & server scripts here). There, what im just trying to say is how can i add the accountaccess If its not located on the resources file.

But thanks anyway for your comments :)

Its just that I want all the scripts on my Folder so that i`ll just start all scripts with just 1 command. /start RPG

But I now used the resource.login_panel :)

resource.RPG 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...