Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local connection = exports['fv_engine']:getConnection(getThisResource())
- local accounts = {}
- --[[
- Tábla felépítése:
- accounts[name] = {id, password, serial, email, regdate, lastlogin, ip}
- ]]
- local isSerialAttachedToAccount = {}
- --[[
- Tábla felépítése:
- isSerialAttachedToAccount[serial] = true
- ]]
- local isEmailAttachedToAccount = {}
- --[[
- Tábla felépítése:
- isEmailAttachedToAccount[email] = true
- ]]
- local idConvertToName = {}
- --[[
- Tábla felépítése:
- idConvertToName[id] = name
- ]]
- local isValidAccount = {}
- --[[
- Tábla felépítése:
- isValidAccount[name] = name
- ]]
- local isLogged = {}
- --[[
- Tábla felépítése:
- isLogged[name] = true
- ]]
- local characters = {}
- --[[
- Tábla felépítése:
- characters[id] = {...}
- ]]
- local getAccountCharacterID = {}
- --[[
- Tábla felépítése:
- getAccountCharacterID[accountName] = id
- ]]
- local isAccountHaveCharacter = {}
- --[[
- Tábla felépítése:
- isAccountHaveCharacter[accountName] = true
- ]]
- local isNameRegistered = {}
- function receiveTables()
- -- triggerClientEvent(root, "giveBackToClient", root, accounts, characters)
- end
- addEvent("receiveTables", true)
- addEventHandler("receiveTables", root, receiveTables)
- addEventHandler("onResourceStart", resourceRoot,
- function()
- dbQuery(function(query)
- local query, query_lines = dbPoll(query, 0)
- if query_lines > 0 then
- for k, row in pairs (query) do
- local id = tonumber(row["id"])
- local name = tostring(row["name"])
- local email = tostring(row["email"])
- local password = tostring(row["password"])
- local serial = tostring(row["serial"])
- local ip = tostring(row["ip"])
- local registerdatum = tostring(row["registerdatum"])
- local lastlogin = tostring(row["lastlogin"])
- local online = tonumber(row["online"])
- if online == 1 then
- isLogged[name] = true
- else
- isLogged[name] = false
- end
- accounts[name] = {id, password, serial, email, registerdatum, lastlogin, ip}
- isValidAccount[name] = true
- isSerialAttachedToAccount[serial] = true
- isEmailAttachedToAccount[email] = true
- idConvertToName[id] = name
- end
- end
- receiveTables()
- outputDebugString("[Success] Loading accounts has finished successfuly. Loaded: " .. query_lines .. " accounts!")
- end, connection, "SELECT * FROM `accounts`")
- end
- )
- addEventHandler("onResourceStart", resourceRoot,
- function()
- dbQuery(function(query)
- local query, query_lines = dbPoll(query, 0)
- if query_lines > 0 then
- for k, row in pairs (query) do
- local id = tonumber(row["id"])
- local ownerName = tostring(row["ownerAccountName"])
- local charname = tostring(row["charname"])
- local position = tostring(row["position"])
- local health = tonumber(row["health"])
- local armor = tonumber(row["armor"])
- local skinid = tonumber(row["skinid"])
- local pedType = tostring(row["pedType"])
- local pedType2 = tostring(row["pedType2"])
- local age = tonumber(row["age"])
- local weight = tonumber(row["weight"])
- local height = tonumber(row["height"])
- local fightStyle = tonumber(row["fightStyle"])
- local walkStyle = tonumber(row["walkStyle"])
- local money = tonumber(row["money"])
- local bankmoney = tonumber(row["bankmoney"])
- local death = tostring(row["death"])
- local headless = tostring(row["headless"])
- local playedtime = tonumber(row["playedtime"])
- local premiumPoints = tonumber(row["premiumPoints"])
- local adminlevel = tonumber(row["adminlevel"])
- local job = tonumber(row["job"])
- local rot = tonumber(row["rot"])
- local adminduty = tostring(row["adminduty"])
- local food = tostring(row["food"])
- local drink = tostring(row["drink"])
- local adminname = tostring(row["adminname"])
- local level = tonumber(row["level"])
- local deathReasons = tostring(row["deathReasons"])
- local bone = tostring(row["bone"])
- local adutytime = tonumber(row["adutytime"])
- local rtc = tonumber(row["rtc"])
- local fix = tonumber(row["fix"])
- local fuel = tonumber(row["fuel"])
- local ban = tonumber(row["ban"])
- local jail = tonumber(row["jail"])
- local kick = tonumber(row["kick"])
- characters[id] = {
- ["ownerName"] = ownerName,
- ["charName"] = charname,
- ["position"] = position,
- ["health"] = health,
- ["armor"] = armor,
- ["skinid"] = skinid,
- ["pedType"] = pedType,
- ["pedType2"] = pedType2,
- ["age"] = age,
- ["weight"] = weight,
- ["height"] = height,
- ["fightStyle"] = fightStyle,
- ["walkStyle"] = walkStyle,
- ["money"] = money,
- ["bankmoney"] = bankmoney,
- ["death"] = death,
- ["headless"] = headless,
- ["playedtime"] = playedtime,
- ["premiumPoints"] = premiumPoints,
- ["adminlevel"] = adminlevel,
- ["job"] = job,
- ["rot"] = rot,
- ["adminduty"] = adminduty,
- ["food"] = food,
- ["drink"] = drink,
- ["adminname"] = adminname,
- ["level"] = level,
- ["deathReasons"] = deathReasons,
- ["bone"] = bone,
- ["adutytime"] = adutytime,
- ["rtc"] = rtc,
- ["fix"] = fix,
- ["fuel"] = fuel,
- ["jail"] = jail,
- ["ban"] = ban,
- ["kick"] = kick,
- }
- getAccountCharacterID[ownerName] = id
- isAccountHaveCharacter[ownerName] = true
- isNameRegistered[charname] = true
- end
- end
- receiveTables()
- outputDebugString("[Success] Loading characters has finished successfuly. Loaded: " .. query_lines .. " characters!")
- end, connection, "SELECT * FROM `characters`")
- end
- )
- addEvent("account >> register", true)
- addEventHandler("account >> register", root,
- function(sourceElement, username, password, email)
- local serial = getPlayerSerial(sourceElement)
- if isSerialAttachedToAccount[serial] then
- exports.fv_infobox:addNotification(sourceElement, "error", "Ez a serial ("..serial..") már társítva van egy felhasználóhoz!")
- return
- end
- if isEmailAttachedToAccount[email] then
- exports.fv_infobox:addNotification(sourceElement, "error", "Ez az email ("..email..") már társítva van egy felhasználóhoz!")
- return
- end
- if isValidAccount[username] then
- exports.fv_infobox:addNotification(sourceElement, "error", "Ez a felhasználónév ("..username..") már regisztrálva lett!")
- return
- end
- local hashPassword1 = hash("md5", password)
- local hashedPassword = hash("sha512", hashPassword1)
- local ip = getPlayerIP(sourceElement)
- local serial = getPlayerSerial(sourceElement)
- dbExec(connection, "INSERT INTO `accounts` SET `name` = ?, `email` = ?, `password` = ?, `serial` = ?, `ip` = ?, `registerdatum` = NOW(), `lastlogin` = NOW()", username, email, hashedPassword, serial, ip)
- dbQuery(function(query)
- local query, query_lines = dbPoll(query, 0)
- if query_lines > 0 then
- for k, row in pairs (query) do
- local id = tonumber(row["id"])
- local name = tostring(row["name"])
- local email = tostring(row["email"])
- local password = tostring(row["password"])
- local serial = tostring(row["serial"])
- local ip = tostring(row["ip"])
- local registerdatum = tostring(row["registerdatum"])
- local lastlogin = tostring(row["lastlogin"])
- accounts[name] = {id, password, serial, email, regdate, lastlogin, ip}
- isValidAccount[name] = true
- isSerialAttachedToAccount[serial] = true
- isEmailAttachedToAccount[email] = true
- idConvertToName[id] = name
- exports.fv_infobox:addNotification(sourceElement, "success", "Sikeres regisztráció most már beléphetsz!")
- end
- receiveTables()
- end
- end, connection, "SELECT * FROM `accounts` WHERE `name` = ?", username)
- end
- )
- addEvent("account >> login", true)
- addEventHandler("account >> login", root,
- function(sourceElement, username, password)
- if not isValidAccount[username] then
- exports.fv_infobox:addNotification(sourceElement, "error", "Ez a felhasználónév ("..username..") nincs regisztrálva!")
- return
- end
- if isLogged[username] then
- exports.fv_infobox:addNotification(sourceElement, "error", "Ez a felhasználó ("..username..") már használatban van!")
- return
- end
- local data = accounts[username]
- local id = data[1]
- local realPassword = data[2]
- local serial = data[3]
- local lastlogin = data[6]
- local registerdatum = data[5]
- local mtaserial = getPlayerSerial(sourceElement)
- if string.lower(serial) ~= string.lower(mtaserial) then
- if tonumber(serial) == "0" or tonumber(serial) == 0 then
- dbExec(connection, "UPDATE `accounts` SET `serial`=? WHERE `id`=?", mtaserial, id)
- accounts[username][3] = mtaserial
- else
- exports.fv_infobox:addNotification(sourceElement, "error", "A te serialod ("..serial..") nem ehhez a felhasználóhoz van társítva!")
- return
- end
- end
- local hashedPassword = hash("md5", password)
- local hashedPassword2 = hash("sha512", hashedPassword)
- if string.lower(realPassword) ~= string.lower(hashedPassword2) then
- exports.fv_infobox:addNotification(sourceElement, "error", "Hibás jelszó!")
- return
- end
- isLogged[username] = true
- dbExec(connection, "UPDATE `accounts` SET `lastlogin`=NOW(), `online`=? WHERE `id`=?", 1, id)
- dbQuery(function(query)
- local query, query_lines = dbPoll(query, 0)
- if query_lines > 0 then
- for k, row in pairs (query) do
- local lastlogin = tostring(row["lastlogin"])
- accounts[username][6] = lastlogin
- end
- receiveTables()
- end
- end, connection, "SELECT * FROM `accounts` WHERE `id` = ?", id)
- dbQuery(function(query)
- local query, query_lines = dbPoll(query, 0)
- if query_lines > 0 then
- for k, row in pairs (query) do
- local premiumPoints = tostring(row["premiumPoints"])
- characters[id]["premiumPoints"] = premiumPoints
- end
- receiveTables()
- end
- end, connection, "SELECT * FROM `characters` WHERE `id` = ?", id)
- setElementData(sourceElement, "acc >> loggedIn", true)
- setElementData(sourceElement, "acc >> id", id)
- setElementData(sourceElement, "acc >> username", username)
- if isAccountHaveCharacter[username] then
- --Betöltés
- local id = getAccountCharacterID[username]
- local data = characters[id]
- triggerClientEvent(sourceElement, "character >> loading", sourceElement, data, lastlogin, id, registerdatum)
- else
- --Karakter létrehozása
- triggerClientEvent(sourceElement, "character >> create", sourceElement)
- end
- end
- )
- addEvent("character >> register", true)
- addEventHandler("character >> register", root,
- function(sourceElement, name, age, weight, height, skinid, pedType, pedType2)
- if isNameRegistered[name] then
- exports.fv_infobox:addNotification(sourceElement, "error", "Ez a név már használatban van!")
- return
- end
- local id = getElementData(sourceElement, "acc >> id")
- local username = getElementData(sourceElement, "acc >> username")
- dbExec(connection, "INSERT INTO `characters` SET `id` = ?, `ownerAccountName` = ?, `charname` = ?, `age` = ?, `weight` = ?, `height` = ?, `skinid` = ?, `pedType` = ?, `pedType2` = ?", id, username, name, age, weight, height, skinid, pedType, pedType2)
- dbQuery(function(query)
- local query, query_lines = dbPoll(query, 0)
- if query_lines > 0 then
- --for i, row in pairs(query) do
- for k, row in pairs (query) do
- local id = tonumber(row["id"])
- local ownerName = tostring(row["ownerAccountName"])
- local charname = tostring(row["charname"])
- local position = tostring(row["position"])
- local health = tonumber(row["health"])
- local armor = tonumber(row["armor"])
- local skinid = tonumber(row["skinid"])
- local pedType = tostring(row["pedType"])
- local pedType2 = tostring(row["pedType2"])
- local age = tonumber(row["age"])
- local weight = tonumber(row["weight"])
- local height = tonumber(row["height"])
- local fightStyle = tonumber(row["fightStyle"])
- local walkStyle = tonumber(row["walkStyle"])
- local money = tonumber(row["money"])
- local bankmoney = tonumber(row["bankmoney"])
- local death = tostring(row["death"])
- local headless = tostring(row["headless"])
- local playedtime = tonumber(row["playedtime"])
- local premiumPoints = tonumber(row["premiumPoints"])
- local adminlevel = tonumber(row["adminlevel"])
- local job = tonumber(row["job"])
- local rot = tonumber(row["rot"])
- local adminduty = tostring(row["adminduty"])
- local adminname = tostring(row["adminname"])
- local food = tostring(row["food"])
- local drink = tostring(row["drink"])
- local level = tonumber(row["level"])
- local deathReasons = tostring(row["deathReasons"])
- local bone = tostring(row["bone"])
- local adutytime = tonumber(row["adutytime"])
- local rtc = tonumber(row["rtc"])
- local fix = tonumber(row["fix"])
- local fuel = tonumber(row["fuel"])
- local ban = tonumber(row["ban"])
- local jail = tonumber(row["jail"])
- local kick = tonumber(row["kick"])
- characters[id] = {
- ["ownerName"] = ownerName,
- ["charName"] = charname,
- ["position"] = position,
- ["health"] = health,
- ["armor"] = armor,
- ["skinid"] = skinid,
- ["pedType"] = pedType,
- ["pedType2"] = pedType2,
- ["age"] = age,
- ["weight"] = weight,
- ["height"] = height,
- ["fightStyle"] = fightStyle,
- ["walkStyle"] = walkStyle,
- ["money"] = money,
- ["bankmoney"] = bankmoney,
- ["death"] = death,
- ["headless"] = headless,
- ["playedtime"] = playedtime,
- ["premiumPoints"] = premiumPoints,
- ["adminlevel"] = adminlevel,
- ["job"] = job,
- ["rot"] = rot,
- ["adminduty"] = adminduty,
- ["food"] = food,
- ["drink"] = drink,
- ["adminname"] = adminname,
- ["level"] = level,
- ["deathReasons"] = deathReasons,
- ["bone"] = bone,
- ["adutytime"] = adutytime,
- ["rtc"] = rtc,
- ["fix"] = fix,
- ["fuel"] = fuel,
- ["jail"] = jail,
- ["ban"] = ban,
- ["kick"] = kick,
- }
- getAccountCharacterID[ownerName] = id
- isAccountHaveCharacter[ownerName] = true
- isNameRegistered[charname] = true
- local data = accounts[ownerName]
- local lastlogin = data[6]
- local registerdatum = data[5]
- exports.fv_infobox:addNotification(sourceElement, "success", "Sikeres karakterregisztráció most már beléphetsz!")
- --triggerClientEvent(sourceElement, "destroyCharCreate", sourceElement)
- local data = characters[id]
- triggerClientEvent(sourceElement, "character >> loading", sourceElement, data, lastlogin, id, registerdatum)
- end
- receiveTables()
- end
- end, connection, "SELECT * FROM `characters` WHERE `id` = ?", id)
- end
- )
- local isValid = {
- ["needSpawn"] = true,
- ["char >> skin"] = true,
- ["char >> fightStyle"] = true,
- ["char >> walkStyle"] = true,
- ["char >> death"] = true,
- ["char >> headless"] = true,
- ["char >> name"] = true,
- ["char >> armor"] = true,
- ["char >> death"] = true,
- }
- addEventHandler("onElementDataChange", root,
- function(dName, oValue)
- if getElementType(source) == "player" and isValid[dName] then
- if dName == "needSpawn" then
- local value = getElementData(source, dName)
- if value then
- local x,y,z, dim, int = unpack(getElementData(source, "char >> position"))
- local rot = getElementData(source, "char >> rot")
- local skinid = getElementData(source, "char >> skin")
- setElementModel(source, skinid)
- setElementRotation(source, 0,0,rot)
- setElementDimension(source, dim)
- setElementInterior(source, int)
- setElementPosition(source, x, y, z)
- spawnPlayer(source, x,y,z, rot, skinid, int, dim)
- setElementHealth(source, getElementData(source, "char >> health"))
- setElementFrozen(source, true)
- local source = source
- setTimer(
- function()
- setElementFrozen(source, false)
- end, 7000, 1
- )
- end
- elseif dName == "char >> skin" then
- local value = getElementData(source, dName)
- setElementModel(source, value)
- elseif dName == "char >> fightStyle" then
- local value = getElementData(source, dName)
- -- setPedFightingStyle(source, value)
- elseif dName == "char >> walkStyle" then
- local value = getElementData(source, dName)
- --setPedWalkingStyle(source, value)
- elseif dName == "char >> name" then
- local value = getElementData(source, dName)
- setPlayerName(source, value)
- local id = getElementData(source, "acc >> id")
- characters[id]["charName"] = value
- --receiveTables()
- elseif dName == "char >> armor" then
- local value = getElementData(source, dName)
- setPedArmor(source, value)
- elseif dName == "char >> headless" then
- local value = getElementData(source, dName)
- setPedHeadless(source, value)
- end
- end
- end
- )
- addEventHandler("onPlayerChangeNick", root,
- function(oldNick, newNick)
- if getElementData(source, "loggedIn") then
- cancelEvent()
- end
- end
- )
- addEventHandler("onPlayerQuit", root,
- function()
- savePlayer(source)
- end
- )
- addEventHandler("onResourceStop", resourceRoot,
- function()
- for k,v in pairs(getElementsByType("player")) do
- savePlayer(v)
- end
- end
- )
- local bones = pasz
- function savePlayer(source)
- if getElementData(source, "acc >> loggedIn") then
- local id = getElementData(source, "acc >> id")
- dbExec(connection, "UPDATE `accounts` SET `online`=? WHERE `id`=?", 0, id)
- local ownerName = idConvertToName[id]
- isLogged[ownerName] = false
- end
- if getElementData(source, "loggedIn") then
- local id = getElementData(source, "acc >> id")
- --isLogged[username] = true
- local dim = getElementDimension(source)
- if getElementData(source, "char >> death") or getElementData(source, "inDeath") then
- local oldDimension = getElementData(source, "oldDimension") or getElementDimension(source)
- dim = oldDimension
- end
- local int = getElementInterior(source)
- local x,y,z = getElementPosition(source)
- local position = toJSON({x,y,math.floor(z + 1), dim, int})
- local money = getElementData(source, "char >> money")
- local bankmoney = getElementData(source, "char >> bankmoney")
- local ax, ay, rot = getElementRotation(source)
- local skinid = getElementData(source, "char >> skin")
- local fightStyle = getElementData(source, "char >> fightStyle")
- local walkStyle = getElementData(source, "char >> walkStyle")
- local charname = getElementData(source, "char >> name")
- local health = getElementHealth(source)
- local armor = getPedArmor(source)
- local job = getElementData(source, "char >> job")
- local death = tostring(getElementData(source, "char >> death"))
- local headless = tostring(getElementData(source, "char >> headless"))
- local playedtime = getElementData(source, "char >> playedtime")
- local premiumPoints = getElementData(source, "char >> premiumPoints")
- local adminlevel = getElementData(source, "admin >> level")
- if adminlevel == 1 then
- adminlevel = 0
- end
- local adminduty = "false"
- local adminname = tostring(getElementData(source, "admin >> name"))
- local food = getElementData(source, "char >> food")
- local drink = getElementData(source, "char >> drink")
- local level = getElementData(source, "char >> level")
- local deathReason = getElementData(source, "deathReason") or "Ismeretlen"
- local deathReasonAdmin = getElementData(source, "deathReason >> admin") or "Ismeretlen"
- local deathReasons = toJSON({deathReason, deathReasonAdmin})
- local bones = getElementData(source, "char >> bone") or {true, true, true, true, true}
- bones = true
- local bone = toJSON(bones)
- local adutytime = getElementData(source, "admin >> time") or 0
- local rtc = getElementData(source, "rtc >> using") or 0
- local fix = getElementData(source, "fix >> using") or 0
- local fuel = getElementData(source, "fuel >> using") or 0
- local ban = getElementData(source, "ban >> using") or 0
- local jail = getElementData(source, "jail >> using") or 0
- local kick = getElementData(source, "kick >> using") or 0
- dbExec(connection, "UPDATE `characters` SET `position`=?, `charname`=?, `health`=?, `armor`=?, `skinid`=?, `fightStyle`=?, `walkStyle`=?, `money`=?, `bankmoney`=?, `death`=?, `headless`=?, `playedtime`=?, `premiumPoints`=?, `adminlevel`=?, `job`=?, `rot`=?, `adminduty`=?, `food`=?, `drink`=?, `level`=?, `adminname`=?, `deathReasons`=?, `bone`=?, `adutytime`=?, `rtc`=?, `fix`=?, `fuel`=?, `ban`=?, `jail`=?, `kick`=? WHERE `id`=?", position, charname, health, armor, skinid, fightStyle, walkStyle, money, bankmoney, death, headless, playedtime, premiumPoints, adminlevel, job, rot, adminduty, food, drink, level, adminname, deathReasons, bone, adutytime, rtc, fix, fuel, ban, jail, kick, id)
- local ownerName = idConvertToName[id]
- characters[id] = {
- ["ownerName"] = ownerName,
- ["charName"] = charname,
- ["position"] = position,
- ["health"] = health,
- ["armor"] = armor,
- ["skinid"] = skinid,
- ["pedType"] = pedType,
- ["pedType2"] = pedType2,
- ["age"] = age,
- ["weight"] = weight,
- ["height"] = height,
- ["fightStyle"] = fightStyle,
- ["walkStyle"] = walkStyle,
- ["money"] = money,
- ["bankmoney"] = bankmoney,
- ["death"] = death,
- ["headless"] = headless,
- ["playedtime"] = playedtime,
- ["premiumPoints"] = premiumPoints,
- ["adminlevel"] = adminlevel,
- ["job"] = job,
- ["rot"] = rot,
- ["adminduty"] = adminduty,
- ["food"] = food,
- ["drink"] = drink,
- ["adminname"] = adminname,
- ["level"] = level,
- ["deathReasons"] = deathReasons,
- ["bone"] = bone,
- ["adutytime"] = adutytime,
- ["rtc"] = rtc,
- ["fix"] = fix,
- ["fuel"] = fuel,
- ["jail"] = jail,
- ["ban"] = ban,
- ["kick"] = kick,
- }
- receiveTables()
- outputDebugString("[SG-Save]: " .. charname .. "("..id..") - saved succesfuly!", 0, 87,255,87)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement