Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- version = 0.02
- if not fs.isDir("/apis") then
- fs.delete("/apis/")
- fs.makeDir("/apis/")
- shell.run("pastebin get 9E5UHiqv /apis/AES")
- shell.run("pastebin get QYvNKrXE /apis/Base64")
- end
- if not fs.exists("/apis/AES") then
- shell.run("pastebin get 9E5UHiqv /apis/AES")
- end
- if not fs.exists("/apis/Base64") then
- shell.run("pastebin get QYvNKrXE /apis/Base64")
- end
- os.loadAPI("/apis/AES")
- os.loadAPI("/apis/Base64")
- modem = nil
- browserID = "storm"
- for k, v in pairs(peripheral.getNames()) do
- if peripheral.getType(v) == "modem" then
- modem = peripheral.wrap(v)
- end
- end
- if not modem then
- error("This program requires a modem!")
- else
- modem.open(24680)
- end
- function decode(msg)
- de_msg = AES.decrypt(tostring(client_id)..tostring(distance)..tostring(server_sent),Base64.decode(msg))
- server_sent = server_sent +1
- return de_msg
- end
- function eSend(tmsg,domain,msg)
- the_key = tostring(client_id) .. tostring(distance) .. tostring(sent)
- messageToSend = Base64.encode(AES.encrypt(the_key,tmsg.." "..msg))
- sent = sent+1
- modem.transmit(24680,client_id,"E"..domain.."|"..messageToSend)
- end
- function send(tmsg,msg)
- sent = sent+1
- modem.transmit(24680,client_id,tmsg.." "..msg)
- end
- function connect(address)
- server_sent = 0
- sent = 0
- client_id = math.random(1000,31337)
- send("PING",address)
- timer_id = os.startTimer(2)
- exit_loop = false
- while not exit_loop do
- evnt = {os.pullEvent()}
- if evnt[1] == "timer" and evnt[2] == timer_id then
- return false -- time out
- elseif evnt[1] == "modem_message" and evnt[4] == client_id then
- msg = evnt[5]
- msg_words = {}
- for w in msg:gmatch("%S+") do
- table.insert(msg_words,w)
- end
- if msg_words[1] and msg_words[1] == "Pong" then
- if msg_words[2] and msg_words[2] == "Pong!" then
- distance = evnt[6]
- exit_loop = true
- end
- end
- end
- end
- eSend("EPING",address,"ENCRYPTED PING")
- exit_loop = false
- timer_id = os.startTimer(2)
- while not exit_loop do
- evnt = {os.pullEvent()}
- if evnt[1] == "timer" and evnt[2] == timer_id then
- return false
- elseif evnt[1] == "modem_message" then
- if evnt[4] == client_id then
- if evnt[5]:sub(1,1) == "E" then
- msg = decode(evnt[5]:sub(2,#evnt[5]))
- msg_words = {}
- for w in msg:gmatch("%S+") do
- table.insert(msg_words,w)
- end
- if msg_words[2] and msg_words[2] == "EPONG" then
- if msg_words[3] and msg_words[4] and msg_words[4] == "ENCRYPTED" and msg_words[4] == "PONG" then
- return true
- end
- else
- return false
- end
- else
- end
- end
- end
- end
- end
- function getPage(dmn,page)
- connect(dmn)
- eSend("PAGE",dmn,page)
- exit_loop = false
- timer_id = os.startTimer(2)
- while not exit_loop do
- evnt = {os.pullEvent()}
- if evnt[1] == "timer" and evnt[2] == timer_id then
- return false
- elseif evnt[1] == "modem_message" then
- if evnt[4] == client_id then
- if evnt[5]:sub(1,1) == "E" then
- msg = decode(evnt[5]:sub(2,#evnt[5]))
- if msg:sub(1,9) == "200 PDATA" then
- page_data = msg:sub(11,#msg)
- exit_loop = true
- return page_data, tonumber(msg:sub(1,3))
- elseif msg:sub(1,9) == "404 PDATA" then
- page_data = msg:sub(11,#msg)
- exit_llop = true
- return page_data, tonumber(msg:sub(1,3))
- end
- end
- end
- end
- end
- end
- function loadPage(pageData)
- if pageData then
- local page = loadstring(pageData)
- page = setfenv(page,getfenv())
- page()
- end
- end
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- local cur = term.current()
- scrx,scry = term.getSize()
- --local wPage = window.create(cur, 1, 3, scrx, scry-2,true)
- --local wBar= window.create(cur,7,1,scrx-6, 1, true)
- history = { "new" }
- local oPullRaw = os.pullEventRaw
- local oPull = os.pullEvent
- os.pullEvent = function(filter)
- local pEData = {oPullRaw(filter)}
- if pEData[1] ~= "mouse_click" then
- return unpack(pEData)
- else
- local e,b,cx,cy =unpack(pEData)
- cy = cy-2
- return e,b,cx,cy
- end
- end
- loadPage(getPage("tron.com","index"))
- os.pullEvent = oPull
Advertisement
Add Comment
Please, Sign In to add comment