Sande Posted May 17, 2014 Share Posted May 17, 2014 Hello, i´m trying to make a login system for my server. But because i am beginner on these login i can not complete it. I have been search many info from wiki and forums how to make the functions and the login function working already. Register functions works too but there is some little problems like you can register while you have empty boxes etc. I dont have any idea how to check that things and the code are so messed up. If someone can fix my code i will be happy. I can pay something for the fixer when i get money to my paypal. !But the "remember me" functions should work then. Server-side: function loginHandler(username,password) -- check that the username and password are correct local account = getAccount ( username, password ) if ( account ~= false ) then logIn(source, account, password) -- the player has successfully logged in, so spawn them if (client) then spawnPlayer(client, 1959.55, -1714.46, 10) fadeCamera(client, true) setCameraTarget(client, client) outputChatBox("Welcome to My Server.", client) end else -- if the username or password are not correct, output a message to the player outputChatBox("Invalid username and password. Please try again.",client) triggerClientEvent (source,"openLogin",getRootElement()) end end addEvent("submitLogin",true) addEventHandler("submitLogin",root,loginHandler) function register (username,password, passwordC) local account = getAccount (username,password) if (account == false) then local accountAdded = addAccount(tostring(username),tostring(password)) if (accountAdded) then outputChatBox ("#FF0000* #00FF00You have sucessfuly registered! [username: #FFFFFF" .. username .. " #00FF00| Password: #FFFFFF" .. password .. "#00FF00 ]",source,255,255,255,true ) logIn(source, account, password) if (client) then spawnPlayer(client, 1959.55, -1714.46, 10) fadeCamera(client, true) setCameraTarget(client, client) outputChatBox("Welcome to My Server.", client) else outputChatBox("Error while registering new account!", source, 255,0,0) triggerClientEvent (source,"openLogin",getRootElement()) end end end end addEvent("submitRegister",true) addEventHandler("submitRegister",root,register) Client-side --[[------------------------------------------------- Notes: > This code is using a relative image filepath. This will only work as long as the location it is from always exists, and the resource it is part of is running. To ensure it does not break, it is highly encouraged to move images into your local resource and reference them there. --]]------------------------------------------------- function createLoginWindow() Loginpanel = { tab = {}, staticimage = {}, tabpanel = {}, edit = {}, button = {}, window = {}, label = {}, checkbox = {} } Loginpanel.window[1] = guiCreateWindow(681, 346, 542, 428, "Suomisisu", false) guiWindowSetSizable(Loginpanel.window[1], false) Loginpanel.tabpanel[1] = guiCreateTabPanel(9, 20, 523, 398, false, Loginpanel.window[1]) Loginpanel.tab[1] = guiCreateTab("Login", Loginpanel.tabpanel[1]) Loginpanel.staticimage[1] = guiCreateStaticImage(10, 5, 503, 90, ":lol/logo.png", false, Loginpanel.tab[1]) edtUser = guiCreateEdit(190, 155, 161, 24, "", false, Loginpanel.tab[1]) edtPass = guiCreateEdit(190, 226, 161, 24, "", false, Loginpanel.tab[1]) Loginpanel.label[1] = guiCreateLabel(191, 135, 156, 15, "Username:", false, Loginpanel.tab[1]) guiSetFont(Loginpanel.label[1], "default-bold-small") Loginpanel.label[2] = guiCreateLabel(191, 211, 156, 15, "Password:", false, Loginpanel.tab[1]) guiSetFont(Loginpanel.label[2], "default-bold-small") Loginpanel.checkbox[1] = guiCreateCheckBox(190, 265, 157, 15, "Remember me", true, false, Loginpanel.tab[1]) guiSetFont(Loginpanel.checkbox[1], "default-bold-small") btnLogin = guiCreateButton(188, 336, 163, 18, "Login", false, Loginpanel.tab[1]) guiSetFont(Loginpanel.button[1], "default-bold-small") Loginpanel.tab[2] = guiCreateTab("Register", Loginpanel.tabpanel[1]) Loginpanel.staticimage[2] = guiCreateStaticImage(10, 5, 503, 90, ":lol/logo.png", false, Loginpanel.tab[2]) edtUserR = guiCreateEdit(188, 141, 165, 24, "", false, Loginpanel.tab[2]) edtPass1 = guiCreateEdit(188, 198, 165, 24, "", false, Loginpanel.tab[2]) edtPass2 = guiCreateEdit(188, 247, 165, 24, "", false, Loginpanel.tab[2]) btnRegister = guiCreateButton(188, 339, 166, 18, "Register", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.button[2], "default-bold-small") Loginpanel.label[3] = guiCreateLabel(192, 121, 155, 15, "Username:", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.label[3], "default-bold-small") Loginpanel.label[4] = guiCreateLabel(189, 183, 164, 15, "Password:", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.label[4], "default-bold-small") Loginpanel.label[5] = guiCreateLabel(189, 232, 164, 15, "Password:", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.label[5], "default-bold-small") Loginpanel.checkbox[2] = guiCreateCheckBox(188, 286, 200, 15, "I accept suomisisu terms of use", true, false, Loginpanel.tab[2]) guiSetFont(Loginpanel.checkbox[2], "default-bold-small") Loginpanel.tab[3] = guiCreateTab("Rules", Loginpanel.tabpanel[1]) Loginpanel.label[6] = guiCreateLabel(1, 3, 518, 366, " 1. Ei hakkerointia, tai muuta mikä häiritsee serverin toimintaa.\n 2. Chattiin spämminen on kiellettyä.\n 3. Älä kerjaa admin/mode oikeuksia\n 4. Tottele henkilökuntaa kaikissa tilanteissa\n 5. Älä sabotoi serveriä\n 6. Älä varasta toisen käyttäjätiliä / yritä onkia salasanoja\n 7. Älä mainosta muita palvelimia\n 8. Älä häiritse muita pelaajia jatkuvasti tappamalla heitä\n 9. Älä warp-tapa\n 10. Älä spawn-tapa\n 11. Henkilökuntaa ei saa häiritä jos hän on on-duty tilassa\n 12. Henkilökunnan jäsentä ei saa tappaa jos hän on on-duty tilassa..\n 13. Trainereiden käyttö on kiellettyä.\n 14. Bugien hyödyntäminen on kiellettyä, jos löydät bugin ilmoita siitä adminille.\n 15. Ilkivalta henkilökunnan & vippien autoja kohtaan on kiellettyä.\n 16. Et saa käyttää toisten pelaajien nimiä\n\n Jos et noudata yllämainittuja sääntöjä on henkilökunalla oikeus antaa sinulle porttikielto\n palvelimelle.\n\n Porttikiellon kesto riippuu sääntörikkeestä ja sen vakavuudesta.\n\n Nämä säännöt hyväksyt joka kerta kun menet palvelimelle.\n Pidämme kaikki oikeudet sääntöjenmuutoksiin.\n", false, Loginpanel.tab[3]) guiSetFont(Loginpanel.label[6], "default-bold-small") guiLabelSetHorizontalAlign(Loginpanel.label[6], "left", true) Loginpanel.tab[4] = guiCreateTab("Info", Loginpanel.tabpanel[1]) Loginpanel.label[7] = guiCreateLabel(3, 5, 515, 359, "Suomisisu mtapalvelin aloitettiin lainelaitoksen kaatumisen aikoina, serveri oli alunperin suuniteltu vain sanden ja vlackin hauskanpito serveriksi. Serverille alkoi kuitenkin virrata pelaajia ja päätimme aloittaa ihan operoimaan serveriä.\n\nSuomisisun ylläpitotiimiin kuuluu:\nSisuviina - Omistaja\nSuokkola - Toinen omistaja\nSinetti - Ylläpitäjä\nFinnPlaya - Ylläpitäjä\nNikkop99 - Päämoderaattori\n\nErityiskiitokset:\n[Dj]Wolf_fin - Lahjoittaja\nMonkey_Dr!fter - Lahjoittaja\nJonskuGameGod - Lahjoittaja\nCookieZ - Lahjoittaja\nMrEllux - Lahjoittaja\n\nSuomisisun omistaa BGSOF eli Best gaming servers of finland yhteisö jota Sisuviina ylläpitää.\n\nServerin nettisivut:\nbgsof.com - Pääsivu\nbgsof.com/Forkka - Foorumi\nbgsof.com/Filecenter - Tiedostopalvelu\n\n© Suomisisu & Bgsof 2012-2014", false, Loginpanel.tab[4]) guiSetFont(Loginpanel.label[7], "default-bold-small") guiLabelSetHorizontalAlign(Loginpanel.label[7], "left", true) addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) addEventHandler("onClientGUIClick", btnRegister, clientSubmitRegister, false) end function show() -- create the log in window and its components createLoginWindow() -- output a brief welcome message to the player --outputChatBox("Welcome to My MTA:SA Server, please log in.") -- if the GUI was successfully created, then show the GUI to the player if (Loginpanel.window[1] ~= nil) then guiSetVisible(Loginpanel.window[1], true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) end addEvent("openLogin",true) addEventHandler("openLogin",root,show) addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function (username, password) -- create the log in window and its components createLoginWindow() -- output a brief welcome message to the player outputChatBox("Welcome to My MTA:SA Server, please log in.") -- if the GUI was successfully created, then show the GUI to the player if (Loginpanel.window[1] ~= nil) then guiSetVisible(Loginpanel.window[1], true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) end ) function clientSubmitLogin(button,state) if button == "left" and state == "up" then -- get the text entered in the 'username' field local username = guiGetText(edtUser) -- get the text entered in the 'password' field local password = guiGetText(edtPass) -- if the username and password both exist if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitLogin", getRootElement(), username, password) -- hide the gui, hide the cursor and return control to the player guiSetInputEnabled(false) guiSetVisible(Loginpanel.window[1], false) showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui outputChatBox("Please enter a username and password.") end end end function clientSubmitRegister(button,state) if button == "left" and state == "up" then -- get the text entered in the 'username' field local username = guiGetText(edtUserR) -- get the text entered in the 'password' field local password = guiGetText(edtPass1) local passwordC = guiGetText(edtPass2) -- if the username and password both exist if username and password and password == passwordC then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitRegister", getRootElement(), username, password, passwordC) -- hide the gui, hide the cursor and return control to the player guiSetInputEnabled(false) guiSetVisible(Loginpanel.window[1], false) showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui outputChatBox("Please enter a username and password, and make sure the password boxes contains same password.") end end end function loadLoginFromXML() --Загрузка логина и пароля из XML 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(username, password) --Сохрание логина и пароля в XML 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 (username ~= "") 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(username)) end if (password ~= "") 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(password)) end xmlSaveFile(xml_save_log_File) xmlUnloadFile (xml_save_log_File) end addEvent("saveLoginToXML", true) addEventHandler("saveLoginToXML", getRootElement(), saveLoginToXML) function resetSaveXML() --Сохрание логина и пароля в XML 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 (username ~= "") then local usernameNode = xmlFindChild (xml_save_log_File, "username", 0) if not usernameNode then usernameNode = xmlCreateChild(xml_save_log_File, "username") end end if (password ~= "") 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) Link to comment
.:HyPeX:. Posted May 17, 2014 Share Posted May 17, 2014 Supposing your saving/loading system functions are right (didnt checked them) and the rest itself is ok, this should work: (I also did some small tweaks, like you werent checking the terms checkbox, nor filling back the edit boxes on panel creation) --[[------------------------------------------------- Notes: > This code is using a relative image filepath. This will only work as long as the location it is from always exists, and the resource it is part of is running. To ensure it does not break, it is highly encouraged to move images into your local resource and reference them there. --]]------------------------------------------------- function createLoginWindow() Loginpanel = { tab = {}, staticimage = {}, tabpanel = {}, edit = {}, button = {}, window = {}, label = {}, checkbox = {} } Loginpanel.window[1] = guiCreateWindow(681, 346, 542, 428, "Suomisisu", false) guiWindowSetSizable(Loginpanel.window[1], false) Loginpanel.tabpanel[1] = guiCreateTabPanel(9, 20, 523, 398, false, Loginpanel.window[1]) Loginpanel.tab[1] = guiCreateTab("Login", Loginpanel.tabpanel[1]) Loginpanel.staticimage[1] = guiCreateStaticImage(10, 5, 503, 90, ":lol/logo.png", false, Loginpanel.tab[1]) edtUser = guiCreateEdit(190, 155, 161, 24, "", false, Loginpanel.tab[1]) edtPass = guiCreateEdit(190, 226, 161, 24, "", false, Loginpanel.tab[1]) local uss, pass = loadLoginFromXML() guiSetText(edtUser, uss) guiSetText(edtPass, pass) Loginpanel.label[1] = guiCreateLabel(191, 135, 156, 15, "Username:", false, Loginpanel.tab[1]) guiSetFont(Loginpanel.label[1], "default-bold-small") Loginpanel.label[2] = guiCreateLabel(191, 211, 156, 15, "Password:", false, Loginpanel.tab[1]) guiSetFont(Loginpanel.label[2], "default-bold-small") Loginpanel.checkbox[1] = guiCreateCheckBox(190, 265, 157, 15, "Remember me", true, false, Loginpanel.tab[1]) guiSetFont(Loginpanel.checkbox[1], "default-bold-small") btnLogin = guiCreateButton(188, 336, 163, 18, "Login", false, Loginpanel.tab[1]) guiSetFont(Loginpanel.button[1], "default-bold-small") Loginpanel.tab[2] = guiCreateTab("Register", Loginpanel.tabpanel[1]) Loginpanel.staticimage[2] = guiCreateStaticImage(10, 5, 503, 90, ":lol/logo.png", false, Loginpanel.tab[2]) edtUserR = guiCreateEdit(188, 141, 165, 24, "", false, Loginpanel.tab[2]) edtPass1 = guiCreateEdit(188, 198, 165, 24, "", false, Loginpanel.tab[2]) edtPass2 = guiCreateEdit(188, 247, 165, 24, "", false, Loginpanel.tab[2]) btnRegister = guiCreateButton(188, 339, 166, 18, "Register", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.button[2], "default-bold-small") Loginpanel.label[3] = guiCreateLabel(192, 121, 155, 15, "Username:", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.label[3], "default-bold-small") Loginpanel.label[4] = guiCreateLabel(189, 183, 164, 15, "Password:", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.label[4], "default-bold-small") Loginpanel.label[5] = guiCreateLabel(189, 232, 164, 15, "Password:", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.label[5], "default-bold-small") Loginpanel.checkbox[2] = guiCreateCheckBox(188, 286, 200, 15, "I accept suomisisu terms of use", true, false, Loginpanel.tab[2]) guiSetFont(Loginpanel.checkbox[2], "default-bold-small") Loginpanel.tab[3] = guiCreateTab("Rules", Loginpanel.tabpanel[1]) Loginpanel.label[6] = guiCreateLabel(1, 3, 518, 366, " 1. Ei hakkerointia, tai muuta mikä häiritsee serverin toimintaa.\n 2. Chattiin spämminen on kiellettyä.\n 3. Älä kerjaa admin/mode oikeuksia\n 4. Tottele henkilökuntaa kaikissa tilanteissa\n 5. Älä sabotoi serveriä\n 6. Älä varasta toisen käyttäjätiliä / yritä onkia salasanoja\n 7. Älä mainosta muita palvelimia\n 8. Älä häiritse muita pelaajia jatkuvasti tappamalla heitä\n 9. Älä warp-tapa\n 10. Älä spawn-tapa\n 11. Henkilökuntaa ei saa häiritä jos hän on on-duty tilassa\n 12. Henkilökunnan jäsentä ei saa tappaa jos hän on on-duty tilassa..\n 13. Trainereiden käyttö on kiellettyä.\n 14. Bugien hyödyntäminen on kiellettyä, jos löydät bugin ilmoita siitä adminille.\n 15. Ilkivalta henkilökunnan & vippien autoja kohtaan on kiellettyä.\n 16. Et saa käyttää toisten pelaajien nimiä\n\n Jos et noudata yllämainittuja sääntöjä on henkilökunalla oikeus antaa sinulle porttikielto\n palvelimelle.\n\n Porttikiellon kesto riippuu sääntörikkeestä ja sen vakavuudesta.\n\n Nämä säännöt hyväksyt joka kerta kun menet palvelimelle.\n Pidämme kaikki oikeudet sääntöjenmuutoksiin.\n", false, Loginpanel.tab[3]) guiSetFont(Loginpanel.label[6], "default-bold-small") guiLabelSetHorizontalAlign(Loginpanel.label[6], "left", true) Loginpanel.tab[4] = guiCreateTab("Info", Loginpanel.tabpanel[1]) Loginpanel.label[7] = guiCreateLabel(3, 5, 515, 359, "Suomisisu mtapalvelin aloitettiin lainelaitoksen kaatumisen aikoina, serveri oli alunperin suuniteltu vain sanden ja vlackin hauskanpito serveriksi. Serverille alkoi kuitenkin virrata pelaajia ja päätimme aloittaa ihan operoimaan serveriä.\n\nSuomisisun ylläpitotiimiin kuuluu:\nSisuviina - Omistaja\nSuokkola - Toinen omistaja\nSinetti - Ylläpitäjä\nFinnPlaya - Ylläpitäjä\nNikkop99 - Päämoderaattori\n\nErityiskiitokset:\n[Dj]Wolf_fin - Lahjoittaja\nMonkey_Dr!fter - Lahjoittaja\nJonskuGameGod - Lahjoittaja\nCookieZ - Lahjoittaja\nMrEllux - Lahjoittaja\n\nSuomisisun omistaa BGSOF eli Best gaming servers of finland yhteisö jota Sisuviina ylläpitää.\n\nServerin nettisivut:\nbgsof.com - Pääsivu\nbgsof.com/Forkka - Foorumi\nbgsof.com/Filecenter - Tiedostopalvelu\n\n© Suomisisu & Bgsof 2012-2014", false, Loginpanel.tab[4]) guiSetFont(Loginpanel.label[7], "default-bold-small") guiLabelSetHorizontalAlign(Loginpanel.label[7], "left", true) addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) addEventHandler("onClientGUIClick", btnRegister, clientSubmitRegister, false) end function show() -- create the log in window and its components createLoginWindow() -- output a brief welcome message to the player --outputChatBox("Welcome to My MTA:SA Server, please log in.") -- if the GUI was successfully created, then show the GUI to the player if (Loginpanel.window[1] ~= nil) then guiSetVisible(Loginpanel.window[1], true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) end addEvent("openLogin",true) addEventHandler("openLogin",root,show) addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function (username, password) -- create the log in window and its components createLoginWindow() -- output a brief welcome message to the player outputChatBox("Welcome to My MTA:SA Server, please log in.") -- if the GUI was successfully created, then show the GUI to the player if (Loginpanel.window[1] ~= nil) then guiSetVisible(Loginpanel.window[1], true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) end ) function clientSubmitLogin(button,state) if button == "left" and state == "up" then -- get the text entered in the 'username' field local username = guiGetText(edtUser) -- get the text entered in the 'password' field local password = guiGetText(edtPass) -- if the username and password both exist if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitLogin", getRootElement(), username, password) if guiCheckBoxGetSelected(Loginpanel.checkbox[1]) then saveLoginToXML(username,password) else resetSaveXML() end -- hide the gui, hide the cursor and return control to the player guiSetInputEnabled(false) guiSetVisible(Loginpanel.window[1], false) showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui outputChatBox("Please enter a username and password.") end end end function clientSubmitRegister(button,state) if button == "left" and state == "up" then if not guiCheckBoxGetSelected(Loginpanel.checkbox[2]) then return outputChatBox("You must accept the terms!") end if dxGetTextWidth(edtUserR, 1, "default") <= 10 then return outputChatBox("Please type in a longer username!") end if dxGetTextWidth(edtPass1, 1, "default") <= 10 then return outputChatBox("Please type in a longer password!") end -- get the text entered in the 'username' field local username = guiGetText(edtUserR) -- get the text entered in the 'password' field local password = guiGetText(edtPass1) local passwordC = guiGetText(edtPass2) -- if the username and password both exist if username and password and password == passwordC then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitRegister", getRootElement(), username, password, passwordC) -- hide the gui, hide the cursor and return control to the player guiSetInputEnabled(false) guiSetVisible(Loginpanel.window[1], false) showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui outputChatBox("Please enter a username and password, and make sure the password boxes contains same password.") end end end function loadLoginFromXML() --Загрузка логина и пароля из XML 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(username, password) --Сохрание логина и пароля в XML 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 (username ~= "") 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(username)) end if (password ~= "") 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(password)) end xmlSaveFile(xml_save_log_File) xmlUnloadFile (xml_save_log_File) end addEvent("saveLoginToXML", true) addEventHandler("saveLoginToXML", getRootElement(), saveLoginToXML) function resetSaveXML() --Сохрание логина и пароля в XML 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 (username ~= "") then local usernameNode = xmlFindChild (xml_save_log_File, "username", 0) if not usernameNode then usernameNode = xmlCreateChild(xml_save_log_File, "username") end end if (password ~= "") 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) Link to comment
Sande Posted May 17, 2014 Author Share Posted May 17, 2014 Thank you very much, now i am trying to make server-side 100% functionally. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now