Jump to content

Login panel


Captain Cody

Recommended Posts

I've began work on new server and already ran into a small issue

When using login panel I have made it creates the account but ignores already created accounts, and using the login panel account it ignores the acl.

-- Using login panel // Account successfully created, and I can login through login panel

User: Codyj Everything I put in ACL is ignored

Pass: //////

-- Using chat // No account of this name exists, when using register it adds new account yet ignores old one.

User: Codyj still am able to login to other one with login panel yet not though chat

Pass: //////

logIn(source, account, password) 

///// Login panel stuff

addAccount(username,password) 

/login name password 

//// Chat stuff

Link to comment

Server side code is using source from another login panel that works perfectly, using it for GUI testing

  
  
function PlayerLogin(username,password,checksave) 
    if not (username == "") then 
        if not (password == "") then 
            local account = getAccount ( username, password ) 
            if ( account ~= false ) then 
                logIn(source, account, password) 
  
                triggerClientEvent (source,"hideLoginWindow",getRootElement()) 
                 
                    if checksave == true then 
                        triggerClientEvent(source,"saveLoginToXML",getRootElement(),username,password) 
                    else 
                        triggerClientEvent(source,"resetSaveXML",getRootElement(),username,password) 
                    end 
                 
            else 
                triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Wrong username and/or password") 
            end 
        else 
            triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Please enter your password!") 
        end 
    else 
        triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Please enter your username!") 
    end 
end 
addEvent("onRequestLogin",true) 
addEventHandler("onRequestLogin",getRootElement(),PlayerLogin) 
  
  
  
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 
                            outputChatBox ("#00FF00Sikeresen regisztráltál! [username: #FFFFFF" .. username .. " #00FF00| Password: #FFFFFF" .. password .. "#00FF00 ]",source,255,255,255,true ) 
                            outputChatBox ("#FF0000- HBT - Login Panel By.: John_Scott",source,255,255,255,true ) 
                        else 
                            triggerClientEvent(source,"set_warning_text",getRootElement(),"Register","Error! Please try again with new username or password!") 
                        end 
                    else 
                        triggerClientEvent(source,"set_warning_text",getRootElement(),"Register","This username already taken!") 
                    end 
                else 
                    triggerClientEvent(source,"set_warning_text",getRootElement(),"Register","The passwords does not match!") 
                end 
            else 
                triggerClientEvent(source,"set_warning_text",getRootElement(),"Register","Please confirm your password!") 
            end 
        else 
            triggerClientEvent(source,"set_warning_text",getRootElement(),"Register","Please enter yout password!") 
        end 
    else 
        triggerClientEvent(source,"set_warning_text",getRootElement(),"Register","Please enter your username!") 
    end 
end 
addEvent("onRequestRegister",true) 
addEventHandler("onRequestRegister",getRootElement(),registerPlayer) 
  
  
  

Client side

MainWindow = {} 
  
function open_log_reg_pannel() 
if not(isElement(MainWindow)) then 
    end 
     
    local screenW, screenH = guiGetScreenSize() 
    MainWindow = guiCreateWindow((screenW - 454) / 2, (screenH - 224) / 2, 454, 224, "Heretrics RolePlay", false) 
    guiWindowSetSizable(MainWindow, false) 
  
    user = guiCreateMemo(33, 35, 196, 33, "", false, MainWindow) 
     
    userpassword = guiCreateMemo(33, 94, 196, 33, "", false, MainWindow) 
     
    email = guiCreateMemo(33, 151, 149, 31, "", false, MainWindow) 
     
    checkbox_save = guiCreateCheckBox(198, 160, 15, 12, "", false, false, MainWindow) 
     
    usernamel = guiCreateLabel(43, 67, 170, 23, "User Name", false, MainWindow) 
     
    passwordl = guiCreateLabel(43, 128, 170, 23, "Password", false, MainWindow) 
     
    emaill = guiCreateLabel(43, 182, 170, 23, "Email, not required", false, MainWindow) 
     
    savel = guiCreateLabel(188, 172, 170, 23, "Save?", false, MainWindow) 
     
    loginb = guiCreateButton(282, 40, 134, 40, "Login", false, MainWindow) 
    guiSetProperty(loginb, "NormalTextColour", "FFFEFEFE") 
     
    registerb = guiCreateButton(282, 94, 134, 40, "Register", false, MainWindow) 
    guiSetProperty(registerb, "NormalTextColour", "FFFFFFFF") 
     
    labelm = guiCreateLabel(23, -62, 421, 63, "Heretrics Role Play", false, MainWindow) 
    guiSetFont(labelm, "sa-gothic") 
    guiLabelSetColor(labelm, 0, 45, 15) 
     
    statel = guiCreateLabel(320, 200, 124, 32, "Pre-Alpha", false, MainWindow) 
    guiLabelSetColor(statel, 113, 0, 0)   
     
    guiSetVisible(MainWindow,true) 
    --guiSetInputEnabled(true) 
    showCursor(true) 
     
     
    -- Save/load functions 
    local usernamexml1, passwordxml1 = loadLoginFromXML() 
     
    if not( usernamexml1 == "" or passwordxml1 == "") then 
        guiCheckBoxSetSelected ( checkbox_save, true ) 
        guiSetText ( user, tostring(usernamexml1)) 
        guiSetText ( userpassword, tostring(passwordxml1)) 
    else 
        guiCheckBoxSetSelected ( checkbox_save, false ) 
        guiSetText ( user, tostring(usernamexml1)) 
        guiSetText ( userpassword, tostring(passwordxml1)) 
    end 
    addEventHandler("onClientGUIClick",loginb,onLoginClick) 
    addEventHandler("onClientGUIClick",registerb,OnRegisterClick) 
  
end 
  
function start_cl_resource() 
    open_log_reg_pannel() 
end 
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),start_cl_resource) 
  
------------------------------------------------------------------------------------------------------ 
-- Save functions 
function loadLoginFromXML()  
    local xml_save_log_File = xmlLoadFile ("files/xml/userdata.xml") 
    if not xml_save_log_File then 
        xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "login") 
    end 
    local usernameNode = xmlFindChild (xml_save_log_File, "username", 0) 
    local passwordNode = xmlFindChild (xml_save_log_File, "password", 0) 
    if usernameNode and passwordNode then 
        return xmlNodeGetValue(usernameNode), xmlNodeGetValue(passwordNode) 
    else 
        return "", "" 
    end 
    xmlUnloadFile ( xml_save_log_File ) 
end 
  
function saveLoginToXML(usernamexml, passwordxml)  
    local xml_save_log_File = xmlLoadFile ("files/xml/userdata.xml") 
    if not xml_save_log_File then 
        xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "login") 
    end 
    if (usernamexml ~= "") then 
        local usernameNode = xmlFindChild (xml_save_log_File, "username", 0) 
        if not usernameNode then 
            usernameNode = xmlCreateChild(xml_save_log_File, "username") 
        end 
        xmlNodeSetValue (usernameNode, tostring(usernamexml)) 
    end 
    if (passwordxml ~= "") then 
        local passwordNode = xmlFindChild (xml_save_log_File, "password", 0) 
        if not passwordNode then 
            passwordNode = xmlCreateChild(xml_save_log_File, "password") 
        end      
        xmlNodeSetValue (passwordNode, tostring(passwordxml)) 
    end 
    xmlSaveFile(xml_save_log_File) 
    xmlUnloadFile (xml_save_log_File) 
end 
addEvent("saveLoginToXML", true) 
addEventHandler("saveLoginToXML", getRootElement(), saveLoginToXML) 
  
function resetSaveXML() 
        local xml_save_log_File = xmlLoadFile ("files/xml/userdata.xml") 
        if not xml_save_log_File then 
            xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "login") 
        end 
        if (usernamexml ~= "") then 
            local usernameNode = xmlFindChild (xml_save_log_File, "username", 0) 
            if not usernameNode then 
                usernameNode = xmlCreateChild(xml_save_log_File, "username") 
            end 
        end 
        if (passwordxml ~= "") then 
            local passwordNode = xmlFindChild (xml_save_log_File, "password", 0) 
            if not passwordNode then 
                passwordNode = xmlCreateChild(xml_save_log_File, "password") 
            end      
            xmlNodeSetValue (passwordNode, "") 
        end 
        xmlSaveFile(xml_save_log_File) 
        xmlUnloadFile (xml_save_log_File) 
end 
addEvent("resetSaveXML", true) 
addEventHandler("resetSaveXML", getRootElement(), resetSaveXML) 
  
------------------------------------------------------------------------------------------------------ 
  
-- Login functions--------------------------------------------------- 
function onLoginClick(button,state) 
    if(button == "left" and state == "up") then 
        if (source == loginb) then 
            username1 = guiGetText(user) 
            password1 = guiGetText(userpassword) 
                if guiCheckBoxGetSelected ( checkbox_save ) == true then 
                    checksave1 = true 
                else 
                    checksave1 = false 
                end 
            triggerServerEvent("onRequestLogin",getLocalPlayer(),username1,password1,checksave1) 
        end 
    end 
end 
-- Register functions------------------------------------------------------------------------------------------------------ 
function OnRegisterClick(button,state) 
    if(button == "left" and state == "up") then 
        if (source == registerb) then 
            username2 = guiGetText(user) 
            password2 = guiGetText(userpassword) 
            passwordConfirm2 = guiGetText(userpassword) 
            triggerServerEvent("onRequestRegister",getLocalPlayer(),username2,password2,passwordConfirm2) 
        end 
    end 
end 
  
-- Error stuff--------------------------------------------------------------------------------------------------------- 
function Error_msg(Tab, Text) 
        guiSetText(email, tostring(Text)) 
end 
addEvent("set_warning_text",true) 
addEventHandler("set_warning_text",getRootElement(),Error_msg) 
  
-- Hide the window------------------------------------------------------------------------------------------------------ 
function hideLoginWindow() 
    guiSetInputEnabled(false) 
    removeEventHandler("onClientGUIClick",loginb,onLoginClick) 
    guiSetVisible(MainWindow, false) 
    destroyElement(MainWindow) 
    MainWindow = nil 
    showCursor(false) 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 
------------------------------------------------------------------------------------------------------ 
  
  
  
  

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...