Guest User

lip

a guest
Sep 8th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.17 KB | None | 0 0
  1. local key="lipAPI.public_key"
  2. local id = os.getComputerID()
  3. local channel = 5480
  4. local timeout = 5
  5. function setTimeout(n)
  6.     if not tonumber(n) or n<=0 then
  7.         error("Timeout should be a positive number",2)
  8.         exit()
  9.     end
  10.     timeout = math.max(.1,tonumber(n))
  11. end
  12. local function request(_p)
  13.     local modem = peripheral.find("modem", function(name, object) return object.isWireless() end)
  14.     if not modem then
  15.         error("Not found: wireless modem",2)
  16.         exit()
  17.     end
  18.     local data = {key,_p}
  19.     local keepOpen = modem.isOpen(id)
  20.     if not keepOpen then modem.open(id) end
  21.     local _timeout = os.startTimer(timeout)
  22.     modem.transmit(channel,id,data)
  23.     while true do
  24.         local e, p, to, from, result, dist = os.pullEvent()
  25.         if e=="modem_message" and to==id and from==channel then
  26.             if not keepOpen then modem.close(id) end
  27.             if result[1] then
  28.                 return result[2]
  29.             else
  30.                 error(result[2],2)
  31.                 exit()
  32.             end
  33.         elseif e=="timer" and p==_timeout then
  34.             error("408 Request Timeout",2)
  35.             exit()
  36.         end
  37.     end
  38. end
  39.  
  40. WorldInterface = {
  41.     getBiome = function(x,y,z) return request({"WorldInterface","getBiome",x,y,z}) end,
  42.     getWeather = function() return request({"WorldInterface","getWeather"}) end,
  43.     getBlockInfos = function(x,y,z) return request({"WorldInterface","getBlockInfos",x,y,z}) end,
  44.     getBlockDatatags = function(x,y,z) return request({"WorldInterface","getBlockDatatags",x,y,z}) end,
  45.     getRealDate = function() return request({"WorldInterface","getRealDate"}) end,
  46.     getPlayerList = function() return request({"WorldInterface","getPlayerList"}) end,
  47.     getMethods = function(str) if str then return request({"WorldInterface","getMethods",str}) else return request({"WorldInterface","getMethods"}) end end,
  48. }
  49. EntityDetector = {
  50.     getEntityList = function(r,x,y,z) return request({"EntityDetector","getEntityList",r,x,y,z}) end,
  51.     getEntityListAdvanced = function(r,x,y,z) return request({"EntityDetector","getEntityListAdvanced",r,x,y,z}) end,
  52.     getPlayerDetail = function(name) return request({"EntityDetector","getPlayerDetail",name}) end,
  53.     getMethods = function(str) if str then return request({"EntityDetector","getMethods",str}) else return request({"EntityDetector","getMethods"}) end end,
  54. }
Advertisement
Add Comment
Please, Sign In to add comment