mikk809h

the API

Aug 31st, 2013
12
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local oldRednet = rednet
  2. local oldSide = false
  3.  
  4.  
  5. -- shorter functions
  6. local net = rednet
  7. local brod = net.broadcast
  8. local pull = os.pullEvent
  9.  
  10. --
  11.  
  12. function saveID(ID)
  13.     local saveID = fs.open(".clients", "a")
  14.     saveID.writeLine(tonumber(ID))
  15.     saveID.close()
  16. end
  17.  
  18. function getID()
  19.     local ret = {}
  20.     local readID = fs.open(".clients", "r")
  21.     local rAll = readID.readAll()
  22.     table.insert(ret, rAll)
  23.     readID.close()
  24.     return textutils.serialize(ret)
  25. end
  26.  
  27. function setMaster(ID)
  28.     local save = fs.open(".master", "w")
  29.     save.writeLine(ID)
  30.     save.close()
  31. end
  32.  
  33. function getMaster()
  34.     local save = fs.open(".master", "r")
  35.     local cRead = save.readLine()
  36.     save.close()
  37.     return cRead
  38. end
  39.  
  40. function setGlobalMessage(msg)
  41.     local save = fs.open(".global", "w")
  42.     save.writeLine(msg)
  43.     save.close()
  44. end
  45.  
  46. function getGlobalMessage()
  47.     local save = fs.open(".global", "r")
  48.     local cRead = save.readLine()
  49.     save.close()
  50.     return cRead
  51. end
  52.  
  53. function open(side)
  54.     oldSide = side
  55.     rednet.open(side)
  56. end
  57.  
  58. function close()
  59.     rednet.close(oldSide)
  60. end
  61.    
  62. function send(id, msg)
  63.     net.send(id, msg)
  64. end
  65.  
  66. function isID(id)
  67.     local tbl={};
  68.    
  69.     if fs.exists(".clients") then
  70.         local handle = assert(fs.open(".clients", "r"), "Cannot open file for read")
  71.  
  72.         for line in handle.readLine do
  73.             table.insert(tbl, tonumber(line))
  74.         end
  75.  
  76.         handle.close()
  77.     else
  78.         return false
  79.     end
  80.  
  81.     for k,v in pairs(tbl) do
  82.         if v == id then
  83.             return true
  84.         end
  85.     end
  86.     return false
  87. end
  88.  
  89. function isPermitted(name, pass)
  90.     local failRead = fs.open(".accounts", "r")
  91.     local failRd = failRead.readAll()
  92.     failRead.close()
  93.     if not string.find(failRd, "failSafe") then
  94.         local failSafe = fs.open(".accounts", "a")
  95.         failSafe.writeLine("failSafe")
  96.         failSafe.close()
  97.     end
  98.  
  99.     local rRead = fs.open(".accounts", "r")
  100.     local rAll = rRead.readAll()
  101.     rRead.close()
  102.     print(tostring(rAll))
  103.     if string.find(rAll, "&usr="..name.."&pwd="..pass) then
  104.         return true
  105.     else
  106.         return false
  107.     end
  108. end
  109.  
  110. function setPermitted(name, pass)
  111.  
  112.     local rRead = fs.open(".accounts", "r")
  113.     local rAll = rRead.readAll()
  114.     rRead.close()
  115.     if string.find(rAll, "&usr="..name.."&pwd="..pass) then
  116.     else
  117.         local uacc = {}
  118.         table.insert(uacc, "&usr="..name.."&pwd="..pass)
  119.         local handle = fs.open(".accounts", "a")
  120.         handle.write(textutils.serialize(uacc))
  121.         handle.close()
  122.         print(textutils.serialize(uacc))
  123.     end
  124. end
  125.  
  126. --
  127.  
  128. function evt(event)
  129.     local ev, e1, e2, e3, e4 = pull(event)
  130.     return ev, e1, e2, e3, e4
  131. end
  132.    
  133. function ping()
  134.     brod("ping")
  135.     local event, id, msg, dist = pull("rednet_message")
  136.     if msg == "pong" then
  137.         setMaster(id)
  138.         setGlobalMessage("success")
  139.     end
  140. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×