Sande Posted April 19, 2014 Share Posted April 19, 2014 Hello, i take new move to little harder scripting. But now i have problems, i dont have skills to finish my loginpanel, and the code is really messed up. if someone can make working version of this i will be happy. Client 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 loginPanel() Loginpanel = { tab = {}, tabpanel = {}, edit = {}, button = {}, window = {}, label = {}, checkbox = {} } Loginpanel.window[1] = guiCreateWindow(580, 330, 547, 382, "Suomisisu", false) guiWindowSetSizable(Loginpanel.window[1], false) Loginpanel.tabpanel[1] = guiCreateTabPanel(9, 20, 528, 352, false, Loginpanel.window[1]) Loginpanel.tab[1] = guiCreateTab("Login", Loginpanel.tabpanel[1]) Loginpanel.checkbox[1] = guiCreateCheckBox(151, 244, 109, 15, "Remember me", false, false, Loginpanel.tab[1]) guiSetFont(Loginpanel.checkbox[1], "default-bold-small") Loginpanel.edit[1] = guiCreateEdit(152, 108, 256, 28, "", false, Loginpanel.tab[1]) Loginpanel.edit[2] = guiCreateEdit(151, 184, 257, 28, "", false, Loginpanel.tab[1]) Loginpanel.label[1] = guiCreateLabel(219, 10, 209, 30, "Suomisisu - Login", false, Loginpanel.tab[1]) guiSetFont(Loginpanel.label[1], "default-bold-small") Loginpanel.label[2] = guiCreateLabel(156, 89, 114, 19, "Username:", false, Loginpanel.tab[1]) guiSetFont(Loginpanel.label[2], "default-bold-small") Loginpanel.label[3] = guiCreateLabel(156, 165, 114, 19, "Password:", false, Loginpanel.tab[1]) guiSetFont(Loginpanel.label[3], "default-bold-small") Loginpanel.button[1] = guiCreateButton(151, 281, 257, 36, "Login", false, Loginpanel.tab[1]) Loginpanel.tab[2] = guiCreateTab("Register", Loginpanel.tabpanel[1]) Loginpanel.edit[3] = guiCreateEdit(180, 88, 238, 30, "", false, Loginpanel.tab[2]) Loginpanel.edit[4] = guiCreateEdit(180, 153, 238, 30, "", false, Loginpanel.tab[2]) Loginpanel.edit[5] = guiCreateEdit(180, 220, 238, 28, "", false, Loginpanel.tab[2]) Loginpanel.label[4] = guiCreateLabel(212, 10, 167, 21, "Suomisisu - Registration", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.label[4], "default-bold-small") Loginpanel.label[5] = guiCreateLabel(180, 70, 98, 18, "Username:", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.label[5], "default-bold-small") Loginpanel.label[6] = guiCreateLabel(180, 131, 95, 18, "Password:", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.label[6], "default-bold-small") Loginpanel.label[7] = guiCreateLabel(180, 202, 166, 18, "Repeat Password:", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.label[7], "default-bold-small") Loginpanel.button[2] = guiCreateButton(180, 274, 238, 43, "Register", false, Loginpanel.tab[2]) Loginpanel.label[8] = guiCreateLabel(10, 98, 138, 209, "When you register to suomisisu, sametime you agree our rules. \n\nWhen you have account all your details, like money, houses, jobs, team saving.\n\n We recommend to read the rules before you register an account.\n\n Info tab have good information too.", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.label[8], "default-bold-small") guiLabelSetColor(Loginpanel.label[8], 254, 234, 0) guiLabelSetHorizontalAlign(Loginpanel.label[8], "left", true) Loginpanel.label[9] = guiCreateLabel(12, 70, 137, 15, "Tips:", false, Loginpanel.tab[2]) guiSetFont(Loginpanel.label[9], "default-bold-small") guiLabelSetColor(Loginpanel.label[9], 253, 0, 0) Loginpanel.tab[3] = guiCreateTab("Rules", Loginpanel.tabpanel[1]) Loginpanel.label[10] = guiCreateLabel(4, 7, 514, 329, "Rules of our server in: English\n 1.No hacking, or anything else illegal / harmful to other players and/or server \n2.No spamming \n3.Don't ask for admins, because that way you surely won't get them, be patient and wait for recruiting \n4.Do what the staff says in all situations, especially in case of a bug or other crisis \n5.Don't sabotage e.g do anything harmful to the server \n6.Don't steal other players accounts, or try to find out their password \n7.Don't advertise other servers \n8.Don't continuously kill other players or bother the admins \n9.Don't warp/map kill \n10.Don't spawn kill \n11.You must not bother the admins by for example following them everywhere \n12.You must not kill an admin unless the admin is part of an action that allows it \n13.Using mods and/or trainers is forbidden and will result in a permanent ban \n14.Bug abuse is forbidden! If you find a bug, report it to an admin, and if you abuse a bug and there is evidence about it you will be banned \n15.Vandalism against admins and donators vehicles is forbidden \n16.You must not use the nickname of an admin/moderator or pretend to be one \nIf you broke the rules, admin have a right to ban you in this server. \nBAN-Time defines from the situation / severity of offense. Rules accepted when you press \"Login or register\" button.\nWe keep allrights to change the rules when we want to.", false, Loginpanel.tab[3]) guiSetFont(Loginpanel.label[10], "default-bold-small") guiLabelSetHorizontalAlign(Loginpanel.label[10], "left", true) Loginpanel.tab[4] = guiCreateTab("Info", Loginpanel.tabpanel[1]) Loginpanel.label[11] = guiCreateLabel(5, 4, 513, 313, "Description of the server: Suomisisu is a freeroam CnR and some rpg server with hay, zombie and other nice events. \nMost of the players are from finland.\n \n\nAdmins:\n Sisuviina, \n [Dj]Wolf_fin, \n Finnplaya, \n Sinetti, \n\nSupermoderators: \nNikkop99\n\nWebsite: bgsof.com\nForum: bgsof.com/Forkka\n\nServer owner: Sisuviina\nSkype: sande.retroilija\nBgsof: Sisuviina", false, Loginpanel.tab[4]) guiSetFont(Loginpanel.label[11], "default-bold-small") guiLabelSetHorizontalAlign(Loginpanel.label[11], "left", true) guiSetVisible(Teampanel.Window[1], true) showCursor(true) local username, password = loadLoginFromXML() if not( username == "" or password == "") then guiCheckBoxSetSelected ( checkbox_save, true ) guiSetText ( Loginpanel.edit[1], tostring(username)) guiSetText ( Loginpanel.edit[2], tostring(password)) else guiCheckBoxSetSelected ( checkbox_save, false ) guiSetText ( Loginpanel.edit[1], tostring(username)) guiSetText ( Loginpanel.edit[2], tostring(password)) end end function start_cl_resource() loginPanel() end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),start_cl_resource) function saveLoginToXML(username, password) 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() 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) function onClickBtnLogin(button,state) showChat(true) showCursor(false) guiSetVisible(Loginpanel.Window[1],false) if(button == "left" and state == "up") then if (source == Loginpanel.Window[1]) then username = guiGetText(Loginpanel.edit[1]) password = guiGetText(Loginpanel.edit[2]) if guiCheckBoxGetSelected ( checkbox_save ) == true then checksave = true else checksave = false end triggerServerEvent("onRequestLogin",getLocalPlayer(),username,password,checksave) end end end addEventHandler("onClientGUIClick", Loginpanel.button[1], onClickBtnLogin) function onClickBtnRegister(button,state) showCursor(true) username = guiGetText(Loginpanel.edit[3]) password = guiGetText(Loginpanel.edit[4]) passwordConfirm = guiGetText(Loginpanel.edit[5]) triggerServerEvent("onRequestRegister",getLocalPlayer(),username,password,passwordConfirm) end addEventHandler("onClientGUIClick", Loginpanel.button[2], onClickBtnRegister) function onClickGuest() setTimer ( function ( source ) exports["ac-message"]:outputTopBar("Login: Guest option are disabled, you have login or create a account.", 255,0,0 ) end ,100, 1, source ) end function hideLoginWindow() exports["ac-message"]:outputTopBar("Login: Welcome to suomisisu, and we hope you enjoying your time here.", 255,0,0 ) showCursor(false) showChat(true) guiSetVisible (Loginpanel.window[1], false) removeEventHandler("onClientGUIClick",getRootElement(),onClickBtnLogin) end addEvent("hideLoginWindow", true) addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) function CursorError () outputChatBox("Kurzor elrejtve") showCursor(false) end addCommandHandler("showc", CursorError) Server: 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 exports["ac-message"]:outputTopBar("Login: Wrong username and/or password.", 255,0,0 ) end else exports["ac-message"]:outputTopBar("Login: Please enter your password.", 255,0,0 ) end else exports["ac-message"]:outputTopBar("Login: Please enter your username.", 255,0,0 ) 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 ("#00FF00[Login] Rekisteroidyit! [username: #FFFFFF" .. username .. " #00FF00| Password: #FFFFFF" .. password .. "#00FF00 ]",source,255,255,255,true ) outputChatBox ("#FF0000[Login] Muista yllämainitut tiedot! ",source,255,255,255,true ) else exports["ac-message"]:outputTopBar("Login: Error, please try again with diffrent username and password.", 255,0,0 ) end else exports["ac-message"]:outputTopBar("Login: This username is already taken.", 255,0,0 ) end else exports["ac-message"]:outputTopBar("Login: Password doesn´t match.", 255,0,0 ) end else exports["ac-message"]:outputTopBar("Login: Please confirm your password.", 255,0,0 ) end else exports["ac-message"]:outputTopBar("Login: Please enter your password.", 255,0,0 ) end else exports["ac-message"]:outputTopBar("Login: Please enter your username.", 255,0,0 ) end end addEvent("onRequestRegister",true) addEventHandler("onRequestRegister",getRootElement(),registerPlayer) Link to comment
Karuzo Posted April 19, 2014 Share Posted April 19, 2014 Could you use /debugscript 3 and tell us what it outputs? 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