Advertisement
wifiboost

Untitled

Mar 27th, 2023
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. include("autorun/server/mysql_config.lua")
  2. util.AddNetworkString("AdminRequest")
  3. util.AddNetworkString("AdminRequestAction")
  4. util.AddNetworkString("AdminRequestClaim")
  5. util.AddNetworkString("AdminRequestClaimData")
  6. util.AddNetworkString("RequestUpdatedAdminRequests")
  7. util.AddNetworkString("UpdatedAdminRequests")
  8. util.AddNetworkString("AdminRequestClose")
  9. util.AddNetworkString("RequestClaimData")
  10. adminClaimData = {}
  11. local adminRequests = {}
  12. local function GetAdmins()
  13. local adminGroups = {
  14. "trialmod", "moderator", "seniormod", "admin", "headadmin", "senioradmin", "council", "superadmin", "manager"
  15. }
  16. local admins = {}
  17. for _, ply in ipairs(player.GetAll()) do
  18. for _, group in ipairs(adminGroups) do
  19. if ply:IsUserGroup(group) then
  20. table.insert(admins, ply)
  21. break
  22. end
  23. end
  24. end
  25. return admins
  26. end
  27. local function IsAdminGroup(ply)
  28. local adminGroups = {
  29. "trialmod", "moderator", "seniormod", "admin", "headadmin", "senioradmin", "council", "superadmin", "manager"
  30. }
  31. for _, group in ipairs(adminGroups) do
  32. if ply:IsUserGroup(group) then
  33. return true
  34. end
  35. end
  36.  
  37. return false
  38. end
  39. hook.Add("PlayerSay", "AdminRequestSystem", function(ply, text, teamChat)
  40. if string.sub(text, 1, 1) == "@" then
  41. local requestData = {
  42. steamID64 = ply:SteamID64(),
  43. name = ply:Nick(),
  44. message = string.sub(text, 2),
  45. requestTime = CurTime()
  46. }
  47. table.insert(adminRequests, requestData) -- Save the request data to the adminRequests table
  48. net.Start("AdminRequest")
  49. net.WriteTable(requestData)
  50. net.Send(GetAdmins()) -- GetAdmins will now check for the specified user groups
  51. return "" -- Hide the message from the chat
  52. end
  53. end)
  54. local function getUpdatedAdminRequests()
  55. -- Return the contents of the adminRequests table
  56. return adminRequests
  57. end
  58. -- Handle admin actions
  59. local playerPreviousPositions = {}
  60. net.Receive("AdminRequestAction", function(len, ply)
  61. if not IsAdminGroup(ply) then return end -- Check if the player is in one of the admin groups
  62. local action = net.ReadString()
  63. local target = net.ReadEntity()
  64. if action == "goto" then
  65. playerPreviousPositions[ply:SteamID64()] = ply:GetPos()
  66. ply:SetPos(target:GetPos() + Vector(0, 0, 50))
  67. elseif action == "bring" then
  68. playerPreviousPositions[target:SteamID64()] = target:GetPos()
  69. target:SetPos(ply:GetPos() + ply:GetForward() * 100 + Vector(0, 0, 50))
  70. elseif action == "return" then
  71. local prevPos = playerPreviousPositions[target:SteamID64()]
  72. if prevPos then
  73. target:SetPos(prevPos)
  74. playerPreviousPositions[target:SteamID64()] = nil
  75. end
  76. end
  77. end)
  78. -- Initialize admin claim data table
  79. function UpdateAdminClaim(ply)
  80. local adminID = ply:SteamID64()
  81. local currentWeek = os.date("%U")
  82. local query = DBConnection:query("SELECT * FROM claim_data WHERE admin_id = '" .. adminID .. "'")
  83. query:start()
  84. query.onSuccess = function(_, data)
  85. if #data > 0 then
  86. local weeklyCount = data[1].weekly_count
  87. local totalCount = data[1].total_count
  88. local week = data[1].week
  89. if week ~= currentWeek then
  90. weeklyCount = 0
  91. week = currentWeek
  92. end
  93. weeklyCount = weeklyCount + 1
  94. totalCount = totalCount + 1
  95. local updateQuery = DBConnection:query("UPDATE claim_data SET weekly_count = " .. weeklyCount .. ", total_count = " .. totalCount .. ", week = " .. week .. " WHERE admin_id = '" .. adminID .. "'")
  96. updateQuery:start()
  97. updateQuery.onSuccess = function()
  98. print("Updated admin claim data successfully.")
  99. end
  100. updateQuery.onError = function(_, err)
  101. print("Failed to update admin claim data:", err)
  102. end
  103. else
  104. local insertQuery = DBConnection:query("INSERT INTO claim_data (admin_id, name, weekly_count, total_count, week) VALUES ('" .. adminID .. "', '" .. ply:Nick() .. "', 1, 1, " .. currentWeek .. ")")
  105. insertQuery:start()
  106. insertQuery.onSuccess = function()
  107. print("Inserted admin claim data successfully.")
  108. end
  109. insertQuery.onError = function(_, err)
  110. print("Failed to insert admin claim data:", err)
  111. end
  112. end
  113. end
  114. query.onError = function(_, err)
  115. print("Failed to retrieve admin claim data:", err)
  116. end
  117. end
  118. local adminClaimData = {}
  119. net.Receive("AdminRequestClaim", function(len, ply)
  120. if not IsAdminGroup(ply) then return end -- Check if the player is in one of the admin groups
  121.  
  122. local requestData = net.ReadTable() -- Add this line
  123. local adminID = ply:SteamID64()
  124. local currentDate = os.date("*t")
  125. local currentWeek = os.date("%U")
  126.  
  127. if not adminClaimData[adminID] then
  128. adminClaimData[adminID] = {
  129. name = ply:Nick(),
  130. totalCount = 0,
  131. weeklyCount = 0,
  132. week = currentWeek
  133. }
  134. end
  135. local data = adminClaimData[adminID]
  136. if data.week ~= currentWeek then
  137. data.weeklyCount = 0
  138. data.week = currentWeek
  139. end
  140. data.totalCount = data.totalCount + 1
  141. data.weeklyCount = data.weeklyCount + 1
  142. local requestData = net.ReadTable() -- Add this line
  143. UpdateAdminClaim(ply)
  144. end)
  145.  
  146. -- Handle claimed cases
  147. local function markCaseAsClaimed(caseIndex, adminID)
  148. adminRequests[caseIndex].claimedBy = adminID
  149. end
  150. net.Receive("RequestUpdatedAdminRequests", function(len, ply)
  151. -- Get updated admin requests here
  152. local updatedRequests = getUpdatedAdminRequests()
  153. net.Start("UpdatedAdminRequests")
  154. net.WriteTable(updatedRequests)
  155. net.Send(ply)
  156. end)
  157. net.Receive("AdminRequestClose", function(len, ply)
  158. if not IsAdminGroup(ply) then return end
  159. local requestData = net.ReadTable()
  160. local index = -1
  161. for i, request in ipairs(adminRequests) do
  162. if request.steamID64 == requestData.steamID64 and request.requestTime == requestData.requestTime then
  163. index = i
  164. break
  165. end
  166. end
  167. if index > 0 then
  168. table.remove(adminRequests, index)
  169. end
  170. end)
  171. net.Receive("RequestClaimData", function(_, ply)
  172. local fetchDataQuery = "SELECT * FROM claim_data;"
  173. local query = DBConnection:query(fetchDataQuery)
  174.  
  175. query:start()
  176.  
  177. query.onSuccess = function(_, data)
  178. net.Start("ReceiveClaimData")
  179. net.WriteTable(data)
  180. net.Send(ply)
  181. end
  182.  
  183. query.onError = function(_, err)
  184. print("Failed to fetch data from claim_data table:", err)
  185. end
  186. end)
  187. concommand.Add("show_claim_data", function(ply, cmd, args)
  188. if not IsAdminGroup(ply) then return end -- Check if the player is in one of the admin groups
  189. -- Send the claim data to the player who requested it
  190. net.Start("AdminRequestClaimData")
  191. net.WriteTable(adminClaimData)
  192. net.Send(ply)
  193. end)
  194.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement