Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local gpu = component.gpu
- local w, h = gpu.getResolution()
- local m = component.modem
- local event = require("event")
- local shell = require("shell")
- local fs = require("filesystem")
- local args, ops = shell.parse(...)
- m.open(1110)
- conf = {}
- function loadcfg()
- local f = fs.open("/home/qclient.conf", "r")
- local fc = f:read(fs.size("/home/qclient.conf"))
- conf = {}
- conf = split(fc, ";")
- end
- function split (inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- function cls()
- gpu.fill(1, 1, w, h, " ")
- end
- function display(text, lw, lc)
- l = 1
- y = 1
- modf = false
- modb = false
- while l <= lc do
- c = 1
- x = 1
- while c <= lw do
- sym = text:sub((l-1)*lw+c, (l-1)*lw+c)
- if modf then
- if sym == "a" then
- gpu.setForeground(0x00FF00)
- elseif sym == "b" then
- gpu.setForeground(0x00AAAA)
- elseif sym == "c" then
- gpu.setForeground(0xFF0000)
- elseif sym == "d" then
- gpu.setForeground(0xAA00AA)
- elseif sym == "e" then
- gpu.setForeground(0xAAAA00)
- elseif sym == "f" then
- gpu.setForeground(0xFFFFFF)
- elseif sym == "0" then
- gpu.setForeground(0x000000)
- elseif sym == "1" then
- gpu.setForeground(0xFFFFFF)
- elseif sym == "2" then
- gpu.setForeground(0x00AA00)
- elseif sym == "3" then
- gpu.setForeground(0x008888)
- elseif sym == "4" then
- gpu.setForeground(0xAA0000)
- elseif sym == "5" then
- gpu.setForeground(0xCC00CC)
- elseif sym == "6" then
- gpu.setForeground(0xBBAA00)
- elseif sym == "7" then
- gpu.setForeground(0xCCCCCC)
- elseif sym == "8" then
- gpu.setForeground(0x333333)
- elseif sym == "9" then
- gpu.setForeground(0x0000FF)
- end
- modf = false
- elseif modb then
- if sym == "a" then
- gpu.setForeground(0x00FF00)
- elseif sym == "b" then
- gpu.setBackground(0x00AAAA)
- elseif sym == "c" then
- gpu.setBackground(0xFF0000)
- elseif sym == "d" then
- gpu.setBackground(0xAA00AA)
- elseif sym == "e" then
- gpu.setBackground(0xAAAA00)
- elseif sym == "f" then
- gpu.setBackground(0xFFFFFF)
- elseif sym == "0" then
- gpu.setBackground(0x000000)
- elseif sym == "1" then
- gpu.setBackground(0xFFFFFF)
- elseif sym == "2" then
- gpu.setBackground(0x00AA00)
- elseif sym == "3" then
- gpu.setBackground(0x008888)
- elseif sym == "4" then
- gpu.setBackground(0xAA0000)
- elseif sym == "5" then
- gpu.setBackground(0xCC00CC)
- elseif sym == "6" then
- gpu.setBackground(0xBBAA00)
- elseif sym == "7" then
- gpu.setBackground(0xCCCCCC)
- elseif sym == "8" then
- gpu.setBackground(0x333333)
- elseif sym == "9" then
- gpu.setBackground(0x0000FF)
- end
- modb = false
- else
- if sym == "&" then
- modf = true
- modb = false
- elseif sym == "^" then
- modb = true
- modf = false
- elseif sym == "\n" then
- y = y + 1
- x = 1
- else
- gpu.set(x, y, sym)
- x = x + 1
- end
- end
- c = c + 1
- end
- l = l + 1
- y = y + 1
- end
- end
- function getip(d)
- m.send(conf[1], 1110, conf[2] ..";0.0;DNSLOOKUP;" .. d)
- local _, _, f, p, _, msg = event.pull("modem_message")
- return split(split(msg, ";")[4], ":")[2]
- end
- function requestpage(d, page)
- cls()
- if page == nil then
- page = "index"
- end
- print("Getting IP from DNS Server...")
- ip = getip(d)
- print("Got IP!")
- print("Requesting page...")
- m.send(conf[1], 1110, conf[2] ..";".. ip ..";DATA;mctp/".. page)
- local _, _, _, _, _, msg = event.pull("modem_message")
- page = split(msg, ";")[4]
- return page
- end
- cls()
- loadcfg()
- page = requestpage(split(args[1], "/")[1], split(args[1], "/")[2])
- cls()
- display(page, w - 10, 20)
- event.pull("touch")
- cls()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement