Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. -- Created by: Kutak Roland
  2. -- Help: Jankovics Patrik
  3.  
  4. -- Local variables
  5.  
  6. local DISALLOWED_ROW_NAMES = {password = true, username = true, serial = true, pos = true, int = true, dim = true}
  7. local connection = exports["kutak_mysql"]:getConnection()
  8. local infobox = exports["kutak_infobox"]
  9.  
  10. -- Functions
  11.  
  12. addEvent("register", true)
  13. addEventHandler("register", getRootElement(), function(username, password)
  14. dbQuery(function(qh, client, username, password)
  15. local result, affected = dbPoll(qh, 0)
  16. result = result[1]
  17. if (result) then
  18. if (result.username==username) then
  19. infobox:createServerBox(client, "Ezzel a felhasználónévvel már valaki regisztrált!", "alert")
  20. elseif (result.serial==getPlayerSerial(client)) then
  21. --infobox:createServerBox(client, "Már van egy karaktered!", "alert")
  22. end
  23. else
  24. dbExec(connection, "INSERT INTO accounts SET username = ?, password = ?, serial = ?", username, sha256(password), getPlayerSerial(client))
  25. end
  26. end, {client, username, password}, connection, "SELECT serial, username FROM accounts WHERE serial=? OR username=? LIMIT 1", getPlayerSerial(client), username)
  27. end)
  28.  
  29. addEvent("loadchar", true)
  30. addEventHandler("loadchar", root, function(charid)
  31. dbQuery(function(qh, client)
  32. local result, aff, pos, intdim = dbPoll(qh, 0)
  33. if (aff>0) then
  34. for rowName, rowValue in pairs(result) do
  35. if not DISALLOWED_ROW_NAMES[rowName] then
  36. setElementData(client, "char:"..rowName, rowValue)
  37. elseif rowName == "pos" then
  38. pos = fromJSON(rowValue)
  39. elseif rowName == "intdim" then
  40. intdim = fromJSON(rowValue)
  41. end
  42. end
  43. --infobox:createServerBox(source, "Sikeres karakterválasztás!", "alert") TODO Kliensoldara
  44. setTimer(spawnPlayer, 3000, 1, client, Vector3(unpack(pos)), 0, skin, unpack(intdim))
  45. triggerClientEvent(thePlayer, "changepanel", thePlayer, "spawnPlayer")
  46. --[[
  47. TODO Klienshez betteni spawnPlayer changepanelhoz
  48. setTimer(function()
  49. setElementData(thePlayer, "showHUD", true)
  50. setElementData(thePlayer, "showScore", true)
  51. clearChat()
  52. showChat(thePlayer, true)
  53. end, 6000, 1)
  54.  
  55. setTimer(function()
  56. setElementData(thePlayer, "showRadar", true)
  57. end, 8000, 1)
  58. ]]
  59. else
  60. infobox:createServerBox(source, "Túl sok a hekk!", "alert")
  61. end
  62. end, {client}, connection, "SELECT * FROM profiles WHERE id=? AND ownerid=? LIMIT 1", charid, getElementData(client, "acc:id"))
  63. end)
  64.  
  65. addEvent("login", true)
  66. addEventHandler("login", getRootElement(), function(username, password)
  67. dbQuery(function(qh, client)
  68. local result, aff = dbPoll(qh, 0)
  69. if (aff>0) then
  70. for rowName, rowValue in pairs(result) do
  71. if not (DISALLOWED_ROW_NAMES[rowName]) then
  72. setElementData(client, "acc:"..rowName, rowValue)
  73. end
  74. end
  75. sendAvailableCharsListToClient(client)
  76. else
  77. infobox:createServerBox(source, "Hibás felhasználónév vagy jelszó!", "alert")
  78. end
  79. end, {client}, connection, "SELECT * FROM profiles WHERE username=? AND password=? LIMIT 1", username, sha256(password))
  80. end)
  81.  
  82. addEvent("createProfile", true)
  83. addEventHandler("createProfile", root, function(name, weight, height, age, skin, avatar, company, logo)
  84. dbQuery(function(qh, client)
  85. local result, aff = dbPoll(qh, 0)
  86. if (aff==0) then
  87. if dbExec(connection, "INSERT INTO profiles SET name=?, weight=?, height=?, age=?, skin=?, avatar=?, company=?, logo=?, ownerid=?", name, weight, height, age, skin, avatar, company, logo, getElementData(client, "acc:id")) then
  88. sendAvailableCharsListToClient(client)
  89. end
  90. else
  91. exports["kutak_infobox"]:createServerBox("Ez a név már foglalt. Kérlek válassz másikat!", "alert")
  92. end
  93. end, {client}, connection, "SELECT * FROM profiles WHERE name = ?", name)
  94. end)
  95.  
  96. function sendAvailableCharsListToClient(client)
  97. dbQuery(function(qh, client)
  98. triggerClientEvent(client, "setAvailableCharsList", client, dbPoll(qh, 0))
  99. end, {client}, connection, "SELECT * FROM profiles WHERE ownerid=?", getElementData(client, "acc:id"))
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement