Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Edytor Strony/Serwer wersja 0.1e
- ver = "0.1e"
- 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()
- 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
- break
- end
- end
- end
- function getBTS()
- rednet.broadcast("HelloBTS")
- parallel.waitForAny(timer, ping)
- return received
- end
- function inf (gt)
- term.clear()
- term.setCursorPos(1,1)
- FreshApi.centerPrint("| Edytor Strony ".. 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 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 = id2
- 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
- rednet.send(received[i][1], "connectBTS")
- parallel.waitForAny(timer, receive)
- if txt == "true" then
- name = config[4][o]
- r = "true"
- output = id2
- break
- end
- end
- end
- end
- end
- return output, name, r
- end
- function receive()
- ot = "false"
- while true do
- event, id2, txt, dis = os.pullEvent("rednet_message")
- if event == "rednet_message" then
- ot = "true"
- break
- end
- return id2, 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(43, 1)
- print(tostring(signal(dis)))
- end
- term.setCursorPos(1,1)
- FreshApi.centerPrint(" | Edytor Strony ".. "| ")
- 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
- function edit(site)
- if fs.exists("edytor/".. site) then
- cal = lTable("edytor/".. site)
- tab = cal[1]
- tec = cal[2]
- else
- tab = {"Link przenies na inna strone|zmien w wlasc. ln.)", "Wysrodkuj (w wlasc. ln.)", "tekst (aby usunac wcisnij enter 2 razy)", "Zapisz wciskajac F3, wyjdz wciskajac F4" }
- tec = {}
- end
- t = 1
- d = 5
- wybor = 7
- w,h = term.getSize()
- scr = 0
- wysSig(id, name, r)
- term.setCursorPos(1,3)
- term.write("Edit:")
- term.setCursorPos(1,3)
- FreshApi.centerPrint(site)
- term.setCursorPos(1,4)
- FreshApi.drawLine()
- while true do
- term.setCursorPos(1,3)
- term.clearLine()
- term.write("Edit:")
- term.setCursorPos(1,3)
- FreshApi.centerPrint(site)
- term.setCursorPos(1,4)
- FreshApi.drawLine()
- c,v = term.getSize()
- --if #tab > 10 then
- tabL = 12
- --else
- -- tabL = #tab
- --end
- a = 0
- ln = "Ln ".. wybor-6
- term.setCursorPos(50-#ln,18)
- term.clearLine()
- term.setCursorPos(1, 18)
- term.write("Enter - Wpisz tekst F1 - Wlasciwosci ln.")
- term.setCursorPos(1, 17)
- term.clearLine()
- term.write("F3 - Zapisz F4 - Wyjdz")
- term.setCursorPos(50-#ln,18)
- term.write(ln)
- 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 > 12 then
- scr = scr - 1
- end
- wybor = wybor - 1
- elseif key == 208 then
- wybor = wybor + 1
- if wybor > 12 then
- scr = scr + 1
- end
- elseif key == 59 then
- elseif key == 61 then
- cal = {}
- cal[1] = tab
- cal[2] = tec
- sTable("edytor/".. site, cal)
- term.setCursorPos(1, 3)
- term.clearLine()
- FreshApi.centerPrint("Zapisano.")
- sleep(1)
- elseif key == 62 then
- 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 server()
- txtT = {}
- p = {}
- k = {}
- u = {}
- for i=1, #config[6] do
- k[i] = config[6][i]
- u[i] = config[5].. ".mc/".. config[6][i]
- end
- k[#k+1] = config[5]
- u[#u+1] = config[5].. ".mc"
- while true do
- while true do
- event1, id3, txt1, dis1 = os.pullEvent("rednet_message")
- if event == "rednet_message" then
- break
- end
- end
- --local ok, err = pcall(function() txtT = textutils.unserialize(txt) end)
- --if not ok then
- -- print("No table")
- --else
- txtT = textutils.unserialize(txt1)
- if txtT == nil then
- else
- for i=1, #u do
- if txtT[2] == u[i] then
- if fs.exists("edytor/".. k[i]) then
- idD = txtT[1]
- p[1] = txtT[1]
- p[2] = lTable("edytor/".. k[i])
- p1 = textutils.serialize(p)
- print("wyslalo")
- rednet.send(id3, p1)
- end
- end
- end
- end
- end
- end
- --end
- function sConnect ()
- while true do
- term.clear()
- id, name, r = connect()
- wysSig(id, name, r)
- sleep(10)
- end
- end
- sides = rs.getSides()
- config = {}
- term.clear()
- inf()
- if fs.exists("edytor/Settings") then
- config = lTable("edytor/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.")
- 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
- m = {"Wpisz nazwe", "Ustaw nazwe"}
- gID = os.getComputerID()
- while true do
- inf()
- term.setCursorPos(1,3)
- term.clearLine()
- FreshApi.centerPrint("Podaj nazwe strony.")
- s = FreshApi.drawMenu(m, 2, 5)
- if s == 1 then
- term.setCursorPos(2,2)
- nazwa = tostring(read())
- m[3] = nazwa.. ".mc"
- end
- if s == 2 then
- a = "true"
- if #nazwa > 31 then
- term.setCursorPos(1,3)
- FreshApi.centerPrint("Nazwa nie moze przekraczac 30 znakow.")
- a = "false"
- sleep(1.5)
- end
- if #nazwa < 1 then
- term.setCursorPos(1,3)
- FreshApi.centerPrint("Podaj nazwe.")
- a = "false"
- sleep(1.5)
- end
- if a == "true" then
- config[5] = nazwa
- break
- end
- end
- end
- config[6] = {}
- fs.makeDir("edytor")
- sTable("edytor/Settings", config)
- FreshApi.centerText("Skonfigurowano pomyslnie.")
- sleep(1)
- term.clear()
- end
- while true do
- term.clear()
- FreshApi.centerText("Laczenie...")
- id, name, r = connect()
- term.clear()
- wysSig(id, name, r)
- term.setCursorPos(1,3)
- FreshApi.centerPrint("Wybierz opcje.")
- term.setCursorPos(1,4)
- FreshApi.drawLine()
- wbr = FreshApi.drawMenu({"Edytuj strone", "Podglag strony", "Uruchom serwer", "Ustawienia", "Informacje"}, 2, 6)
- if wbr == 3 then
- --parallel.waitForAny(sConnect, server)
- server()
- end
- if wbr == 1 then
- wysSig(id, name, r)
- term.setCursorPos(1,3)
- FreshApi.centerPrint("Wybierz opcje.")
- term.setCursorPos(1,4)
- FreshApi.drawLine()
- ps = FreshApi.drawMenu({"Edytuj stone/podstrone", "Utworz podstrone", "Usun podstrone", "Wstecz"}, 2, 6)
- if ps == 3 then
- wb = {}
- wb[1] = "Wstecz"
- for i=1, #config[6] do
- wb[i+1] = config[5].. ".mc/".. config[6][i]
- end
- wysSig(id, name, r)
- term.setCursorPos(1,3)
- FreshApi.centerPrint("Wybierz podstrone do usuniecia.")
- term.setCursorPos(1,4)
- FreshApi.drawLine()
- kl = FreshApi.drawMenu(wb, 2, 6)
- if kl == 1 then
- else
- config[6][kl-1] = nil
- for i=1, #config[6] do
- if config[6][i] == nil then
- table.remove(config[6], i)
- end
- end
- sTable("edytor/Settings", config)
- end
- end
- if ps == 1 then
- wb = {}
- wb[1] = "Wstecz"
- wb[2] = config[5].. ".mc"
- for i=1, #config[6] do
- wb[i+2] = config[5].. ".mc/".. config[6][i]
- end
- wysSig(id, name, r)
- term.setCursorPos(1,3)
- FreshApi.centerPrint("Wybierz strone do edytowania.")
- term.setCursorPos(1,4)
- FreshApi.drawLine()
- kl = FreshApi.drawMenu(wb, 2, 6)
- if kl == 1 then
- end
- if kl == 2 then
- edit(config[5])
- end
- if kl > 2 then
- edit(config[6][kl-2])
- end
- end
- if ps == 2 then
- nazwa = ""
- m = {"Wpisz nazwe", "Ustaw nazwe", "Wstecz"}
- gID = os.getComputerID()
- while true do
- wysSig(id, name, r)
- term.setCursorPos(1,3)
- term.clearLine()
- FreshApi.centerPrint("Podaj nazwe podstrony.")
- term.setCursorPos(1,4)
- FreshApi.drawLine()
- s = FreshApi.drawMenu(m, 2, 6)
- if s == 3 then
- break
- end
- if s == 1 then
- term.setCursorPos(2,2)
- nazwa = tostring(read())
- m[4] = config[5].. ".mc".. "/".. nazwa
- end
- if s == 2 then
- a = "true"
- if #nazwa > 34 - #config[5] then
- term.setCursorPos(1,3)
- FreshApi.centerPrint("Nazwa nie moze przekraczac ".. 34 - #config[5] " znakow.")
- a = "false"
- sleep(1.5)
- end
- for i=1, #config[6] do
- if nazwa == #config[6][i] then
- term.setCursorPos(1,3)
- FreshApi.centerPrint("Nazwa nie moze przekraczac ".. 34 - #config[5] " znakow.")
- a = "false"
- sleep(1.5)
- end
- end
- if #nazwa < 1 then
- term.setCursorPos(1,3)
- FreshApi.centerPrint("Podaj nazwe.")
- a = "false"
- sleep(1.5)
- end
- if a == "true" then
- wysSig(id, name, r)
- config[6][#config[6]+1] = nazwa
- sTable("edytor/Settings", config)
- break
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement