Guest User

Untitled

a guest
Sep 29th, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.17 KB | None | 0 0
  1. --set prespecifical settings for getting no probs with the Gamemode
  2. function createSQLOnScriptStart()
  3.     executeSQLCreateTable ( "accounts", "accountname TEXT, accountpassword TEXT, level INTEGER, ip TEXT, serial TEXT, money INTEGER, bank INTEGER, online INTEGER")
  4.     local online = 0
  5.     local onlineCheck = 1
  6.     executeSQLUpdate("accounts","online='"..online.."'","online='"..onlineCheck.."'")
  7. end
  8.  
  9. addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),createSQLOnScriptStart)
  10.  
  11. function dropMyTable()
  12.     success = executeSQLDropTable("accounts")
  13.     if (success ) then
  14.         outputChatBox("Table Dropped!")
  15.     end
  16. end
  17.  
  18. addCommandHandler("drop",dropMyTable)
  19. --Login
  20. function loginCheck( loginName,loginPassword )
  21.     --Check if there´s a password entered
  22.     if (string.len(tostring(loginName)) <= 0 ) or (string.len(tostring(loginPassword)) <= 0) then
  23.         outputChatBox("Please insert your logindata!",client,255,0,0)
  24.         triggerClientEvent("onPasswordEntryIsWrong",getRootElement())
  25.     else
  26.         local getAccountViaDB = executeSQLQuery("SELECT * FROM accounts WHERE accountname=? AND accountpassword=?", loginName, md5(loginPassword) )
  27.         local alreadyLoggedInCheck = executeSQLQuery("SELECT * FROM accounts WHERE accountname=? AND accountpassword=? AND online=?", loginName, md5(loginPassword), 1 )
  28.         --check if the SQL is a table and if there is an accountname == loginName
  29.         if (type(getAccountViaDB) == "table") and( #getAccountViaDB == 1) then
  30.             --check if User is already logged in
  31.             if (type(alreadyLoggedInCheck) == "table") and ( #alreadyLoggedInCheck ~= 1 ) then
  32.                 --Update my SQLStats on Login--
  33.                 local getDataFromDatabase = executeSQLQuery("SELECT * FROM accounts WHERE accountname=?",loginName)
  34.                 local ipFromPlayerRegistered = getPlayerIP(client)
  35.                 local serialFromPlayerRegistered = getPlayerSerial(client)
  36.                 local getNumberOfSameSerialsInDB = executeSQLQuery("SELECT * FROM accounts WHERE serial=?",serialFromPlayerRegistered)
  37.                 if (type(getNumberOfSameSerialsInDB) == "table") and (#getNumberOfSameSerialsInDB > 1 ) then
  38.                     local serialreset = "RESETTED"
  39.                     outputChatBox("MORESERIALS")
  40.                     executeSQLUpdate("accounts","serial='"..serialreset.."'","serial='"..serialFromPlayerRegistered.."'")
  41.                 end
  42.                 for i, updateStats in ipairs(getDataFromDatabase) do
  43.                     setPlayerMoney(client,updateStats.money)
  44.                     local online = 1
  45.                     executeSQLUpdate("accounts","ip='"..ipFromPlayerRegistered.."',serial='"..serialFromPlayerRegistered.."',online='"..online.."'","accountname='"..loginName.."'")
  46.                 end
  47.                 --Spawn the player and other stuff for spawn--
  48.                 spawnPlayer( client,1213.4375, -6.7730188369751, 1000.921875 )
  49.                 setElementInterior( client, 2 )
  50.                 setElementRotation( client, 0,0,90)
  51.                 r,g,b=math.random(0,255),math.random(0,255),math.random(0,255)
  52.                 createBlipAttachedTo(client,0,2,r,g,b)
  53.                 fadeCamera( client, true, 3.0, 0, 0, 0 )
  54.                 setCameraTarget(client,client)
  55.                 outputChatBox("You have been successfully logged in!",client,255,0,0)
  56.             else
  57.                 outputChatBox("Your account is already logged in!",client,255,0,0)
  58.                 triggerClientEvent("onPasswordEntryIsWrong",getRootElement())  
  59.             end
  60.         else
  61.             triggerClientEvent("onPasswordEntryIsWrong",getRootElement())
  62.             outputChatBox("The loginName: "..tostring(loginName).. " or your password: "..loginPassword.." is wrong!",client,255,0,0)
  63.         end
  64.     end
  65. end
  66. addEvent("checkMyLogin",true)
  67. addEventHandler("checkMyLogin",getRootElement(),loginCheck)
  68.  
  69. --Registration
  70. function registerPlayer(userName,password,passwordReEntry)
  71.     if userName ~= nil and password ~= nil and passwordReEntry ~= nil then
  72.     local playerSerial = getPlayerSerial(client)
  73.     local accountAvailable = executeSQLQuery("SELECT * FROM accounts WHERE serial=?",playerSerial)
  74.     if (type(accountAvailable) == "table") and( #accountAvailable ~= 0) then
  75.         outputChatBox("Only one account per serial is allowed!",client,255,0,0)
  76.         return
  77.     else
  78.             local checkIfAccountAvailable = executeSQLQuery("SELECT * FROM accounts WHERE accountname =?",userName)[1]
  79.             if (string.len(password) < 6) then
  80.                 outputChatBox("Your password should be at least 6 chars. long!",client,255,0,0)
  81.             elseif (password ~= passwordReEntry) then
  82.                 outputChatBox("Your password and your re-entered one arent the same!",client,255,0,0)
  83.             elseif (string.len(userName) <= 0) then
  84.                 outputChatBox("Please insert an username!",client,255,0,0)
  85.             elseif ( checkIfAccountAvailable ~= nil ) then
  86.                 outputChatBox("#FF0000This Username is already taken!#FFFFFF ( "..userName.." )", client, 255,0,0, true)
  87.                 return
  88.             elseif (userName) and (password == passwordReEntry) then
  89.                 local ipFromPlayerRegistered = getPlayerIP(client)
  90.                 local serialFromPlayerRegistered = getPlayerSerial(client)
  91.                 executeSQLInsert("accounts","'"..userName.."','"..md5(password).."',0,'"..ipFromPlayerRegistered.."','"..serialFromPlayerRegistered.."',0,0","accountname,accountpassword,level,ip,serial,money,bank")
  92.                 outputChatBox("#FF0000Your account has been successfully created!#FFFFFF(User: "..tostring(userName)..", Password: "..tostring(password)..")",client,255,0,0,true)
  93.                 triggerClientEvent("onRegisterDone",getRootElement())
  94.             end
  95.         end
  96.     end
  97. end
  98.  
  99. addEvent("onClientRegisterFinish",true)
  100. addEventHandler("onClientRegisterFinish",getRootElement(),registerPlayer)
  101. --playerquit saves all your stats on your Quit to prevent statsloss
  102. function playerQuit(player)
  103.     local playerMoney = getPlayerMoney(source)
  104.     local playerSerial = getPlayerSerial(source)
  105.     local accountName = executeSQLQuery("SELECT accountname FROM accounts WHERE serial=?",playerSerial)
  106.     local onlineStatus = 0
  107.     if (type(accountName) == "table") and (#accountName == 1) then
  108.         for k,account in ipairs(accountName) do
  109.             executeSQLUpdate("accounts","money='"..playerMoney.."',online='"..onlineStatus.."'","accountname='"..account.accountname.."'")
  110.         end
  111.         local attached = getAttachedElements ( source )
  112.         if ( attached ) then
  113.             for k,element in ipairs(attached) do
  114.                 if getElementType ( element ) == "blip" then
  115.                     destroyElement ( element )
  116.                 end
  117.             end
  118.         end
  119.     end
  120. end
  121. addEventHandler("onPlayerQuit",getRootElement(),playerQuit)
  122.  
  123. --Change your accountpassword if you forgot it ( JUST WORKS if your serial is the same )
  124. function changeAccountPW(source,command,newPassword)
  125.     local playerSerial = getPlayerSerial(source)
  126.     local getAccountToChangePW = executeSQLQuery("SELECT * FROM accounts WHERE serial=?",playerSerial)
  127.     if newPassword == nil or newPassword == false then
  128.         outputChatBox("Please fill out all gaps!",source,255,0,0)
  129.         return
  130.     end
  131.     if (type(getAccountToChangePW)== "table") and (#getAccountToChangePW == 1) then
  132.         if (string.len(newPassword) >= 6 ) then
  133.             for k,getAccountChangePW in ipairs(getAccountToChangePW)do
  134.                 executeSQLUpdate("accounts","accountpassword='"..md5(newPassword).."'","serial='"..getAccountChangePW.serial.."'")
  135.                 outputChatBox("#FF0000Your password has been successfully changed to#FFFFFF("..newPassword..")!",source,255,0,0,true)
  136.             end
  137.         else
  138.             outputChatBox("#FF0000Your password is too short!#FFFFFF ( Min 6 letters! )",source,255,0,0,true)
  139.         end
  140.     else
  141.         outputChatBox("No account with your serial found!",source,255,0,0)
  142.     end
  143. end
  144. addCommandHandler("npw",changeAccountPW)
Add Comment
Please, Sign In to add comment