Advertisement
iNxmi

Backrooms Code Server

May 12th, 2024 (edited)
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | Source Code | 0 0
  1. local socket = require "socket"
  2.  
  3. function generateCode()
  4.     local request = http.get(
  5.         "https://www.random.org/integers/?num=4&min=0&max=9&col=1&base=10&format=plain&rnd=new"
  6.     )
  7.  
  8.     local text = request.readAll()
  9.  
  10.     return string.gsub(text, "\n", "")
  11. end
  12.  
  13. local codes = {
  14.     pool_door = generateCode()
  15. }
  16. print(textutils.serializeJSON(codes))
  17.  
  18. function response(id, protocol, table)
  19.     local location = table["location"]
  20.     return codes[location]
  21. end
  22.  
  23. while true do
  24.     print("Listening on port " .. os.computerID())
  25.    
  26.     local id, protocol, table = socket.receive()
  27.     print(string.format("id=%s protocol=%s table=%s", id, protocol, table))
  28.     local response = response(id, protocol, table)
  29.    
  30.     local data = {success = false, error = "bad request"}
  31.     if response ~= nil then
  32.         data = {success = true, code = response}
  33.     end
  34.    
  35.     print(data)
  36.     socket.send(id, "code", data)
  37. end
  38.  
  39. print("Server stopped")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement