Hydrotronics

Browser

Jul 6th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Variables
  2. local x,y = term.getSize()
  3. local dnsid = 0
  4.  
  5. -- Functions
  6. function clear()
  7.   term.setBackgroundColor(colors.black)
  8.   term.clear()
  9.   term.setCursorPos(1,1)
  10. end
  11.  
  12. function drawLine(color, x, y)
  13.   term.setCursorPos(x, y)
  14.   term.setBackgroundColor(color)
  15.   term.clearLine()
  16.   term.setCursorPos(x, y+1)
  17. end
  18.  
  19. function writeToLog(text)
  20.   local file = fs.open("log","a")
  21.   file.writeLine(text)
  22.   file.close()
  23. end
  24. local file = fs.open("log","w")
  25. file.write("")
  26. file.close()
  27. -- main gui function
  28. function drawGui()
  29.     drawLine(256,1,1)
  30.     term.setTextColor(32768)
  31.     write("  <-  -> ")
  32.     term.setBackgroundColor(1)
  33.     write(" http://                        ")
  34.     term.setBackgroundColor(256)
  35.     write("              ")
  36.     drawLine(256,1,3)
  37.     drawLine(1,1,4)
  38.     drawLine(1,1,5)
  39.     drawLine(1,1,6)
  40.     drawLine(1,1,7)
  41.     drawLine(1,1,8)
  42.     drawLine(1,1,9)
  43.     drawLine(1,1,10)
  44.     drawLine(1,1,11)
  45.     drawLine(1,1,12)
  46.     drawLine(1,1,13)
  47.     drawLine(1,1,14)
  48.     drawLine(1,1,15)
  49.     drawLine(1,1,16)
  50.     drawLine(1,1,17)
  51.     drawLine(1,1,18)
  52.     drawLine(1,1,y)
  53.  writeToLog("Gui Drawn")
  54. end
  55.  
  56. local s = rs.getSides()
  57. local modemside
  58. for each,side in pairs(s) do
  59.   if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
  60.     modemside = side
  61.     break
  62.   end
  63. end
  64. writeToLog("Found modem "..modemside)
  65. drawGui()
  66.  
  67. -- URL
  68. while true do
  69.     term.setCursorPos(18,2)
  70.     term.setBackgroundColor(1)
  71.     term.setTextColor(32768)
  72.     url = read()
  73.  writeToLog("Tried to access "..url)
  74.     term.setCursorPos(1,4)
  75.     term.setBackgroundColor(1)
  76.     term.setTextColor(32768)
  77.     -- Rednet
  78.  writeToLog("Sending request "..url.." to "..dnsid.." on "..modemside)
  79.     rednet.open(modemside)
  80.     rednet.send(dnsid, url,os.getComputerID())
  81.  id,message = rednet.receive(5)
  82.     if message==nil then
  83.   write("Error 404: Cannot connect to server")
  84.   writeToLog("Couldn't connect")
  85.  else
  86.    local file = fs.open("temp","w")
  87.    file.write(message)
  88.    file.close()
  89.    shell.run("temp")
  90.    writeToLog("Connected")
  91.  end
  92.     rednet.close()
  93.     while true do
  94.         local event, param = os.pullEvent()
  95.         writeToLog("Key")
  96.   if event == "key" then
  97.             if param == keys.leftCtrl then
  98.     writeToLog("Exiting website")
  99.                 break
  100.             end
  101.         end
  102.     end
  103.     clear()
  104.     drawGui()
  105. end
Add Comment
Please, Sign In to add comment