Advertisement
Guest User

Server

a guest
Aug 21st, 2019
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.70 KB | None | 0 0
  1. exports.SCmysql:exec("CREATE TABLE IF NOT EXISTS accounts (id INT, username TEXT, password LONGTEXT, pin TEXT, email TEXT, serial TEXT, dateJoined TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)")
  2. exports.SCmysql:exec("CREATE TABLE IF NOT EXISTS accountsData (username TEXT, data LONGTEXT)")
  3.  
  4. function register (plr, user, pass, email, pin)
  5.  
  6.     local hashedPass = sha256(pass)
  7.     local query = exports.SCmysql:query("SELECT * FROM accounts")
  8.     local accQuery = exports.SCmysql:query("SELECT * FROM accounts WHERE username=?", user)
  9.     local serQuery = exports.SCmysql:query("SELECT * FROM accounts WHERE serial=?", getPlayerSerial(plr))
  10.     if (#accQuery > 0) then return triggerClientEvent(plr, "SCaccounting:fail", plr, "Registration has failed, Account Already Exists!") end
  11.     if (#accQuery > 1) then return triggerClientEvent(plr, "SCaccounting:fail", plr, "Registration has failed, You can only register 2 accounts per serial!") end
  12.     local exec = exports.SCmysql:exec("INSERT INTO accounts (id, username, password, pin, email, serial) VALUES (?,?,?,?,?,?)", #query+1, user, hashedPass, pin, email, getPlayerSerial(plr))
  13.     local data = {
  14.  
  15.         ['cash'] = 50000,
  16.         ['health'] = 100,
  17.         ['armor'] = 100,
  18.         ['location'] = toJSON({1480.9766845703, -1770.2244873047, 18.795755386353}),
  19.         ['team'] = "Citizens",
  20.         ['occupation'] = "New Citizen",
  21.         ['skin'] = 0,
  22.         ['rotation'] = 0,
  23.         ['interior'] = 0,
  24.         ['dimension'] = 0,
  25.     }
  26.     local exec2 = exports.SCmysql:exec("INSERT INTO accountsData (username, data) VALUES (?,?)", user, toJSON(data))
  27.     if (exec) then
  28.         triggerClientEvent(plr, "SCaccounting:success", plr)
  29.     else
  30.         triggerClientEvent(plr, "SCaccounting:fail", plr, "Registration has failed, try contacting any developer or report on forums !")
  31.     end
  32.  
  33. end
  34. addEvent("SCaccounting:RegisterPlayer", true)
  35. addEventHandler("SCaccounting:RegisterPlayer", root, register)
  36.  
  37.  
  38. function login (plr, user, pass)
  39.  
  40.     local hashedPass = sha256(pass)
  41.     local accQuery = exports.SCmysql:query("SELECT * FROM accounts WHERE username=?", user)
  42.     local emailQuery = exports.SCmysql:query("SELECT * FROM accounts WHERE email=?", user)
  43.     if (#accQuery > 0) then
  44.         accPass = accQuery[1].password
  45.         accUser = user
  46.     elseif (#emailQuery > 0) then
  47.         accPass = emailQuery[1].password
  48.         accUser = emailQuery[1].username
  49.     else
  50.         triggerClientEvent(plr, "SCaccounting:fail", plr, "Signing in has failed, Account not found !")
  51.     end
  52.     iprint(hashedPass, accUser, accPass)
  53.     if (hashedPass == accPass) then
  54.         local data = exports.SCmysql:query("SELECT * FROM accountsData WHERE username=?", accUser)
  55.         local dataTable = fromJSON(data[1].data)
  56.         local x,y,z = unpack(fromJSON(dataTable['location']))
  57.         spawnPlayer(plr, x,y,z, dataTable.rotation, dataTable.skin, dataTable.interior or 0, dataTable.dimension or 0, getTeamFromName(dataTable.team))
  58.         setElementData(plr, "Occupation", dataTable.occupation)
  59.         setElementHealth(plr, dataTable.health)
  60.         setPlayerArmor(plr, dataTable.armor)
  61.         givePlayerMoney(plr, dataTable.cash)
  62.         setElementData(plr, "logged in", true)
  63.         setElementData(plr, "accName", accUser)
  64.         iprint("logged in")
  65.         fadeCamera(plr, true)
  66.         setCameraTarget(plr, plr)
  67.     else
  68.         triggerClientEvent(plr, "SCaccounting:fail", plr, "Signing in has failed, Wrong Password !")
  69.     end
  70. end
  71. addEvent("SCaccounting:LoginPlayer", true)
  72. addEventHandler("SCaccounting:LoginPlayer", root, login)
  73.  
  74.  
  75. function saveDataWhenQuit ()
  76.  
  77.     local user = getElementData(source, "accName")
  78.     if (user == false) then return false end
  79.     local money = getPlayerMoney(source)
  80.     local team = getTeamName(getPlayerTeam(source))
  81.     local x,y,z = getElementPosition(source)
  82.     local rot = getElementRotation(source)
  83.     local dim = getElementDimension(source)
  84.     local int = getElementInterior(source)
  85.     local skin = getElementModel(source)
  86.     local health = getElementHealth(source)
  87.     local armor = getPlayerArmor(source)
  88.     local occupation = getElementData(source, "Occupation")
  89.     exports.SCaccounting:setPlayerData(source, "cash", money)
  90.     exports.SCaccounting:setPlayerData(source, "health", health)
  91.     exports.SCaccounting:setPlayerData(source, "team", team)
  92.     exports.SCaccounting:setPlayerData(source, "occupation", occupation)
  93.     exports.SCaccounting:setPlayerData(source, "armor", armor)
  94.     exports.SCaccounting:setPlayerData(source, "rotation", rot)
  95.     exports.SCaccounting:setPlayerData(source, "dimension", dim)
  96.     exports.SCaccounting:setPlayerData(source, "interior", int)
  97.     exports.SCaccounting:setPlayerData(source, "skin", skin)
  98.     exports.SCaccounting:setPlayerData(source, "location", toJSON({x,y,z}))
  99. end
  100. addEventHandler("onPlayerQuit", root, saveDataWhenQuit)
  101.  
  102.  
  103. function saveMyData (plr, cmd)
  104.  
  105.     local user = getElementData(plr, "accName")
  106.     if (user == false) then return false end
  107.     local money = getPlayerMoney(plr)
  108.     local team = getTeamName(getPlayerTeam(plr))
  109.     local x,y,z = getElementPosition(plr)
  110.     local rot = getElementRotation(plr)
  111.     local dim = getElementDimension(plr)
  112.     local int = getElementInterior(plr)
  113.     local skin = getElementModel(plr)
  114.     local health = getElementHealth(plr)
  115.     local armor = getPlayerArmor(plr)
  116.     local occupation = getElementData(plr, "Occupation")
  117.     exports.SCaccounting:setPlayerData(plr, "cash", money)
  118.     exports.SCaccounting:setPlayerData(plr, "health", health)
  119.     exports.SCaccounting:setPlayerData(plr, "team", team)
  120.     exports.SCaccounting:setPlayerData(plr, "occupation", occupation)
  121.     exports.SCaccounting:setPlayerData(plr, "armor", armor)
  122.     exports.SCaccounting:setPlayerData(plr, "rotation", rot)
  123.     exports.SCaccounting:setPlayerData(plr, "dimension", dim)
  124.     exports.SCaccounting:setPlayerData(plr, "interior", int)
  125.     exports.SCaccounting:setPlayerData(plr, "skin", skin)
  126.     exports.SCaccounting:setPlayerData(plr, "location", toJSON({x,y,z}))
  127. end
  128. addCommandHandler("save", saveMyData)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement