Advertisement
mikk809h

usage of the API

Aug 31st, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.36 KB | None | 0 0
  1.     while true do
  2.         local event, id, msg, dist = api.evt("rednet_message")
  3.             if string.find(msg, "update") then
  4.                 msg = string.sub(msg, string.len("update")+2)
  5.                 ids = textutils.unserialize(msg)
  6.                 if api.isID(id) then
  7.                     mesg = textutils.unserialize(msg)
  8.                 end
  9.             elseif string.find(msg, "apply") then  
  10.                 if api.isID(id) then
  11.                     msg = string.sub(msg, string.len("apply")+2)
  12.                     local _, _, user, pass = string.find(msg, "^(%w+)&pwd=(%w+)$")
  13.                     term.scroll(1)
  14.                     term.setTextColor(colors.yellow)
  15.                     print("Authenticating...")
  16.                     if api.isPermitted(user, pass) then -- using the API here, where it returns an error
  17.                         term.scroll(1)
  18.                         term.setTextColor(colors.lime)
  19.                         print("Authenticated!")
  20.                         api.send(id, encrypt.hash("OK"))
  21.                     else
  22.                         term.scroll(1)
  23.                         term.setTextColor(colors.lime)
  24.                         print("Not authenticated!")
  25.                         api.send(id, encrypt.hash("FAIL"))
  26.                        
  27.                     end
  28.  
  29.                     sleep(2)                   
  30.                 end
  31.             elseif msg == "ping" then
  32.                 term.scroll(1)
  33.                 term.setTextColor(colors.yellow)
  34.                 print("Got \"ping\" from "..id)
  35.                 if not api.isID(id) then
  36.                     api.saveID(id)
  37.                     term.scroll(1)
  38.                     term.setTextColor(colors.lime)
  39.                     print("Saved ID of client")
  40.                 end
  41.                 api.send(id, "pong")
  42.                 term.scroll(1)
  43.                 term.setTextColor(colors.lime)
  44.                 print("Successfully sended \"pong\"")  
  45.             end
  46.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement