immibis

nexusboot

Sep 10th, 2013
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. local mside
  2. for _,side in ipairs(rs.getSides()) do
  3.  if peripheral.getType(side) == "modem" then
  4.   mside = side
  5.   break
  6.  end
  7. end
  8. if not mside then error("No modem found", 0) end
  9. print("== NEXUSBOOT 1.0 ==")
  10. local modem = peripheral.wrap(mside)
  11. modem.open(1000)
  12. modem.transmit(1000, 1000, "request")
  13. local timer = os.startTimer(10)
  14. local bootcode
  15. while true do
  16.  local e, p1, p2, p3, p4, p5 = os.pullEventRaw()
  17.  if e == "timer" and p1 == timer then
  18.   break
  19.  elseif e == "modem_message" and p2 == 1000 and type(p4) == "string" and p4:sub(1,6)=="reply:" then
  20.   bootcode = p4:sub(7)
  21.   break
  22.  end
  23. end
  24.  
  25. if bootcode then
  26.  local fn, err = loadstring(bootcode)
  27.  if not fn then printError(err)
  28.  else local ok, err = pcall(fn)
  29.   if not ok then printError(err)
  30.   else printError("Boot code terminated")
  31.   end
  32.  end
  33. else
  34.  printError("Timeout - Check boot server")
  35. end
  36.  
  37. while true do coroutine.yield() end
Advertisement
Add Comment
Please, Sign In to add comment