Advertisement
Guest User

Browser 0.3b

a guest
Jul 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.24 KB | None | 0 0
  1. -- Browser 0.3b
  2.  
  3. -- Nic tu nie zmieniaj. Haslo do admina - 5050
  4.  
  5. debug = true
  6.  
  7.  
  8.  
  9. slow = true
  10. if debug then
  11. slow = false
  12. end
  13.  
  14. if fs.exists("FreshApi") then
  15. os.unloadAPI("FreshApi")
  16. os.loadAPI("FreshApi")
  17. else
  18. error("Zainstaluj FreshAPI")
  19. end
  20.  
  21. function sTable(file, table)
  22. f = fs.open(file, "w")
  23. f.write(textutils.serialize(table))
  24. f.close()
  25. end
  26.  
  27. function lTable(file)
  28. f = fs.open(file, "r")
  29. table = textutils.unserialize(f.readAll())
  30. f.close()
  31. return table
  32. end
  33.  
  34. function ping()
  35. received = {}
  36. test = {}
  37. n2 = {}
  38. a = 0
  39. if config[3] == 2 then
  40. sleep(0.5)
  41. end
  42. while true do
  43. a = a + 1
  44. received[a] = {}
  45. event, id, txt, xd = os.pullEvent("rednet_message")
  46. if txt:find("BTSHello") then
  47. n = textutils.unserialize(txt)
  48. n2[a] = n[2]
  49. received[a][1] = id
  50. received[a][2] = n2[a]
  51. received[a][3] = xd
  52. end
  53. end
  54. end
  55.  
  56. function timer()
  57. ot2 = "false"
  58. if config[3] == 2 then
  59. timer1 = os.startTimer(5)
  60. else
  61. timer1 = os.startTimer(0.2)
  62. end
  63. while true do
  64. event, timer2 = os.pullEvent("timer")
  65. if event == "timer" and timer2 == timer1 then
  66. ot2 = "true"
  67. break
  68. end
  69. end
  70. end
  71.  
  72. function getBTS()
  73. rednet.broadcast("HelloBTS")
  74. parallel.waitForAny(timer, ping)
  75. return received
  76. end
  77.  
  78. ver = "0.3b"
  79. sides = rs.getSides()
  80. config = {}
  81.  
  82. function inf (gt)
  83. term.clear()
  84. term.setCursorPos(1,1)
  85. FreshApi.centerPrint("| KrzakBrowser ".. ver.. " |")
  86. term.setCursorPos(1,2)
  87. if gt then
  88. textutils.slowPrint(FreshApi.line(), 100)
  89. else
  90. FreshApi.drawLine()
  91. end
  92. term.setCursorPos(1,3)
  93. term.clearLine()
  94. end
  95.  
  96. function signal(dis)
  97. dis = tonumber(dis)
  98. sig = "[ ]"
  99. if dis == nil then
  100. dis = 513
  101. sig = "[ ]"
  102. end
  103. if dis < 113 then
  104. sig = "[*****]"
  105. end
  106. if dis < 201 then
  107. if dis > 113 then
  108. sig = "[**** ]"
  109. end
  110. end
  111. if dis < 301 then
  112. if dis > 201 then
  113. sig = "[*** ]"
  114. end
  115. end
  116. if dis < 401 then
  117. if dis > 301 then
  118. sig = "[** ]"
  119. end
  120. end
  121. if dis < 513 then
  122. if dis > 401 then
  123. sig = "[* ]"
  124. end
  125. end
  126. return sig
  127. end
  128.  
  129. function zaladuj(cal, site)
  130. tab = cal[1]
  131. tec = cal[2]
  132. t = 1
  133. d = 5
  134. wybor = 7
  135. w,h = term.getSize()
  136. scr = 0
  137. wysSig(id, name, r)
  138. term.setCursorPos(1,3)
  139. term.write("Adres:")
  140. term.setCursorPos(7,3)
  141. term.write(site)
  142. term.setCursorPos(1,4)
  143. FreshApi.drawLine()
  144. while true do
  145. term.setCursorPos(1,3)
  146. term.clearLine()
  147. term.write("Adres:")
  148. term.setCursorPos(7,3)
  149. term.write(site)
  150. term.setCursorPos(1,4)
  151. FreshApi.drawLine()
  152. c,v = term.getSize()
  153. --if #tab > 10 then
  154. tabL = 13
  155. --else
  156. -- tabL = #tab
  157. --end
  158. a = 0
  159. term.setCursorPos(1, 18)
  160. term.clearLine()
  161. term.write("Enter Link F3 Cofnij F4 Szukaj F5 Odswiez")
  162. for i=1,tabL do
  163. a = a + 1
  164. term.setCursorPos(t, d + a - 1)
  165. term.clearLine()
  166. if a+scr == wybor-6 then
  167. if tab[i+scr] == nil then
  168. write(">")
  169. else
  170. write(">".. tostring(tab[i+scr]))
  171. end
  172. else
  173. if tab[i+scr] == nil then
  174. write("")
  175. else
  176. write(" ".. tostring(tab[i+scr]))
  177. end
  178. end
  179. end
  180. event, key = os.pullEvent("key")
  181. if key == 200 and wybor-6>1 then
  182. if wybor > 13 then
  183. scr = scr - 1
  184. end
  185. wybor = wybor - 1
  186. elseif key == 208 then
  187. wybor = wybor + 1
  188. if wybor > 13 then
  189. scr = scr + 1
  190. end
  191. elseif key == 63 then
  192. bk = "false"
  193. break
  194. elseif key == 61 then
  195. elseif key == 62 then
  196. bk = "true"
  197. break
  198. elseif key == 28 then
  199. term.setCursorPos(1, 18)
  200. term.clearLine()
  201. term.write('Wpisz "Anuluj123" aby anulowac')
  202. term.setCursorPos(1, 3)
  203. term.clearLine()
  204. FreshApi.centerPrint("Wpisz tekst")
  205. term.setCursorPos(1,17)
  206. term.clearLine()
  207. term.write(">")
  208. term.setCursorPos(2,17)
  209. input = read()
  210. if #input > 48 then
  211. term.setCursorPos(1,17)
  212. term.clearLine()
  213. FreshApi.centerPrint("Tekst nie moze przekraczac 48 znakow.")
  214. sleep(1.5)
  215. wysSig(id, name, r)
  216. else
  217. if input == "Anuluj123" or input == '"Anuluj123"' then
  218. else
  219. tab[wybor-6] = input
  220. end
  221. end
  222. end
  223. end
  224. end
  225.  
  226. function pgError(er)
  227. if er == 401 then
  228. end
  229. end
  230.  
  231. function connect()
  232. getBTS()
  233. our = {}
  234. r = "false"
  235. output = "false"
  236. p = 0
  237. for i=1, #received do
  238. if n2[i] == config[2] then
  239. p = p + 1
  240. our[p] = received[i][1]
  241. end
  242. end
  243. for i=1, #our do
  244. rednet.send(our[i], "connectBTS")
  245. parallel.waitForAny(timer, receive)
  246. if txt == "true" then
  247. output = id
  248. name = config[2]
  249. break
  250. end
  251. end
  252. if output == "false" then
  253. sleep(1)
  254. for i=1, #received do
  255. for o=1, #config[4] do
  256. if n2[i] == config[4][o] then
  257. print(received[i][1])
  258. rednet.send(received[i][1], "connectBTS")
  259. parallel.waitForAny(timer, receive)
  260. if txt == "true" then
  261. name = config[4][o]
  262. r = "true"
  263. output = id
  264. break
  265. end
  266. end
  267. end
  268. end
  269. end
  270. return output, name, r
  271. end
  272.  
  273. function receive()
  274. ot = "false"
  275. while true do
  276. event, id, txt, dis = os.pullEvent("rednet_message")
  277. if event == "rednet_message" then
  278. ot = "true"
  279. break
  280. end
  281. return id, txt, dis, ot
  282. end
  283. end
  284.  
  285. function wysSig(id, name, r)
  286. while true do
  287. if id == "false" then
  288. FreshApi.centerText("Brak Polaczenia...")
  289. while true do
  290. id = connect()
  291. if id == "false" then
  292. else
  293. break
  294. end
  295. end
  296. end
  297. rednet.send(id, "HelloBTS")
  298. parallel.waitForAny(timer, receive)
  299. nm = ""
  300. if ot then
  301. nm = " ".. tostring(name)
  302. else
  303. nm = "Brak Polaczenia"
  304. end
  305. term.clear()
  306. term.setCursorPos(1,1)
  307. print(nm)
  308. if r == "true" then
  309. term.setCursorPos(39, 1)
  310. print("[R] ".. tostring(signal(dis)))
  311. else
  312. term.setCursorPos(42, 1)
  313. print(tostring(signal(dis)))
  314. end
  315. term.setCursorPos(1,1)
  316. FreshApi.centerPrint(" | KrzakBrowser ".. " | ")
  317. term.setCursorPos(1,2)
  318. FreshApi.drawLine()
  319. term.setCursorPos(1,3)
  320. term.clearLine()
  321. if ot then
  322. break
  323. else
  324. FreshApi.centerText("Brak Polaczenia...")
  325. while true do
  326. id = connect()
  327. if id == "false" then
  328. else
  329. break
  330. end
  331. end
  332. end
  333. end
  334. end
  335.  
  336. inf(slow)
  337.  
  338. if fs.exists("Settings") then
  339. config = lTable("Settings")
  340. rednet.open(config[1])
  341. else
  342. term.setCursorPos(1,3)
  343. FreshApi.centerPrint("Pierwsza konfiguracja.")
  344. sleep(1.5)
  345. term.setCursorPos(1,3)
  346. term.clearLine()
  347. FreshApi.centerPrint("Wybierz rodzaj polaczenia.")
  348. s = FreshApi.drawMenu({"Modem", "Kabel"}, 2, 5)
  349. config[3] = s
  350. term.setCursorPos(1,3)
  351. term.clearLine()
  352. inf(slow)
  353. if config[3] == 1 then
  354. FreshApi.centerPrint("Wybierz strone z ktorej jest modem.")
  355. else
  356. FreshApi.centerPrint("Wybierz strone z ktorej jest kabel.")
  357. end
  358. s = FreshApi.drawMenu(sides, 2, 5)
  359. config[1] = sides[s]
  360. rednet.open(config[1])
  361. inf(slow)
  362. term.setCursorPos(1, 3)
  363. term.clearLine()
  364. getBTS()
  365. FreshApi.centerPrint("Lista dostepnych operatorow. Wybierz jednego.")
  366. list = {}
  367. wys = {}
  368. for i=1, #n2 do
  369. if n2[i] == nil then
  370. else
  371. for i2=i+1, #n2 do
  372. if n2[i] == n2[i2] then
  373. table.remove(n2, i2)
  374. table.remove(received, i2)
  375. end
  376. end
  377. end
  378. end
  379. for i=1, #n2 do
  380. if not n2[i] == nil then
  381. else
  382. list[i] = n2[i]
  383. zm = n2[i]
  384. if config[3] == 1 then
  385. wys[i] = " ".. zm.. " ".. tostring(signal(received[i][3])).. " "
  386. else
  387. wys[i] = " ".. zm.. " "
  388. end
  389. end
  390. end
  391. wbr = FreshApi.drawMenu(wys, 2, 5)
  392. config[2] = list[wbr]
  393. y = 1
  394. w = {}
  395. list2 = {}
  396. for i=1, #list do
  397. list2[i] = " ".. list[i].. " "
  398. end
  399. list2[#list2+1] = "Dalej"
  400. inf(slow)
  401. term.setCursorPos(1, 3)
  402. term.clearLine()
  403. FreshApi.centerPrint("Lista dostepnych operatorow. Wybierz rumuningi.")
  404. while true do
  405. inf(false)
  406. term.setCursorPos(1, 3)
  407. term.clearLine()
  408. FreshApi.centerPrint("Lista dostepnych operatorow. Wybierz rumuningi. XD")
  409. l = FreshApi.drawMenu(list2, 2, 5)
  410. if l == #list2 then
  411. break
  412. else
  413. finding = list2[l]
  414. if finding:find("[R]") then
  415. list2[l] = " ".. list[l].. " "
  416. else
  417. list2[l] = " ".. list2[l].. " [R] "
  418. end
  419. end
  420. end
  421. for i=1, #list2 do
  422. finding = list2[i]
  423. if finding:find("[R]") then
  424. w[y] = list[i]
  425. y = y + 1
  426. end
  427. end
  428. config[4] = w
  429. sTable("Settings", config)
  430. FreshApi.centerText("Skonfigurowano pomyslnie.")
  431. sleep(1)
  432. term.clear()
  433. end
  434.  
  435.  
  436. while true do
  437. id, name, r = connect()
  438. wysSig(id, name, r)
  439. term.setCursorPos(1, 3)
  440. term.write("Adres:")
  441. term.setCursorPos(1, 4)
  442. FreshApi.drawLine()
  443. term.setCursorPos(7, 3)
  444. input = read()
  445. gID = os.getComputerID()
  446. tbl = {}
  447. t = {}
  448. t[1] = gID
  449. t[2] = input
  450. b = 0
  451. while true do
  452. b = b + 1
  453. if b == 10 then
  454. id, name, r = connect()
  455. wysSig(id, name, r)
  456. end
  457. if b == 15 then
  458. term.clear()
  459. id, name, r = connect()
  460. wysSig(id, name, r)
  461. term.setCursorPos(1, 3)
  462. term.write("Adres:")
  463. term.setCursorPos(1, 4)
  464. FreshApi.drawLine()
  465. term.setCursorPos(7, 3)
  466. term.write(input)
  467. FreshApi.centerText("Error 404. Wcisnij cokolwiek...")
  468. os.pullEvent("key")
  469. break
  470. end
  471. sleep(0.1)
  472. wid = textutils.serialize(t)
  473. rednet.send(id, wid)
  474. parallel.waitForAny(receive, timer)
  475. txtT = textutils.unserialize(txt)
  476. if txtT == nil then
  477. else
  478. if txtT[1] == gID then
  479. zaladuj(txtT[2], input)
  480. if bk == "true" then
  481. term.clear()
  482. break
  483. else
  484. term.clear()
  485. end
  486. end
  487. end
  488. end
  489. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement