Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Browser 0.3b
- -- Nic tu nie zmieniaj. Haslo do admina - 5050
- debug = true
- slow = true
- if debug then
- slow = false
- end
- if fs.exists("FreshApi") then
- os.unloadAPI("FreshApi")
- os.loadAPI("FreshApi")
- else
- error("Zainstaluj FreshAPI")
- end
- function sTable(file, table)
- f = fs.open(file, "w")
- f.write(textutils.serialize(table))
- f.close()
- end
- function lTable(file)
- f = fs.open(file, "r")
- table = textutils.unserialize(f.readAll())
- f.close()
- return table
- end
- function ping()
- received = {}
- test = {}
- n2 = {}
- a = 0
- if config[3] == 2 then
- sleep(0.5)
- end
- while true do
- a = a + 1
- received[a] = {}
- event, id, txt, xd = os.pullEvent("rednet_message")
- if txt:find("BTSHello") then
- n = textutils.unserialize(txt)
- n2[a] = n[2]
- received[a][1] = id
- received[a][2] = n2[a]
- received[a][3] = xd
- end
- end
- end
- function timer()
- ot2 = "false"
- if config[3] == 2 then
- timer1 = os.startTimer(5)
- else
- timer1 = os.startTimer(0.2)
- end
- while true do
- event, timer2 = os.pullEvent("timer")
- if event == "timer" and timer2 == timer1 then
- ot2 = "true"
- break
- end
- end
- end
- function getBTS()
- rednet.broadcast("HelloBTS")
- parallel.waitForAny(timer, ping)
- return received
- end
- ver = "0.3b"
- sides = rs.getSides()
- config = {}
- function inf (gt)
- term.clear()
- term.setCursorPos(1,1)
- FreshApi.centerPrint("| KrzakBrowser ".. ver.. " |")
- term.setCursorPos(1,2)
- if gt then
- textutils.slowPrint(FreshApi.line(), 100)
- else
- FreshApi.drawLine()
- end
- term.setCursorPos(1,3)
- term.clearLine()
- end
- function signal(dis)
- dis = tonumber(dis)
- sig = "[ ]"
- if dis == nil then
- dis = 513
- sig = "[ ]"
- end
- if dis < 113 then
- sig = "[*****]"
- end
- if dis < 201 then
- if dis > 113 then
- sig = "[**** ]"
- end
- end
- if dis < 301 then
- if dis > 201 then
- sig = "[*** ]"
- end
- end
- if dis < 401 then
- if dis > 301 then
- sig = "[** ]"
- end
- end
- if dis < 513 then
- if dis > 401 then
- sig = "[* ]"
- end
- end
- return sig
- end
- function zaladuj(cal, site)
- tab = cal[1]
- tec = cal[2]
- t = 1
- d = 5
- wybor = 7
- w,h = term.getSize()
- scr = 0
- wysSig(id, name, r)
- term.setCursorPos(1,3)
- term.write("Adres:")
- term.setCursorPos(7,3)
- term.write(site)
- term.setCursorPos(1,4)
- FreshApi.drawLine()
- while true do
- term.setCursorPos(1,3)
- term.clearLine()
- term.write("Adres:")
- term.setCursorPos(7,3)
- term.write(site)
- term.setCursorPos(1,4)
- FreshApi.drawLine()
- c,v = term.getSize()
- --if #tab > 10 then
- tabL = 13
- --else
- -- tabL = #tab
- --end
- a = 0
- term.setCursorPos(1, 18)
- term.clearLine()
- term.write("Enter Link F3 Cofnij F4 Szukaj F5 Odswiez")
- for i=1,tabL do
- a = a + 1
- term.setCursorPos(t, d + a - 1)
- term.clearLine()
- if a+scr == wybor-6 then
- if tab[i+scr] == nil then
- write(">")
- else
- write(">".. tostring(tab[i+scr]))
- end
- else
- if tab[i+scr] == nil then
- write("")
- else
- write(" ".. tostring(tab[i+scr]))
- end
- end
- end
- event, key = os.pullEvent("key")
- if key == 200 and wybor-6>1 then
- if wybor > 13 then
- scr = scr - 1
- end
- wybor = wybor - 1
- elseif key == 208 then
- wybor = wybor + 1
- if wybor > 13 then
- scr = scr + 1
- end
- elseif key == 63 then
- bk = "false"
- break
- elseif key == 61 then
- elseif key == 62 then
- bk = "true"
- break
- elseif key == 28 then
- term.setCursorPos(1, 18)
- term.clearLine()
- term.write('Wpisz "Anuluj123" aby anulowac')
- term.setCursorPos(1, 3)
- term.clearLine()
- FreshApi.centerPrint("Wpisz tekst")
- term.setCursorPos(1,17)
- term.clearLine()
- term.write(">")
- term.setCursorPos(2,17)
- input = read()
- if #input > 48 then
- term.setCursorPos(1,17)
- term.clearLine()
- FreshApi.centerPrint("Tekst nie moze przekraczac 48 znakow.")
- sleep(1.5)
- wysSig(id, name, r)
- else
- if input == "Anuluj123" or input == '"Anuluj123"' then
- else
- tab[wybor-6] = input
- end
- end
- end
- end
- end
- function pgError(er)
- if er == 401 then
- end
- end
- function connect()
- getBTS()
- our = {}
- r = "false"
- output = "false"
- p = 0
- for i=1, #received do
- if n2[i] == config[2] then
- p = p + 1
- our[p] = received[i][1]
- end
- end
- for i=1, #our do
- rednet.send(our[i], "connectBTS")
- parallel.waitForAny(timer, receive)
- if txt == "true" then
- output = id
- name = config[2]
- break
- end
- end
- if output == "false" then
- sleep(1)
- for i=1, #received do
- for o=1, #config[4] do
- if n2[i] == config[4][o] then
- print(received[i][1])
- rednet.send(received[i][1], "connectBTS")
- parallel.waitForAny(timer, receive)
- if txt == "true" then
- name = config[4][o]
- r = "true"
- output = id
- break
- end
- end
- end
- end
- end
- return output, name, r
- end
- function receive()
- ot = "false"
- while true do
- event, id, txt, dis = os.pullEvent("rednet_message")
- if event == "rednet_message" then
- ot = "true"
- break
- end
- return id, txt, dis, ot
- end
- end
- function wysSig(id, name, r)
- while true do
- if id == "false" then
- FreshApi.centerText("Brak Polaczenia...")
- while true do
- id = connect()
- if id == "false" then
- else
- break
- end
- end
- end
- rednet.send(id, "HelloBTS")
- parallel.waitForAny(timer, receive)
- nm = ""
- if ot then
- nm = " ".. tostring(name)
- else
- nm = "Brak Polaczenia"
- end
- term.clear()
- term.setCursorPos(1,1)
- print(nm)
- if r == "true" then
- term.setCursorPos(39, 1)
- print("[R] ".. tostring(signal(dis)))
- else
- term.setCursorPos(42, 1)
- print(tostring(signal(dis)))
- end
- term.setCursorPos(1,1)
- FreshApi.centerPrint(" | KrzakBrowser ".. " | ")
- term.setCursorPos(1,2)
- FreshApi.drawLine()
- term.setCursorPos(1,3)
- term.clearLine()
- if ot then
- break
- else
- FreshApi.centerText("Brak Polaczenia...")
- while true do
- id = connect()
- if id == "false" then
- else
- break
- end
- end
- end
- end
- end
- inf(slow)
- if fs.exists("Settings") then
- config = lTable("Settings")
- rednet.open(config[1])
- else
- term.setCursorPos(1,3)
- FreshApi.centerPrint("Pierwsza konfiguracja.")
- sleep(1.5)
- term.setCursorPos(1,3)
- term.clearLine()
- FreshApi.centerPrint("Wybierz rodzaj polaczenia.")
- s = FreshApi.drawMenu({"Modem", "Kabel"}, 2, 5)
- config[3] = s
- term.setCursorPos(1,3)
- term.clearLine()
- inf(slow)
- if config[3] == 1 then
- FreshApi.centerPrint("Wybierz strone z ktorej jest modem.")
- else
- FreshApi.centerPrint("Wybierz strone z ktorej jest kabel.")
- end
- s = FreshApi.drawMenu(sides, 2, 5)
- config[1] = sides[s]
- rednet.open(config[1])
- inf(slow)
- term.setCursorPos(1, 3)
- term.clearLine()
- getBTS()
- FreshApi.centerPrint("Lista dostepnych operatorow. Wybierz jednego.")
- list = {}
- wys = {}
- for i=1, #n2 do
- if n2[i] == nil then
- else
- for i2=i+1, #n2 do
- if n2[i] == n2[i2] then
- table.remove(n2, i2)
- table.remove(received, i2)
- end
- end
- end
- end
- for i=1, #n2 do
- if not n2[i] == nil then
- else
- list[i] = n2[i]
- zm = n2[i]
- if config[3] == 1 then
- wys[i] = " ".. zm.. " ".. tostring(signal(received[i][3])).. " "
- else
- wys[i] = " ".. zm.. " "
- end
- end
- end
- wbr = FreshApi.drawMenu(wys, 2, 5)
- config[2] = list[wbr]
- y = 1
- w = {}
- list2 = {}
- for i=1, #list do
- list2[i] = " ".. list[i].. " "
- end
- list2[#list2+1] = "Dalej"
- inf(slow)
- term.setCursorPos(1, 3)
- term.clearLine()
- FreshApi.centerPrint("Lista dostepnych operatorow. Wybierz rumuningi.")
- while true do
- inf(false)
- term.setCursorPos(1, 3)
- term.clearLine()
- FreshApi.centerPrint("Lista dostepnych operatorow. Wybierz rumuningi. XD")
- l = FreshApi.drawMenu(list2, 2, 5)
- if l == #list2 then
- break
- else
- finding = list2[l]
- if finding:find("[R]") then
- list2[l] = " ".. list[l].. " "
- else
- list2[l] = " ".. list2[l].. " [R] "
- end
- end
- end
- for i=1, #list2 do
- finding = list2[i]
- if finding:find("[R]") then
- w[y] = list[i]
- y = y + 1
- end
- end
- config[4] = w
- sTable("Settings", config)
- FreshApi.centerText("Skonfigurowano pomyslnie.")
- sleep(1)
- term.clear()
- end
- while true do
- id, name, r = connect()
- wysSig(id, name, r)
- term.setCursorPos(1, 3)
- term.write("Adres:")
- term.setCursorPos(1, 4)
- FreshApi.drawLine()
- term.setCursorPos(7, 3)
- input = read()
- gID = os.getComputerID()
- tbl = {}
- t = {}
- t[1] = gID
- t[2] = input
- b = 0
- while true do
- b = b + 1
- if b == 10 then
- id, name, r = connect()
- wysSig(id, name, r)
- end
- if b == 15 then
- term.clear()
- id, name, r = connect()
- wysSig(id, name, r)
- term.setCursorPos(1, 3)
- term.write("Adres:")
- term.setCursorPos(1, 4)
- FreshApi.drawLine()
- term.setCursorPos(7, 3)
- term.write(input)
- FreshApi.centerText("Error 404. Wcisnij cokolwiek...")
- os.pullEvent("key")
- break
- end
- sleep(0.1)
- wid = textutils.serialize(t)
- rednet.send(id, wid)
- parallel.waitForAny(receive, timer)
- txtT = textutils.unserialize(txt)
- if txtT == nil then
- else
- if txtT[1] == gID then
- zaladuj(txtT[2], input)
- if bk == "true" then
- term.clear()
- break
- else
- term.clear()
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement