Noneatme

login/register

Mar 9th, 2012
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.95 KB | None | 0 0
  1. local Guivar = 0
  2.  
  3. local LOFenster = {}
  4. local LOTabPanel = {}
  5. local LOTab = {}
  6. local LOKnopf = {}
  7. local LOLabel = {}
  8. local LOEdit = {}
  9. local LORadio = {}
  10. local LOGrid = {}
  11. local LOBild = {}
  12.  
  13. function createEinloggMenue()
  14.     if(Guivar == 1) then return end
  15.     Guivar = 1
  16.     showCursor(true)
  17.     guiSetInputMode("no_binds_when_editing")
  18.  
  19.  
  20.     local X, Y, Width, Height = getMiddleGuiPosition(540,376)
  21.     LOFenster[1] = guiCreateWindow(X, Y, Width, Height,"Willkommen auf Multistunt!",false)
  22.     LOTabPanel[1] = guiCreateTabPanel(9,22,525,345,false,LOFenster[1])
  23.     LOTab[1] = guiCreateTab("Einloggen",LOTabPanel[1])
  24.     LOBild[1] = guiCreateStaticImage(5,2,507,80,"data/images/logo.png",false,LOTab[1])
  25.     LOLabel[1] = guiCreateLabel(8,87,505,58,"Willkommen auf Multistunt!\nDein Account wurde gefunden, bitte logge dich ein!\nFalls du noch kein Account hast, waehle bitte einen anderen Namen.\nFalls du dein Passwort vergessen hast, frage bitte ein Admin!",false,LOTab[1])
  26.     guiLabelSetHorizontalAlign(LOLabel[1],"center",false)
  27.     guiSetFont(LOLabel[1],"default-bold-small")
  28.     LOLabel[2] = guiCreateLabel(232,182,79,18,"Passwort:",false,LOTab[1])
  29.     guiSetFont(LOLabel[2],"default-bold-small")
  30.     LOLabel[3] = guiCreateLabel(10,139,507,19,"_____________________________________________________________________________",false,LOTab[1])
  31.     guiLabelSetColor(LOLabel[3],0, 255, 0)
  32.     LOEdit[1] = guiCreateEdit(102,203,333,35,"12345",false,LOTab[1]) -- Login
  33.     guiEditSetMasked(LOEdit[1],true)
  34.     LOKnopf[1] = guiCreateButton(189,244,149,29,"Einloggen",false,LOTab[1])
  35.     LOTab[2] = guiCreateTab("Regestrieren",LOTabPanel[1])
  36.     LOBild[2] = guiCreateStaticImage(5,2,509,84,"data/images/logo.png",false,LOTab[2])
  37.     LOLabel[4] = guiCreateLabel(8,86,443,18,"Willkommen auf Multistunt! Du hast noch kein Account. Bitte Regestriere dich!",false,LOTab[2])
  38.     guiSetFont(LOLabel[4],"default-bold-small")
  39.     LOLabel[5] = guiCreateLabel(22,143,192,16,"Name: "..getPlayerName(gMe),false,LOTab[2])
  40.     guiSetFont(LOLabel[5],"default-bold-small")
  41.     LOLabel[6] = guiCreateLabel(22,167,45,16,"Alter:",false,LOTab[2])
  42.     guiSetFont(LOLabel[6],"default-bold-small")
  43.     LOEdit[2] = guiCreateEdit(67,164,52,22,"",false,LOTab[2]) -- Alter
  44.     LOLabel[7] = guiCreateLabel(17,112,321,19,"_____________________________________________",false,LOTab[2])
  45.     guiLabelSetColor(LOLabel[7],0, 255, 255)
  46.     guiSetFont(LOLabel[7],"default-bold-small")
  47.     LOLabel[8] = guiCreateLabel(21,193,99,19,"Passwort:(2x)",false,LOTab[2])
  48.     guiSetFont(LOLabel[8],"default-bold-small")
  49.     LOEdit[3] = guiCreateEdit(21,212,106,24,"",false,LOTab[2]) -- PW1
  50.     guiEditSetMasked(LOEdit[3],true)
  51.     LOEdit[4] = guiCreateEdit(21,243,106,24,"",false,LOTab[2]) -- PW2
  52.     guiEditSetMasked(LOEdit[4],true)
  53.     LOLabel[9] = guiCreateLabel(181,142,74,16,"Herkunft:",false,LOTab[2])
  54.     guiSetFont(LOLabel[9],"default-bold-small")
  55.     LOGrid[1] = guiCreateGridList(174,159,157,117,false,LOTab[2])
  56.     guiGridListSetSelectionMode(LOGrid[1],1)
  57.  
  58.     guiGridListAddColumn(LOGrid[1],"Land",0.6)
  59.  
  60.     local row = guiGridListAddRow(LOGrid[1])
  61.     guiGridListSetItemText(LOGrid[1], row, 1, "Deutschland", false, false)
  62.     local row = guiGridListAddRow(LOGrid[1])
  63.     guiGridListSetItemText(LOGrid[1], row, 1, "Oesterreich", false, false)
  64.     local row = guiGridListAddRow(LOGrid[1])
  65.     guiGridListSetItemText(LOGrid[1], row, 1, "Schweiz", false, false)
  66.  
  67.     LOLabel[10] = guiCreateLabel(342,141,89,19,"Geschlecht:",false,LOTab[2])
  68.     guiSetFont(LOLabel[10],"default-bold-small")
  69.     LORadio[1] = guiCreateRadioButton(342,164,112,22,"Maennlich",false,LOTab[2])
  70.     LORadio[2] = guiCreateRadioButton(342,183,112,22,"Weiblich",false,LOTab[2])
  71.     guiRadioButtonSetSelected(LORadio[1],true)
  72.     LOKnopf[2] = guiCreateButton(361,218,127,31,"Regestrieren",false,LOTab[2])
  73.     LOKnopf[3] = guiCreateButton(361,253,127,31,"Abbrechen",false,LOTab[2])
  74.  
  75.     guiSetVisible(LOFenster[1], false)
  76.    
  77.     addEventHandler("onClientGUIClick", LOEdit[1],
  78.     function()
  79.         local passwort = guiGetText(LOEdit[1])
  80.         if(passwort == "12345") then guiSetText(LOEdit[1], "") end
  81.     end, false)
  82.    
  83.     addEventHandler("onClientGUIClick", LOKnopf[1],
  84.     function()
  85.         local passwort = guiGetText(LOEdit[1])
  86.         triggerServerEvent("onAccountLogin", gMe, passwort)
  87.         showCursor(false)
  88.         outputChatBox("Bitte Warten...", 0, 255, 255)
  89.     end, false)
  90.     addEvent("onAccountLoginBack", true)
  91.     addEventHandler("onAccountLoginBack", getRootElement(),
  92.     function(sucess)
  93.         if(sucess == true) then
  94.             guiSetVisible(LOFenster[1], false)
  95.             Guivar = 0
  96.             showCursor(false)
  97.  
  98.         else
  99.        
  100.         end
  101.     end)
  102.     addEventHandler("onClientGUIClick", LOKnopf[2],
  103.     function()
  104.         local alter = tonumber(guiGetText(LOEdit[2]))
  105.         local pw1, pw2 = guiGetText(LOEdit[3]), guiGetText(LOEdit[4])
  106.         local maennlich, weiblich = guiRadioButtonGetSelected(LORadio[1]), guiRadioButtonGetSelected(LORadio[2])
  107.         local geschlecht = 0
  108.         if(maennlich == true) then geschlecht = 1
  109.         elseif(weiblich == true) then geschlecht = 2 end
  110.         local land = guiGridListGetItemText(LOGrid[1], guiGridListGetSelectedItem(LOGrid[1]), 1)
  111.         if not(alter) then outputChatBox("Ungueltiges Alter!", 255, 0, 0) return end
  112.         if (alter < 14) or (alter > 99) then outputChatBox("Ungueltiges Alter!", 255, 0, 0) return end
  113.         if(string.len(pw1) < 4) or (string.len(pw1) > 20) then outputChatBox("Dein Passwort darf Maximal 20 Zeichen, und Minimal 4 Zeichen lang sein!", 255, 0, 0, 0) return end
  114.         if(pw1 == "12345") or (pw1 == "1234") or (pw1 == "123") or (pw1 == "123456") or (pw1 == "1234567") or (pw1 == "12345678") or (pw1 == "Hallo") then outputChatBox("Dieses Passwort darfst du nicht verwenden!", 255, 0, 0, false) return end
  115.         if(pw1 ~= pw2) then outputChatBox("Die Passwoerter stimmen nicht ueberein!", 255, 0, 0, false) return end
  116.         if(land == "") or (land == " ") then outputChatBox("Bitte waehle ein Land aus!", 255, 0, 0, false) return end
  117.         local landvar = 0
  118.         if(land == "Deutschland") then landvar = 1 end
  119.         if(land == "Oesterreich") then landvar = 2 end
  120.         if(land == "Schweiz") then landvar = 3 end
  121.         if(landvar == 0) then outputChatBox("Fehler!", 255, 0, 0, false) return end
  122.         triggerServerEvent("onAccountRegister", gMe, alter, pw1, geschlecht, landvar)
  123.         showCursor(false)
  124.         outputChatBox("Bitte Warten...", 0, 255, 255)
  125.     end, false)
  126.     addEvent("showLoginCursor", true)
  127.     addEventHandler("showLoginCursor", getRootElement(), function() showCursor(true) end)
  128. end
  129.  
  130.  
  131. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
  132. function()
  133.     createEinloggMenue()
  134.     if(getElementData(gMe, "ms.eingeloggt") ~= true) then
  135.         triggerServerEvent("onLoginDataNeed", gMe)
  136.         addEvent("onLoginDataNeedBack", true)
  137.         addEventHandler("onLoginDataNeedBack", getRootElement(),
  138.         function(rofl)
  139.             guiSetVisible(LOFenster[1], true)
  140.             if(rofl == true) then -- Account gibt es
  141.                 guiSetEnabled(LOTab[2], false)
  142.                 guiSetSelectedTab(LOTabPanel[1], LOTab[1])
  143.             else -- Account gibt es nicht
  144.                 guiSetEnabled(LOTab[1], false)
  145.                 guiSetSelectedTab(LOTabPanel[1], LOTab[2])
  146.             end
  147.         end)
  148.     end
  149. end)
  150.  
  151. -- SERVER -- SERVER ASSHOLE! -- SERVEAAAAAAAAAAAAAAAAAAAAAAAAA!!!
  152.  
  153. addEvent("onAccountLogin", true)
  154. addEventHandler("onAccountLogin", getRootElement(),
  155. function(pw)
  156.     if(client ~= source) then return end
  157.     local query = "SELECT * FROM accounts WHERE NAME = '"..getPlayerName(source).."' AND PASSWORD = '"..md5(pw).."';"
  158.     local result = mysql_query( handler, query )
  159.     if ( result and mysql_num_rows( result ) > 0) then
  160.         triggerClientEvent(source, "onAccountLoginBack", source, true)
  161.         fadeCamera(source, false, 1.0, 255, 255, 255)
  162.         setTimer(fadeCamera, 1500, 1, source, true)
  163.         setTimer(triggerEvent, 1500, 1, "onMultistuntSpawn", source)
  164.         setElementData(source, "ms.eingeloggt", true)
  165.         outputChatBox("Du hast dich erfolgreich Eingeloggt!", source, 0, 255, 0)
  166.         local rowAccount = mysql_fetch_assoc(result)
  167.         --
  168.         -- Account --
  169.         setElementData(source, "ms.adminlevel", rowAccount['ADMINLEVEL'])
  170.         setElementData(source, "ms.money", rowAccount['MONEY'])
  171.         setElementData(source, "ms.playtime", rowAccount['PLAYTIME'])
  172.         setElementData(source, "ms.skin", rowAccount['SKIN'])
  173.         setElementModel(source, getElementData(source, "ms.skin"))
  174.         --
  175.        
  176.         addEventHandler("onElementDataChange", source,
  177.         function(data)
  178.             if(data == "ms.adminlevel") then
  179.                 mysql_query(handler,"UPDATE accounts SET ADMINLEVEL = '"..getElementData(source, data).."' WHERE NAME = '"..getPlayerName(source).."'")
  180.             elseif(data == "ms.money") then
  181.                 mysql_query(handler,"UPDATE accounts SET MONEY = '"..getElementData(source, data).."' WHERE NAME = '"..getPlayerName(source).."'")
  182.                 setPlayerMoney(source, getElementData(source, data))
  183.             elseif(data == "ms.playtime") then
  184.                 mysql_query(handler,"UPDATE accounts SET PLAYTIME = '"..getElementData(source, data).."' WHERE NAME = '"..getPlayerName(source).."'")
  185.             elseif(data == "ms.skin") then
  186.                 mysql_query(handler,"UPDATE accounts SET SKIN = '"..getElementData(source, data).."' WHERE NAME = '"..getPlayerName(source).."'")
  187.             end
  188.        
  189.         end)
  190.     else
  191.         triggerClientEvent(source, "onAccountLoginBack", source, false)
  192.         triggerClientEvent(source, "showLoginCursor", source)
  193.         outputChatBox("Fehler: Der Account Exestiert nicht, oder du hast ein falsches Passwort eingegeben!", source, 255, 0, 0 )
  194.     end
  195.     mysql_free_result(result)
  196. end)
  197.  
  198. addEvent("onLoginDataNeed", true)
  199. addEventHandler("onLoginDataNeed", getRootElement(),
  200. function()
  201.     if(client ~= source) then return end
  202.     local query = "SELECT * FROM accounts WHERE NAME = \'"..getPlayerName(source).."\';"
  203.     local result = mysql_query( handler, query )
  204.     if ( result and mysql_num_rows( result ) > 0) then
  205.         triggerClientEvent(source, "onLoginDataNeedBack", source, true)
  206.     else
  207.         triggerClientEvent(source, "onLoginDataNeedBack", source, false)
  208.     end
  209.     mysql_free_result(result)
  210. end)
  211.  
  212. addEvent("onAccountRegister", true)
  213. addEventHandler("onAccountRegister", getRootElement(),
  214. function(alter, passwort, geschlecht, land)
  215.     if(client ~= source) then return end
  216.     if(alter) and (passwort) and (geschlecht) and (land) then
  217.         local name = getPlayerName(source)
  218.         local ip = getPlayerIP(source)
  219.         local serial = getPlayerSerial(source)
  220.         local newpasswort = md5(passwort)
  221.         local time = getRealTime()
  222.         local day = time.monthday
  223.         local month = time.month+1
  224.         local year = time.year+1900
  225.         local hour = time.hour
  226.         local minute = time.minute
  227.         local datum = day.."."..month.."."..year.." "..hour..":"..minute
  228.         local query = "INSERT INTO accounts ( NAME, PASSWORD, IP, SERIAL, AGE, GESCHLECHT, LAND, REGISTERDATUM ) VALUES ( '"..name.."', '"..newpasswort.."', '"..ip.."', '"..serial.."', '"..alter.."', '"..geschlecht.."', '"..land.."', '"..datum.."' )"
  229.         local result = mysql_query( handler, query )
  230.         if(result) then
  231.             outputChatBox("Du hast dich erfolgreich Registriert, und kannst dich nun Einloggen!", source, 0, 255, 0, false)
  232.             triggerClientEvent(source, "showLoginCursor", source)
  233.             triggerEvent("onLoginDataNeed", source)
  234.             mysql_free_result(result)
  235.         else
  236.             outputChatBox("Fehler beim Registrieren!", source, 255, 0, 0, false)
  237.             triggerClientEvent(source, "showLoginCursor", source)
  238.         end
  239.     end
  240. end)
Advertisement
Add Comment
Please, Sign In to add comment