Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. ------------------------------------------------------------------------------------
  2. -- COMMUNITY CONTRIBUTION FOR CIT2.NET
  3. -- PURPOSE: Feedback for the updates
  4. -- DEVELOPERS: Nikos, Zelda - ( Server side )
  5. ------------------------------------------------------------------------------------
  6.  
  7. local con = dbConnect("mysql", "dbname=;host=", "", "")
  8. -- local con = dbConnect("sqlite", "//feedbacks.db")
  9. dbExec(con, "CREATE TABLE IF NOT EXISTS feedbacks (update_post TEXT, message TEXT)")
  10.  
  11. local antibug1 = { -- with this we filter and remove the months with the year. example August 2018. If we do not do this the gridlist will show the dates.
  12. "January", "February", "March", "April", "May", "June", "July",
  13. "August", "September", "October", "November", "December",
  14. }
  15.  
  16. local antibug2 = { -- with this we can fix the error caused by detecting something like this inside the string (-30 decreased).
  17. "a","b","c","d","e","f","g","h","i","j","k","l","m",
  18. "n","o","p","k","r","s","t","u","v","w","x","y","z",
  19. "1","2","3","4","5","6","7","8","9","10",
  20. }
  21.  
  22. local startAge, endAge = 2018, 2070 -- Years filter
  23.  
  24. function processUpdates(data)
  25. local cache = {}
  26. local updates = ""..data..""
  27. for k = startAge, endAge do
  28. for index, v in ipairs(antibug1) do
  29. updates = string.gsub(updates, ""..v.." "..k.."", "")
  30. end
  31. end
  32. local updates = string.gsub(updates, "\n", "")
  33. local updates = string.gsub(updates, "\r", "")
  34. for i, v in ipairs(antibug2) do
  35. updates = string.gsub(updates, "-"..v.."", "~"..v.."")
  36. end
  37. local ent = split(updates, "-") or {}
  38. for i, v in ipairs(ent) do
  39. table.insert(cache, ""..i..". "..v)
  40. end
  41. return cache
  42. end
  43.  
  44. function getUpdatesList(player)
  45. if (isGuestAccount(getPlayerAccount(player))) then
  46. return false
  47. end
  48. if (exports.CITchecking:getPlayerTimeSinceLastOccurence(player, "feedback") < 3000) then
  49. return false
  50. end
  51. local conversion = processUpdates(exports.CITupdatesInfo:getUpdates()) or {}
  52. exports.CITchecking:setPlayerOccurenceTime(player, "feedback")
  53. if (#conversion == 0) then
  54. outputChatBox("The feedback list is not loaded yet, retry later.", player, 255, 0, 0)
  55. else
  56. triggerClientEvent(player, "CITfeedback.sendFeedbackList", player, conversion)
  57. end
  58. end
  59. addCommandHandler("feedback", getUpdatesList)
  60.  
  61. function sendFeedback(message, update)
  62. if (isGuestAccount(getPlayerAccount(client))) then
  63. return false
  64. end
  65. local name = getPlayerName(client)
  66. local accname = getAccountName(getPlayerAccount(client))
  67. local results = dbPoll(dbQuery(con, "SELECT * FROM feedbacks WHERE update_post=?", update) ,-1)
  68. if (#results == 0) then
  69. local cc = "- "..name.." ("..accname..")\n"..message..""
  70. dbExec(con,"INSERT INTO feedbacks VALUES (?, ?)", update, cc, accname)
  71. exports.CIThelp:dm("Feedback sended", client, 0, 255, 0)
  72. else
  73. if (string.find(results[1]["message"], "("..accname..")")) then
  74. exports.CIThelp:dm("You have already made a comment to this update.", client, 255, 0, 0)
  75. return false
  76. end
  77. local cc = ""..results[1]["message"].."\n- "..name.." ("..accname..")\n"..message..""
  78. dbExec(con, "UPDATE feedbacks SET message=? WHERE update_post=?", cc, update)
  79. exports.CIThelp:dm("Feedback sended", client, 0, 255, 0)
  80. end
  81. end
  82. addEvent("CITfeedback.sendFeedback", true )
  83. addEventHandler("CITfeedback.sendFeedback", root, sendFeedback)
  84.  
  85. function getGridData(update)
  86. local result = dbPoll( dbQuery(con, "SELECT * FROM feedbacks WHERE update_post=?", update) , -1)
  87. if (type(result) == "table" and #result ~= 0) then
  88. triggerClientEvent(client, "CITfeedback.sendGridData", client, result[1]["message"])
  89. else
  90. triggerClientEvent(client, "CITfeedback.sendGridData", client, "No comments yet.")
  91. end
  92. end
  93. addEvent("CITfeedback.getGridData", true )
  94. addEventHandler("CITfeedback.getGridData", root, getGridData)
  95.  
  96. function cleanDB(player)
  97. if exports.CITadmin:getPlayerAdminLevel(player) == 5 then
  98. dbExec(con, "DELETE FROM feedbacks")
  99. exports.CIThelp:dm("Feedback cleaned", player, 255, 255, 0)
  100. end
  101. end
  102. addCommandHandler("cleancomments", cleanDB)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement