Advertisement
Tapeline

web

Oct 8th, 2021
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.38 KB | None | 0 0
  1. local component = require("component")
  2. local gpu = component.gpu
  3. local w, h = gpu.getResolution()
  4. local m = component.modem
  5. local event = require("event")
  6. local shell = require("shell")
  7. local fs = require("filesystem")
  8. local args, ops = shell.parse(...)
  9. m.open(1110)
  10.  
  11.  
  12. conf = {}
  13.  
  14.  
  15. function loadcfg()
  16.   local f = fs.open("/home/qclient.conf", "r")
  17.   local fc = f:read(fs.size("/home/qclient.conf"))
  18.   conf = {}
  19.   conf = split(fc, ";")
  20. end
  21.  
  22.  
  23. function split (inputstr, sep)
  24.   if sep == nil then
  25.     sep = "%s"
  26.   end
  27.   local t={}
  28.   for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  29.     table.insert(t, str)
  30.   end
  31.   return t
  32. end
  33.                                                                                
  34.  
  35.  
  36. function cls()
  37.   gpu.fill(1, 1, w, h, " ")
  38. end
  39.  
  40. function display(text, lw, lc)
  41.   l = 1
  42.   y = 1
  43.   modf = false
  44.   modb = false
  45.   while l <= lc do
  46.     c = 1
  47.     x = 1
  48.     while c <= lw do
  49.       sym = text:sub((l-1)*lw+c, (l-1)*lw+c)
  50.       if modf then
  51.         if sym == "a" then
  52.           gpu.setForeground(0x00FF00)
  53.         elseif sym == "b" then
  54.           gpu.setForeground(0x00AAAA)
  55.         elseif sym == "c" then
  56.           gpu.setForeground(0xFF0000)
  57.         elseif sym == "d" then
  58.           gpu.setForeground(0xAA00AA)
  59.         elseif sym == "e" then
  60.           gpu.setForeground(0xAAAA00)
  61.         elseif sym == "f" then
  62.           gpu.setForeground(0xFFFFFF)
  63.         elseif sym == "0" then
  64.           gpu.setForeground(0x000000)
  65.         elseif sym == "1" then
  66.           gpu.setForeground(0xFFFFFF)
  67.         elseif sym == "2" then
  68.           gpu.setForeground(0x00AA00)
  69.         elseif sym == "3" then
  70.           gpu.setForeground(0x008888)
  71.         elseif sym == "4" then
  72.           gpu.setForeground(0xAA0000)
  73.         elseif sym == "5" then
  74.           gpu.setForeground(0xCC00CC)
  75.         elseif sym == "6" then
  76.           gpu.setForeground(0xBBAA00)
  77.         elseif sym == "7" then
  78.           gpu.setForeground(0xCCCCCC)
  79.         elseif sym == "8" then
  80.           gpu.setForeground(0x333333)
  81.         elseif sym == "9" then
  82.           gpu.setForeground(0x0000FF)
  83.         end
  84.         modf = false
  85.       elseif modb then
  86.         if sym == "a" then
  87.           gpu.setForeground(0x00FF00)
  88.         elseif sym == "b" then
  89.           gpu.setBackground(0x00AAAA)
  90.         elseif sym == "c" then
  91.           gpu.setBackground(0xFF0000)
  92.         elseif sym == "d" then
  93.           gpu.setBackground(0xAA00AA)
  94.         elseif sym == "e" then
  95.           gpu.setBackground(0xAAAA00)
  96.         elseif sym == "f" then
  97.           gpu.setBackground(0xFFFFFF)
  98.         elseif sym == "0" then
  99.           gpu.setBackground(0x000000)
  100.         elseif sym == "1" then
  101.           gpu.setBackground(0xFFFFFF)
  102.         elseif sym == "2" then
  103.           gpu.setBackground(0x00AA00)
  104.         elseif sym == "3" then
  105.           gpu.setBackground(0x008888)
  106.         elseif sym == "4" then
  107.           gpu.setBackground(0xAA0000)
  108.         elseif sym == "5" then
  109.           gpu.setBackground(0xCC00CC)
  110.         elseif sym == "6" then
  111.           gpu.setBackground(0xBBAA00)
  112.         elseif sym == "7" then
  113.           gpu.setBackground(0xCCCCCC)
  114.         elseif sym == "8" then
  115.           gpu.setBackground(0x333333)
  116.         elseif sym == "9" then
  117.           gpu.setBackground(0x0000FF)
  118.         end
  119.         modb = false
  120.       else
  121.      
  122.         if sym == "&" then
  123.           modf = true
  124.           modb = false
  125.         elseif sym == "^" then
  126.           modb = true
  127.           modf = false
  128.         elseif sym == "\n" then
  129.           y = y + 1
  130.           x = 1
  131.         else
  132.           gpu.set(x, y, sym)
  133.           x = x + 1
  134.         end
  135.       end
  136.       c = c + 1
  137.     end
  138.     l = l + 1
  139.     y = y + 1
  140.   end
  141. end
  142.  
  143.  
  144. function getip(d)
  145.   m.send(conf[1], 1110, conf[2] ..";0.0;DNSLOOKUP;" .. d)
  146.   local _, _, f, p, _, msg = event.pull("modem_message")
  147.   return split(split(msg, ";")[4], ":")[2]
  148. end
  149.  
  150.  
  151. function requestpage(d, page)
  152.   cls()
  153.   if page == nil then
  154.     page = "index"
  155.   end
  156.   print("Getting IP from DNS Server...")
  157.   ip = getip(d)
  158.   print("Got IP!")
  159.   print("Requesting page...")
  160.   m.send(conf[1], 1110, conf[2] ..";".. ip ..";DATA;mctp/".. page)
  161.   local _, _, _, _, _, msg = event.pull("modem_message")
  162.   page = split(msg, ";")[4]
  163.   return page
  164. end
  165.  
  166. cls()
  167. loadcfg()
  168. page = requestpage(split(args[1], "/")[1], split(args[1], "/")[2])
  169. cls()
  170. display(page, w - 10, 20)
  171. event.pull("touch")
  172. cls()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement