Jump to content

[HELP] Register


LabiVila

Recommended Posts

Hello;

The server-side

function loginHandler (username, password) 
    if username == "LabiVila" and password == "LabinoTVilA" then 
        if ( client ) then 
            outputChatBox ("You have successfully logged in.", client, 255, 255, 255) 
        end 
    else 
        outputChatBox ("Wrong username or password, please re-connect.", client, 255, 255, 255) 
        end 
end 
addEvent ("submitLogin", true) 
addEventHandler ("submitLogin", root, loginHandler) 
  
function createFileHandler () 
    local RootNode = xmlCreateFile("accounts.xml", "accounts") 
    local NewNode = xmlCreateChild(RootNode, "informations") 
    xmlSaveFile (RootNode) 
end 
addEvent ("submitRegister", true) 
addEventHandler ("submitRegister", root, createFileHandler) 

the client-side

function createLoginWindow() 
    loginwindow = guiCreateWindow (0.25, 0.25, 0.4, 0.4, "Login Window", true) 
  
    guiCreateLabel (0.10, 0.15, 0.90, 0.90, "Username: ", true, loginwindow) 
    guiCreateLabel (0.10, 0.35, 0.90, 0.90, "Password: ", true, loginwindow) 
     
    usernameEdit = guiCreateEdit (0.30, 0.12, 0.50, 0.13, "", true, loginwindow) 
    passwordEdit = guiCreateEdit (0.30, 0.32, 0.50, 0.13, "", true, loginwindow) 
    guiEditSetMaxLength (usernameEdit, 22) 
    guiEditSetMaxLength (passwordEdit, 22) 
    guiEditSetMasked (usernameEdit, false) 
    guiEditSetMasked (passwordEdit, true) 
    --remembermeBox = guiCreateCheckBox (0.29, 0.50, 0.35, 0.10, "Remember me", true, true, loginwindow) 
    playasguestButton = guiCreateButton (0.60, 0.50, 0.40, 0.20, "Play As Guest", true, loginwindow) 
    registerButton = guiCreateButton (0.00, 0.50, 0.40, 0.20, "Register", true, loginwindow) 
    loginButton = guiCreateButton (0.00, 0.75, 1.00, 0.20, "Login", true, loginwindow) 
     
    guiWindowSetSizable (loginwindow, false) 
    guiWindowSetMovable (loginwindow, false) 
    guiSetVisible(loginwindow, false) 
    guiSetInputEnabled ( true ) 
    addEventHandler ("onClientGUIClick", playasguestButton, clientSubmitPlayAsGuest, false) 
    addEventHandler ("onClientGUIClick", registerButton, clientSubmitRegister, false) 
    addEventHandler ("onClientGUIClick", loginButton, clientSubmitLogin, false) 
end  
  
addEventHandler ("onClientResourceStart", getResourceRootElement (getThisResource()), 
    function () 
        createLoginWindow() 
            if (loginwindow ~= nil) then 
            guiSetVisible (loginwindow, true) 
            showCursor ( true ) 
            showChat ( true ) 
            guiSetInputEnabled ( true ) 
        else 
            outputChatBox ("An unexpected errer has occurred, and the window is not created.", 255, 255, 255) 
            end 
    end 
) 
  
function clientSubmitLogin (button, state) 
    if button == "left" and state == "up" then 
        local username = guiGetText (usernameEdit) 
        local password = guiGetText (passwordEdit) 
        if username and password then 
            triggerServerEvent ("submitLogin", getRootElement (), username, password) 
            guiSetInputEnabled ( false ) 
            guiSetVisible (loginwindow, false) 
            showCursor ( false ) 
            showChat ( true ) 
        end 
    end 
end 
  
function clientSubmitRegister (button, state) 
    if button == "left" and state == "up" then 
        local username = guiGetText (usernameEdit) 
        local password = guiGetText (passwordEdit) 
        if username and password then 
            triggerServerEvent ("submitRegister", getRootElement (), username, password) 
            guiSetInputEnabled ( false ) 
            guiSetVisible (loginwindow, true) 
            showCursor ( true ) 
            showChat ( true ) 
            outputChatBox ("You have been successfully registered.", 255, 255, 255) 
        else 
            outputChatBox ("Error occurred while trying to register, please re-connect.", 255, 255, 255) 
        end 
    end 
end  
  
function clientSubmitPlayAsGuest (button, state) 
    if button == "left" and state == "up" then 
        guiSetVisible (loginwindow, false) 
        showCursor ( false ) 
        showChat ( true ) 
        guiSetInputEnabled ( false ) 
        outputChatBox ("You are successfully playing as a guest, any statistic will be not saved.", 255, 255, 255) 
    else 
        outputChatBox ("An unexpected error has occurred, please reconnect.", 255, 255, 255) 
    end 
end 

Everything is working fine so far. But can you guys tell me how can I get the usernameEdit and passwordEdit from the client-side to server-side? I don't want to replace with the existing xml file (accounts.xml). I want to put it a child down to accounts.xml, informations.

This is the way I want to make a register-window. I would appreciate too if you would tell me an easier way to register.

(I am a newbie)

Edited by Guest
Link to comment

Yes, exactly that, but I don't know how to get the usernameEdit and passwordEdit text when you click Register. I tried every way I know (with the triggerClientEvent) but it didn't work.

If you know a better and easier way of making a register, could you please tell me? :/

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