Advertisement
Dojnaz

HZCity Browser v2.0

Oct 16th, 2016
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.11 KB | None | 0 0
  1. rednet.open("top")
  2. serverID = 3155
  3.  
  4. local stop
  5.  
  6. local function text(color)
  7.   term.setTextColor(color)
  8. end
  9.  
  10. local function color(colo)
  11.   term.setBackgroundColor(colo)
  12. end
  13.  
  14. local function pos(x, y)
  15.   term.setCursorPos(x, y)
  16. end
  17.  
  18. local function yellowScreen()
  19.     color(colors.yellow)
  20.     term.clear()
  21.     pos(1,1)
  22.     text(colors.white)
  23.     color(colors.green)
  24.     term.write("Cookie Browser")
  25.     color(colors.lime)
  26.     term.write("                                            ")
  27.     color(colors.red)
  28.     pos(51,1)
  29.     term.write("X")
  30.     pos(1,19)
  31.     color(colors.lime)
  32.     term.write("                                                 ")
  33.     pos(1,3)
  34.     color(colors.lime)
  35.     term.write("                                                   ")
  36.     pos(1,2)
  37.     text(colors.black)
  38.     term.write("   >")
  39.     color(colors.white)
  40.     term.write("                                               ")
  41.     color(colors.lime)
  42.     pos(50,2)
  43.     term.write("  ")
  44.     pos(5, 8)
  45.     color(colors.yellow)
  46.     text(colors.black)
  47.     term.write("Yellow Screen of Death")
  48.     pos(5, 10)
  49.     term.write("Can't connect to webpage")
  50.     pos(5, 12)
  51.     term.write("The server computer is not loaded")
  52.     pos(5, 13)
  53.     term.write("or the webpage does not exist")
  54. end
  55.  
  56. local function reset()
  57.     term.clear()
  58.     pos(1,1)
  59.     text(colors.white)
  60.     color(colors.green)
  61.     term.write("Cookie Browser")
  62.     color(colors.lime)
  63.     term.write("                                            ")
  64.     color(colors.red)
  65.     pos(51,1)
  66.     term.write("X")
  67.     pos(1,19)
  68.     color(colors.lime)
  69.     term.write("                                                 ")
  70.     pos(1,3)
  71.     color(colors.lime)
  72.     term.write("                                                   ")
  73.     pos(1,2)
  74.     text(colors.black)
  75.     term.write("   >")
  76.     color(colors.white)
  77.     term.write("                                               ")
  78.     color(colors.lime)
  79.     pos(50,2)
  80.     term.write("  ")
  81. end
  82.  
  83. xPos = 0
  84. yPos = 0
  85.  
  86. w, h = term.getSize()
  87.  
  88. local function drawClock()
  89.  
  90.     color(colors.green)
  91.     text(colors.white)
  92.  
  93.     if os.time() >= 10 then
  94.         xTime = 47
  95.     else
  96.         xTime = 48
  97.         pos(47, 19)
  98.         io.write("0")
  99.     end
  100.    
  101.     pos(xTime, 19)
  102.     io.write(textutils.formatTime(os.time(), true))
  103. end
  104.  
  105. local function events()
  106.  
  107.     event, p1, p2, p3 = os.pullEvent()
  108.    
  109.     if event == "rednet_message" then
  110.         return p2
  111.     end
  112.    
  113.     if event == "mouse_click" then
  114.         xPos = p2
  115.         yPos = p3
  116.         button = p1
  117.         browserClickPos()
  118.         return "fail"
  119.     end
  120.    
  121.     if event == "alarm" and stop == nil then
  122.         drawClock()
  123.         return "fail"
  124.     end
  125.    
  126. end
  127.  
  128. function browserClickPos()
  129.  
  130.     if xPos == 51 and yPos == 1 then
  131.         stop = true
  132.     elseif xPos > 4 and xPos < 51 and yPos == 2 then
  133.         pos(5,2)
  134.         color(colors.white)
  135.         term.write("                                             ")
  136.         pos(5,2)
  137.         text(colors.black)
  138.         adress = read()
  139.        
  140.         rednet.send(serverID, adress)
  141.         repeat
  142.             id = events()
  143.         until id
  144.    
  145.         if id ~= "fail" then
  146.             rednet.send(id,1)
  147.            
  148.             repeat
  149.                 id2 = events()
  150.             until id2
  151.         end
  152.        
  153.         if id == "fail" or id2 == "fail" then
  154.             yellowScreen()
  155.         else
  156.        
  157.             local num = 1
  158.            
  159.             message = {}
  160.        
  161.             webInfo = {color = {}, text = {}, tColor = {}, pos = {x = {}, y = {}}}
  162.        
  163.             while message[6] == nil do
  164.                 rednet.send(id,num)
  165.                 id, message = rednet.receive()
  166.            
  167.                 webInfo.color[num] = message[1]
  168.                 webInfo.text[num] = message[2]
  169.                 webInfo.tColor[num] = message[3]
  170.                 webInfo.pos.x[num] = message[4]
  171.                 webInfo.pos.y[num] = message[5]
  172.            
  173.                 num = num + 1
  174.             end
  175.        
  176.             color(message[6])
  177.             reset()
  178.        
  179.             for i = 1,num-1 do
  180.                 color(webInfo.color[i])
  181.                 pos(webInfo.pos.x[i],webInfo.pos.y[i])
  182.                 text(webInfo.tColor[i])
  183.                 term.write(webInfo.text[i])
  184.             end
  185.            
  186.         end
  187.     end
  188. end
  189.  
  190. local function clockUpdate()
  191.  
  192.     while stop == nil do
  193.    
  194.         if os.time() < 23.99 then
  195.             os.setAlarm(os.time() + 0.01)
  196.         else
  197.             os.setAlarm(0)
  198.         end
  199.    
  200.         events()
  201.        
  202.     end
  203.    
  204. end
  205.  
  206. if stop == nil then
  207.     color(colors.white)
  208.     reset()
  209.    
  210.     color(colors.green)
  211.     text(colors.white)
  212.  
  213.     if os.time() >= 10 then
  214.         xTime = 47
  215.     else
  216.         xTime = 48
  217.         pos(47, 19)
  218.         io.write("0")
  219.     end
  220.    
  221.     pos(xTime, 19)
  222.     io.write(textutils.formatTime(os.time(), true))
  223.    
  224.     clockUpdate()
  225. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement