Advertisement
Chaos_Cash

Connection main backup: 01.03.2024

Mar 1st, 2024
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.39 KB | None | 0 0
  1. function startup()
  2.  
  3. settings = {}
  4. settings["names"] = {}
  5. settings["len"] = 0
  6.  
  7. old_label={}
  8. label_save={}
  9.  
  10. got_response=0
  11.  
  12. connected_pcs={}
  13. connected_pcs["len"]=0
  14. connected_pcs["got_response"]={}
  15.  
  16. button_positions={}
  17. button_positions["status"]={}
  18.  
  19. connected_pcs["number"]={}
  20. connected_pcs["number_of_id"]={}
  21.  
  22. connected_pcs["labels"]={}
  23. connected_pcs["labels"]["is_nil"]={}
  24. connected_pcs["labels"]["len"]=0
  25. for i=1,3 do
  26. connected_pcs["labels"]["line"..i]={}
  27. end
  28.  
  29. rednet.open("top")
  30.  
  31. connections=fs.open("connections","a")
  32.  
  33. connections.close()
  34.  
  35.  
  36. if not fs.exists("connection_code") then
  37.  
  38. term.clear()
  39. term.setCursorPos(1,1)
  40. term.setTextColor(colors.green)
  41. print("Please enter the name you want to use to connect")
  42. print("to other PC´s")
  43. print()
  44. term.setTextColor(colors.white)
  45. connection_name=read()
  46.  
  47. connection_code=fs.open("connection_code","w")
  48. connection_code.writeLine(connection_name)
  49. connection_code.flush()
  50. connection_code.close()
  51.  
  52. end
  53.  
  54. if not fs.exists("settings") then
  55.  
  56. settings_save = fs.open("settings","w")
  57.  
  58. settings_save.writeLine("off")
  59.  
  60. settings_save.flush()
  61. settings_save.close()
  62. end
  63.  
  64. assign_name()
  65.  
  66. mon=peripheral.wrap("right")
  67. mon.setTextScale(0.5)
  68.  
  69.  
  70. logs={}
  71. logs["len"]=0
  72. logs["entries"]={}
  73. logs["time"]={}
  74.  
  75.  
  76. assign_connections()
  77.  
  78. assign_labels()
  79.  
  80. for i=1,connected_pcs["len"] do
  81. rednet.send(tonumber(connected_pcs["id"][i]),{["sending_to"]=connected_pcs["name"][i],["name"]=connection_name,["status"]="get_info"})
  82. end
  83.  
  84. create_setting("solo")
  85. assign_settings()
  86.  
  87. end
  88.  
  89.  
  90.  
  91.  
  92. function screen()
  93.  
  94. cur_x1=1
  95. cur_y1=1
  96. cur_x2=7
  97. cur_y2=5
  98. cur_connection=1
  99. button_positions["len"]=0
  100.  
  101. mon.clear()
  102.  
  103. for i=1,math.ceil(connected_pcs["len"]^0.5) do
  104.  
  105. for i1=1,math.ceil(connected_pcs["len"]^0.5) do
  106. if connected_pcs["name"][cur_connection]~=nil then
  107. if button_positions["status"][cur_connection]=="on" then
  108. mon_button(connected_pcs["name"][cur_connection],cur_x1,cur_y1,cur_x2,cur_y2)
  109. end
  110. if button_positions["status"][cur_connection]=="off" then
  111. mon_button(connected_pcs["name"][cur_connection],cur_x1,cur_y1,cur_x2,cur_y2,colors.red)
  112. end
  113. if button_positions["status"][cur_connection]==nil then
  114. mon_button(connected_pcs["name"][cur_connection],cur_x1,cur_y1,cur_x2,cur_y2,colors.blue)
  115. end
  116. button_positions[cur_connection]={}
  117. button_positions[cur_connection]={["x1"]=cur_x1,["y1"]=cur_y1,["x2"]=cur_x2,["y2"]=cur_y2,["id"]=connected_pcs["id"][cur_connection],["status"]="on"}
  118. button_positions["len"]=button_positions["len"]+1
  119. end
  120. cur_x1=cur_x1+8
  121. cur_x2=cur_x2+8
  122. cur_connection=cur_connection+1
  123. end
  124.  
  125. cur_y1=cur_y1+5
  126. cur_y2=cur_y2+5
  127.  
  128. cur_x1=1
  129. cur_x2=7
  130.  
  131. end
  132. end
  133.  
  134.  
  135.  
  136.  
  137. function menu()
  138.  
  139. cur_env="menu"
  140.  
  141. term.setBackgroundColor(colors.black)
  142. term.clear()
  143.  
  144. headline("Menu")
  145. button("Connections",12,7,25,9)
  146. button("Change name",27,7,40,9)
  147. button("Settings",27,11,40,13)
  148. button("Log",12,11,25,13)
  149.  
  150. end
  151.  
  152.  
  153.  
  154.  
  155. function pull(loop_time)
  156.  
  157. if tonumber(loop_time)~=nil then
  158. timer_id=os.startTimer(loop_time)
  159. end
  160.  
  161. while info_1~="timer" or timer_id~=info_2 do
  162.  
  163. last_info_1 = info_1
  164. last_info_2 = info_2
  165. last_info_3 = info_3
  166. last_info_4 = info_4
  167.  
  168. info_1, info_2, info_3, info_4 = os.pullEvent()
  169.  
  170.  
  171. if info_1=="rednet_message" and info_3["sending_to"]==connection_name then
  172.  
  173. if info_3["sending_status"] then
  174. if button_positions["status"][connected_pcs["number"][info_3["name"]]]~=info_3["status"] then
  175. button_positions["status"][connected_pcs["number"][info_3["name"]]]=info_3["status"]
  176. screen()
  177. end
  178. end
  179.  
  180. if tonumber(answer_id)==tonumber(info_2) then
  181. answered=true
  182. end
  183.  
  184. end
  185.  
  186.  
  187. if info_1=="rednet_message" and info_3["connecting_to"]==connection_name then
  188.  
  189.  
  190. already_connected=false
  191. same_id=false
  192. same_name=false
  193.  
  194. for i=1,connected_pcs["len"] do
  195.  
  196. if tonumber(connected_pcs["id"][i])==tonumber(info_2) then
  197. same_id=true
  198. end
  199.  
  200. if info_3["name"] == connected_pcs["name"][i] then
  201. same_name=true
  202. end
  203.  
  204. end
  205.  
  206. if not same_id and not same_name then
  207.  
  208. connections = fs.open("connections","a")
  209. connections.writeLine(info_3["name"])
  210. connections.writeLine(info_2)
  211. connections.close()
  212. assign_connections()
  213.  
  214. create_log_entry("Connected to the PC named: "..info_3["name"])
  215. change_connection_menu=true
  216. screen()
  217. rednet.send(info_2,{["name"]=connection_name,["connecting_to"]=info_3["name"]})
  218.  
  219. elseif same_id then
  220. create_log_entry("rejected PC because was already connected, name: "..info_3["name"])
  221. rednet.send(info_2,{["name"]=connection_name,["sending_to"]=info_3["name"],["status"]="disconnected",["same_id"]=true})
  222. elseif same_name then
  223. create_log_entry("rejected PC because a PC with the same name was already connected, name: "..info_3["name"])
  224. rednet.send(info_2,{["name"]=connection_name,["sending_to"]=info_3["name"],["status"]="disconnected",["same_name"]=true})
  225. end
  226.  
  227. end
  228.  
  229.  
  230. for i=1,button_positions["len"] do
  231.  
  232. if mon_button_check(button_positions[i]["x1"],button_positions[i]["y1"],button_positions[i]["x2"],button_positions[i]["y2"]) then
  233.  
  234. if settings["solo"]["status"]~="on" then
  235. rednet.send(tonumber(connected_pcs["id"][i]),{["sending_to"]=connected_pcs["name"][i],["name"]=connection_name,["status"]="change_status"})
  236. answer_id=connected_pcs["id"][i]
  237. answered=false
  238. pull(0.05,true)
  239.  
  240. if not answered then
  241. screen()
  242. x,y=mon.getSize()
  243. mon.setCursorPos(math.floor(x/2-string.len("ERROR,open log for more info")/2),math.floor(y/2))
  244. mon.setTextColor(colors.red)
  245. mon.write("ERROR,open log for more info")
  246.  
  247. create_log_entry("The PC named, "..connected_pcs["name"][i]..", did not respond, its probably not loaded or the programm is not running")
  248.  
  249. os.startTimer(0.05)
  250. pull(3)
  251. screen()
  252. end
  253.  
  254. else
  255.  
  256. answered_pcs=0
  257. pcs_that_are_on=0
  258. for i1=1,connected_pcs["len"] do
  259. if button_positions["status"][i1] == "on" or i1==i then
  260. pcs_that_are_on=pcs_that_are_on+1
  261. rednet.send(tonumber(connected_pcs["id"][i1]),{["sending_to"]=connected_pcs["name"][i1],["name"]=connection_name,["status"]="get_info"})
  262. answer_id=connected_pcs["id"][i1]
  263. answered=false
  264. pull(0.01,true)
  265. if answered then
  266. answered_pcs=answered_pcs+1
  267. else
  268. create_log_entry("The PC named, "..connected_pcs["name"][i1]..", did not respond, its probably not loaded or the programm is not running")
  269. end
  270. end
  271. end
  272.  
  273.  
  274. if answered_pcs==pcs_that_are_on then
  275.  
  276. for i1=1,connected_pcs["len"] do
  277. if button_positions["status"][i1] == "on" or i1==i then
  278.  
  279. rednet.send(tonumber(connected_pcs["id"][i1]),{["sending_to"]=connected_pcs["name"][i1],["name"]=connection_name,["status"]="change_status"})
  280.  
  281. end
  282. end
  283.  
  284. else
  285.  
  286. screen()
  287. x,y=mon.getSize()
  288. mon.setCursorPos(math.floor(x/2-string.len("ERROR,open log for more info")/2),math.floor(y/2))
  289. mon.setTextColor(colors.red)
  290. mon.write("ERROR,open log for more info")
  291.  
  292. pull(3)
  293. screen()
  294.  
  295. end
  296. end
  297. end
  298.  
  299. end
  300.  
  301.  
  302. if cur_env=="menu" then
  303.  
  304. if button_check(27,7,40,9) then
  305. change_name()
  306. end
  307.  
  308. if button_check(12,11,25,13) then
  309. log()
  310. end
  311.  
  312. if button_check(12,7,25,9) then
  313. connection_menu()
  314. end
  315.  
  316. if button_check(27,11,40,13) then
  317. settings_menu()
  318. end
  319.  
  320. end
  321.  
  322. if cur_env=="log" then
  323.  
  324. if change_log then
  325. log()
  326. end
  327.  
  328. if button_check(44,17,51,19) then
  329. menu()
  330. end
  331.  
  332. end
  333.  
  334.  
  335. if cur_env=="connection_menu" then
  336.  
  337. if button_check(44,17,51,19) then
  338. menu()
  339. end
  340.  
  341.  
  342. for i=1,connected_pcs["len"] do
  343.  
  344.  
  345. if info_1=="mouse_click" and info_4==i+3 then
  346. connection_menu()
  347. term.setBackgroundColor(colors.red)
  348. term.setCursorPos(1,i+3)
  349. term.setTextColor(colors.green)
  350. term.write("[Id-"..tonumber(connected_pcs["id"][i]).."]")
  351.  
  352. for i1=1,9-string.len("[Id-"..tonumber(connected_pcs["id"][i]).."]") do
  353. write(" ")
  354. end
  355.  
  356. term.setTextColor(colors.white)
  357. term.write(connected_pcs["name"][i])
  358.  
  359. for i1=1,51-string.len(connected_pcs["name"][i])-9 do
  360. term.write(" ")
  361. end
  362.  
  363. button("Delete",1,17,10,19,colors.red)
  364. button("Settings",12,17,22,19)
  365.  
  366. if i~=clicked_connection then
  367. clicked_connection=i
  368. else
  369. clicked_connection=nil
  370. connection_menu()
  371. end
  372. end
  373. end
  374.  
  375. if clicked_connection~=nil then
  376. if button_check(1,17,10,19) then
  377. rednet.send(tonumber(connected_pcs["id"][clicked_connection]),{["sending_to"]=connected_pcs["name"][clicked_connection],["status"]="disconnected"})
  378. disconnect(clicked_connection)
  379. clicked_connection=nil
  380. connection_menu()
  381. end
  382.  
  383. if button_check(12,17,22,19) then
  384. connection_settings(clicked_connection)
  385. end
  386. end
  387.  
  388. if change_connection_menu then
  389. connection_menu()
  390.  
  391. if clicked_connection~=nil then
  392.  
  393. term.setBackgroundColor(colors.red)
  394. term.setCursorPos(1,clicked_connection+3)
  395. term.setTextColor(colors.green)
  396. term.write("[Id-"..tonumber(connected_pcs["id"][clicked_connection]).."]")
  397.  
  398. for i1=1,9-string.len("[Id-"..tonumber(connected_pcs["id"][clicked_connection]).."]") do
  399. write(" ")
  400. end
  401.  
  402. term.setTextColor(colors.white)
  403. term.write(connected_pcs["name"][clicked_connection])
  404.  
  405. for i1=1,51-string.len(connected_pcs["name"][clicked_connection])-9 do
  406. term.write(" ")
  407. end
  408.  
  409. button("Delete",1,17,10,19,colors.red)
  410. button("Settings",12,17,22,19)
  411.  
  412. end
  413.  
  414. change_connection_menu=false
  415. end
  416.  
  417. if clicked_connection~=nil then
  418. if ((last_info_1=="mouse_click" or last_info_1=="mouse_drag") and last_info_4==clicked_connection+3) and (info_1=="mouse_drag" and (info_4 < clicked_connection+3 or info_4 > clicked_connection+3)) then
  419. if info_4-3 < connected_pcs["len"]+1 and info_4-3>0 then
  420. change_connection_order(clicked_connection,info_4-3)
  421. end
  422. end
  423. end
  424.  
  425. end
  426.  
  427.  
  428. if cur_env=="change_name" then
  429.  
  430. if info_1=="rednet_message" and info_3["sending_to"]==connection_name then
  431. if info_3["sending_status"] then
  432. button_positions["status"][connected_pcs["number"][info_3["name"]]]=info_3["status"]
  433. screen()
  434. got_response=got_response+1
  435. connected_pcs["got_response"][connected_pcs["number"][info_3["name"]]]=true
  436. end
  437. end
  438.  
  439. end
  440.  
  441.  
  442. if cur_env=="connection_settings" then
  443.  
  444. if button_check(44,17,51,19) then
  445. connection_menu()
  446. end
  447.  
  448. if button_check(3,3,16,5) then
  449. label_settings(clicked_connection)
  450. end
  451. end
  452.  
  453.  
  454. if cur_env=="label_settings" then
  455.  
  456. if button_check(44,17,51,19) then
  457. connection_settings(clicked_connection)
  458. end
  459.  
  460. if info_1=="mouse_click" and info_4 < 6 and info_4 > 2 then
  461. term.setTextColor(colors.green)
  462. term.setCursorPos(1,info_4)
  463. term.write("Line "..tostring(info_4-2)..": ")
  464. term.setTextColor(colors.white)
  465. for i=1,42 do
  466. write(" ")
  467. end
  468. term.setCursorPos(9,info_4)
  469. new_text=read()
  470. edit_label(clicked_connection,info_4-2,new_text)
  471. end
  472.  
  473. end
  474.  
  475.  
  476. if cur_env=="settings" then
  477.  
  478. if button_check(44,17,51,19) then
  479. menu()
  480. end
  481.  
  482. if button_check(3,3,12,5) then
  483. if settings["solo"]["status"]=="on" then
  484. change_setting("solo","off")
  485. else
  486. change_setting("solo","on")
  487. end
  488. settings_menu()
  489. end
  490. end
  491.  
  492. end
  493. info_1=nil
  494. end
  495.  
  496.  
  497.  
  498. function settings_menu()
  499. cur_env="settings"
  500. info_1=nil
  501.  
  502. term.clear()
  503. headline("Settings")
  504. button("Back",44,17,51,19)
  505.  
  506. if settings["solo"]["status"] == "on" then
  507. button("Solo",3,3,12,5)
  508. else
  509. button("Solo",3,3,12,5,colors.red)
  510. end
  511.  
  512. end
  513.  
  514.  
  515.  
  516. function create_setting(name)
  517.  
  518. settings[name] = {}
  519.  
  520. settings["len"]=settings["len"]+1
  521.  
  522. settings["names"][settings["len"]] = name
  523.  
  524. settings[name]["number"] = settings["len"]
  525.  
  526. end
  527.  
  528.  
  529.  
  530. function assign_settings()
  531.  
  532. settings_save = fs.open("settings","r")
  533.  
  534. for i=1,settings["len"] do
  535. settings[i] = {}
  536. settings[settings["names"][i]]["status"] = settings_save.readLine()
  537. settings[i]["status"] = settings[settings["names"][i]]["status"]
  538. end
  539. settings_save.close()
  540. end
  541.  
  542.  
  543.  
  544. function change_setting(name,new_status)
  545.  
  546. settings_save = fs.open("settings","w")
  547.  
  548. for i=1,settings[name]["number"]-1 do
  549. settings_save.writeLine(settings[i]["status"])
  550. end
  551.  
  552. settings_save.writeLine(new_status)
  553.  
  554. for i=1,settings["len"]-settings[name]["number"] do
  555. settings_save.writeLine(settings[i+settings[name]["number"]]["status"])
  556. end
  557.  
  558. settings_save.flush()
  559. settings_save.close()
  560.  
  561. assign_settings()
  562. end
  563.  
  564.  
  565.  
  566. function change_connection_order(changing,change_to)
  567.  
  568. connection_save_name = connected_pcs["name"][changing]
  569. connection_save_id = connected_pcs["id"][changing]
  570. status_save = button_positions["status"][changing]
  571. for i=1,3 do
  572. label_save[i] = connected_pcs["labels"]["line"..i][changing]
  573. end
  574.  
  575. connected_pcs["name"][changing] = connected_pcs["name"][change_to]
  576. connected_pcs["id"][changing] = connected_pcs["id"][change_to]
  577. button_positions["status"][changing] = button_positions["status"][change_to]
  578. for i=1,3 do
  579. connected_pcs["labels"]["line"..i][changing] = connected_pcs["labels"]["line"..i][change_to]
  580. end
  581.  
  582. connected_pcs["name"][change_to] = connection_save_name
  583. connected_pcs["id"][change_to] = connection_save_id
  584. button_positions["status"][change_to] = status_save
  585. for i=1,3 do
  586. connected_pcs["labels"]["line"..i][change_to] = label_save[i]
  587. end
  588.  
  589.  
  590. connections = fs.open("connections","w")
  591.  
  592. for i=1,connected_pcs["len"] do
  593. connections.writeLine(connected_pcs["name"][i])
  594. connections.writeLine(connected_pcs["id"][i])
  595. end
  596. connections.flush()
  597. connections.close()
  598.  
  599. if clicked_connection==changing then
  600. clicked_connection=change_to
  601. end
  602.  
  603. assign_connections()
  604. change_connection_menu=true
  605. screen()
  606. end
  607.  
  608.  
  609.  
  610. function connection_menu()
  611.  
  612. if cur_env~="connection_menu" then
  613. info_1=nil
  614. end
  615.  
  616. cur_env="connection_menu"
  617.  
  618. term.setBackgroundColor(colors.black)
  619. term.clear()
  620. headline("Connections")
  621. button("Back",44,17,51,19)
  622. term.setCursorPos(1,4)
  623.  
  624. for i=1,connected_pcs["len"] do
  625.  
  626. term.setTextColor(colors.green)
  627. term.write("[Id-"..tonumber(connected_pcs["id"][i]).."]")
  628.  
  629. for i1=1,9-string.len("[Id-"..tonumber(connected_pcs["id"][i]).."]") do
  630. write(" ")
  631. end
  632.  
  633. term.setTextColor(colors.white)
  634. print(connected_pcs["name"][i])
  635.  
  636. end
  637.  
  638. end
  639.  
  640.  
  641.  
  642. function assign_name()
  643.  
  644. connection_code = fs.open("connection_code","r")
  645. connection_name = connection_code.readLine()
  646. connection_code.close()
  647.  
  648. end
  649.  
  650.  
  651.  
  652. function change_name()
  653.  
  654. cur_env="change_name"
  655.  
  656. term.clear()
  657. term.setCursorPos(1,1)
  658. term.setTextColor(colors.green)
  659. print("Please enter the name you want to use to connect")
  660. print("to other PC´s")
  661. print()
  662. term.write("Old name: ")
  663. term.setBackgroundColor(colors.white)
  664. term.setTextColor(colors.blue)
  665. print(" "..connection_name.." ")
  666. print()
  667. term.setTextColor(colors.white)
  668. term.setBackgroundColor(colors.black)
  669. new_name=read()
  670.  
  671. term.clear()
  672. term.setCursorPos(1,1)
  673. term.setTextColor(colors.green)
  674. write("Changing name...")
  675.  
  676.  
  677. for i=1,connected_pcs["len"] do
  678. rednet.send(tonumber(connected_pcs["id"][i]),{["sending_to"]=connected_pcs["name"][i],["name"]=connection_name,["status"]="get_info"})
  679. end
  680.  
  681. got_response=0
  682.  
  683. for i=1,connected_pcs["len"] do
  684. connected_pcs["got_response"][i]=false
  685. end
  686.  
  687. pull(1)
  688.  
  689.  
  690. if not (got_response < connected_pcs["len"]) then
  691.  
  692. for i=1,connected_pcs["len"] do
  693. rednet.send(tonumber(connected_pcs["id"][i]),{["sending_to"]=connected_pcs["name"][i],["name"]=connection_name,["status"]="changing_name",["new_name"]=new_name})
  694. end
  695.  
  696. connection_name = new_name
  697. connection_code=fs.open("connection_code","w")
  698. connection_code.writeLine(connection_name)
  699. connection_code.flush()
  700. connection_code.close()
  701.  
  702. else
  703.  
  704. for i=1,connected_pcs["len"] do
  705. if not connected_pcs["got_response"][i] then
  706. create_log_entry("The name could not be changed, because the PC named:, "..connected_pcs["name"][i]..", did not respond.")
  707. end
  708. end
  709.  
  710. term.clear()
  711. term.setTextColor(colors.red)
  712. term.setCursorPos(1,1)
  713. term.write("ERROR,open log for more info")
  714. pull(3)
  715. menu()
  716. end
  717.  
  718. menu()
  719. end
  720.  
  721.  
  722.  
  723. function log()
  724.  
  725. cur_env="log"
  726.  
  727. term.setBackgroundColor(colors.black)
  728. term.clear()
  729. button("Back",44,17,51,19)
  730. headline("Log")
  731.  
  732. term.setCursorPos(1,4)
  733. term.setTextColor(colors.white)
  734. term.setBackgroundColor(colors.black)
  735.  
  736. if logs["len"] < 13 then
  737.  
  738. for i=1,12 do
  739.  
  740. if logs["time"][i]~=nil then
  741.  
  742. term.setTextColor(colors.green)
  743. write("[")
  744. write(math.floor(logs["time"][i]))
  745. write(":")
  746. write(math.floor( math.floor( (logs["time"][i]-math.floor(logs["time"][i])) *100 ) /1.6666666 ) )
  747. write("]")
  748.  
  749. for i1=1,7-string.len("["..math.floor(logs["time"][i])..":"..math.floor( math.floor( (logs["time"][i]-math.floor(logs["time"][i])) *100 ) /1.6666666 ).."]") do
  750. write(" ")
  751. end
  752.  
  753. term.setTextColor(colors.white)
  754. print(logs["entries"][i])
  755.  
  756. end
  757.  
  758. end
  759.  
  760. else
  761.  
  762. for i=1,12 do
  763.  
  764. if logs["time"][logs["len"]-12+i]~=nil then
  765.  
  766. term.setTextColor(colors.green)
  767. write("[")
  768. write(math.floor(logs["time"][logs["len"]-12+i]))
  769. write(":")
  770. write(math.floor( math.floor( (logs["time"][logs["len"]-12+i]-math.floor(logs["time"][logs["len"]-12+i])) *100 ) /1.6666666 ) )
  771. write("]")
  772.  
  773. for i1=1,7-string.len("["..math.floor(logs["time"][logs["len"]-12+i])..":"..math.floor( math.floor( (logs["time"][logs["len"]-12+i]-math.floor(logs["time"][logs["len"]-12+i])) *100 ) /1.6666666 ).."]") do
  774. write(" ")
  775. end
  776.  
  777. term.setTextColor(colors.white)
  778. print(logs["entries"][logs["len"]-12+i])
  779.  
  780. end
  781.  
  782. end
  783.  
  784. end
  785.  
  786. change_log=false
  787. end
  788.  
  789.  
  790.  
  791. function assign_connections()
  792.  
  793. connections=fs.open("connections","r")
  794.  
  795. connected_pcs["name"]={}
  796. connected_pcs["len"]=0
  797. connected_pcs["id"]={}
  798. connected_pcs["id"][0]="0"
  799. i=0
  800. while tonumber(connected_pcs["id"][i])~=nil do
  801.  
  802. i=i+1
  803.  
  804. connected_pcs["name"][i] = connections.readLine()
  805. connected_pcs["id"][i] = connections.readLine()
  806.  
  807.  
  808. if tonumber(connected_pcs["id"][i])~=nil then
  809. connected_pcs["len"]=connected_pcs["len"]+1
  810. connected_pcs["number"][connected_pcs["name"][i]]=i
  811. connected_pcs["number_of_id"][connected_pcs["id"][i]]=i
  812. connected_pcs["id"][i]=tonumber(connected_pcs["id"][i])
  813. end
  814.  
  815. end
  816. connections.close()
  817. end
  818.  
  819.  
  820.  
  821. function disconnect(disconnect_number)
  822.  
  823. rednet.send(connected_pcs["id"][disconnect_number],{["name"]=connection_name,["sending_to"]=connected_pcs["name"][disconnect_number],["status"]="disconnected"})
  824.  
  825. connections = fs.open("connections","w")
  826.  
  827. for i=1,connected_pcs["len"]-1 do
  828.  
  829. if i < disconnect_number then
  830. connections.writeLine(connected_pcs["name"][i])
  831. connections.writeLine(connected_pcs["id"][i])
  832. end
  833.  
  834. if i > disconnect_number-1 then
  835. connections.writeLine(connected_pcs["name"][i+1])
  836. connections.writeLine(connected_pcs["id"][i+1])
  837. end
  838.  
  839. end
  840. connections.flush()
  841. connections.close()
  842. assign_connections()
  843. screen()
  844. end
  845.  
  846.  
  847.  
  848. function create_log_entry(entry)
  849.  
  850. logs["len"]=logs["len"]+math.ceil((string.len(entry)+8)/51)
  851. logs["entries"][logs["len"]]=entry
  852. logs["time"][logs["len"]]=os.time()
  853. change_log=true
  854.  
  855. end
  856.  
  857.  
  858.  
  859. function connection_settings(connection)
  860. cur_env="connection_settings"
  861.  
  862. term.clear()
  863. headline("Settings for: "..connected_pcs["name"][connection])
  864. button("Button label",3,3,16,5)
  865. button("Back",44,17,51,19)
  866. end
  867.  
  868.  
  869.  
  870. function label_settings(connection)
  871. cur_env="label_settings"
  872. info_4=0
  873.  
  874. term.clear()
  875. headline("Label settings for: "..connected_pcs["name"][connection])
  876. button("Back",44,17,51,19)
  877.  
  878. for i=1,3 do
  879. term.setCursorPos(1,2+i)
  880. term.setTextColor(colors.green)
  881. term.write("Line "..i..": ")
  882. term.setTextColor(colors.white)
  883. print(connected_pcs["labels"]["line"..i][connection])
  884. end
  885. end
  886.  
  887.  
  888.  
  889. function assign_labels()
  890. connected_pcs["labels"]["len"]=0
  891.  
  892. for i=1,connected_pcs["len"] do
  893.  
  894. if fs.exists("button label "..connected_pcs["name"][i]) then
  895. connected_pcs["labels"]["len"]=connected_pcs["labels"]["len"]+1
  896.  
  897. read_label = fs.open("button label "..connected_pcs["name"][i],"r")
  898.  
  899. connected_pcs["labels"]["line"..1][i] = read_label.readLine()
  900. connected_pcs["labels"]["line"..2][i] = read_label.readLine()
  901. connected_pcs["labels"]["line"..3][i] = read_label.readLine()
  902.  
  903. if connected_pcs["labels"]["line"..1][i]==nil and connected_pcs["labels"]["line"..2][i]==nil and connected_pcs["labels"]["line"..3][i]==nil then
  904. connected_pcs["labels"]["is_nil"][i]=true
  905. else
  906. connected_pcs["labels"]["is_nil"][i]=false
  907. end
  908.  
  909. read_label.close()
  910.  
  911. else
  912. open_label = fs.open("button label "..connected_pcs["name"][i],"w")
  913. open_label.flush()
  914. open_label.close()
  915.  
  916. connected_pcs["labels"]["len"]=connected_pcs["labels"]["len"]+1
  917.  
  918. read_label = fs.open("button label "..connected_pcs["name"][i],"r")
  919.  
  920. connected_pcs["labels"]["line"..1][i] = read_label.readLine()
  921. connected_pcs["labels"]["line"..2][i] = read_label.readLine()
  922. connected_pcs["labels"]["line"..3][i] = read_label.readLine()
  923.  
  924. read_label.close()
  925.  
  926. end
  927.  
  928. end
  929.  
  930. end
  931.  
  932.  
  933.  
  934. function edit_label(connection,line,new_label)
  935.  
  936. read_label = fs.open("button label "..connected_pcs["name"][connection],"r")
  937.  
  938. for i=1,3 do
  939. old_label[i] = read_label.readLine()
  940. end
  941.  
  942. read_label.close()
  943. write_label = fs.open("button label "..connected_pcs["name"][connection],"w")
  944.  
  945.  
  946. for i=1,3 do
  947.  
  948. if i==line then
  949. write_label.writeLine(new_label)
  950. else
  951. write_label.writeLine(old_label[i])
  952. end
  953. end
  954. write_label.flush()
  955. write_label.close()
  956.  
  957. assign_labels()
  958. screen()
  959. end
  960.  
  961.  
  962.  
  963. function headline(headline)
  964. headline_lenght=string.len(" "..headline.." ")
  965. headline_pos=27-headline_lenght/2
  966. term.setCursorPos(headline_pos,1)
  967. term.setBackgroundColor(colors.yellow)
  968. term.setTextColor(colors.blue)
  969. term.write(" "..headline.." ")
  970. term.setBackgroundColor(colors.black)
  971. term.setTextColor(colors.white)
  972. end
  973.  
  974.  
  975.  
  976. function button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,button_color)
  977. term.setTextColor(colors.green)
  978.  
  979. if button_color~=nil then
  980. term.setTextColor(button_color)
  981. end
  982.  
  983. square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
  984. term.setCursorPos(math.ceil(button_pos_x1-string.len(button_text)/2+(button_pos_x2-button_pos_x1)/2),button_pos_y1+(button_pos_y2-button_pos_y1)/2)
  985. term.write(button_text)
  986. end
  987.  
  988.  
  989.  
  990. function mon_button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,button_color)
  991. mon.setTextColor(colors.green)
  992.  
  993. if button_color~=nil then
  994. mon.setTextColor(button_color)
  995. end
  996.  
  997. mon_square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
  998.  
  999. if connected_pcs["labels"]["is_nil"][connected_pcs["number"][button_text]] then
  1000. mon.setCursorPos(math.ceil(button_pos_x1-string.len(button_text)/2+(button_pos_x2-button_pos_x1)/2),button_pos_y1+(button_pos_y2-button_pos_y1)/2)
  1001. mon.write(button_text)
  1002. else
  1003.  
  1004. for i=1,button_pos_y2-button_pos_y1-1 do
  1005. mon.setCursorPos(button_pos_x1+1,button_pos_y1+i)
  1006. mon.write(connected_pcs["labels"]["line"..i][connected_pcs["number"][button_text]])
  1007. end
  1008. end
  1009. end
  1010.  
  1011.  
  1012.  
  1013.  
  1014. function button_check(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
  1015. if info_1=="mouse_click" and info_3 > b_check_x1-1 and info_3 < b_check_x2+1 and info_4 > b_check_y1-1 and info_4 < b_check_y2+1 then
  1016. return true
  1017. else
  1018. return false
  1019. end
  1020. end
  1021.  
  1022.  
  1023.  
  1024. function mon_button_check(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
  1025. if info_1=="monitor_touch" and info_3 > b_check_x1-1 and info_3 < b_check_x2+1 and info_4 > b_check_y1-1 and info_4 < b_check_y2+1 then
  1026. return true
  1027. else
  1028. return false
  1029. end
  1030. end
  1031.  
  1032.  
  1033.  
  1034.  
  1035. function square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
  1036. x_1=x1
  1037. y_1=y1
  1038. x_2=x2
  1039. y_2=y2
  1040. while x_1~=x2+1 do
  1041. term.setBackgroundColor(back_color_square)
  1042. term.setCursorPos(x_1,y_1)
  1043. if text_color~=nil then
  1044. term.setTextColor(text_color)
  1045. end
  1046. term.write(symbol_square_x)
  1047. x_1=x_1+1
  1048. end
  1049.  
  1050. while y_1~=y2-1 do
  1051. term.setCursorPos(x_1-1,y_1+1)
  1052. term.write(symbol_square_y)
  1053. y_1=y_1+1
  1054. end
  1055. x2=x2-1
  1056. while x_2~=x1-1 do
  1057. term.setCursorPos(x_2,y_2)
  1058. term.write(symbol_square_x)
  1059. x_2=x_2-1
  1060. end
  1061.  
  1062. while y_2~=y1+1 do
  1063. term.setCursorPos(x_2+1,y_2-1)
  1064. term.write(symbol_square_y)
  1065. y_2=y_2-1
  1066. end
  1067. term.setBackgroundColor(colors.black)
  1068. end
  1069.  
  1070.  
  1071.  
  1072.  
  1073. function mon_square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
  1074. x_1=x1
  1075. y_1=y1
  1076. x_2=x2
  1077. y_2=y2
  1078. while x_1~=x2+1 do
  1079. mon.setBackgroundColor(back_color_square)
  1080. mon.setCursorPos(x_1,y_1)
  1081. if text_color~=nil then
  1082. term.setTextColor(text_color)
  1083. end
  1084. mon.write(symbol_square_x)
  1085. x_1=x_1+1
  1086. end
  1087.  
  1088. while y_1~=y2-1 do
  1089. mon.setCursorPos(x_1-1,y_1+1)
  1090. mon.write(symbol_square_y)
  1091. y_1=y_1+1
  1092. end
  1093. x2=x2-1
  1094. while x_2~=x1-1 do
  1095. mon.setCursorPos(x_2,y_2)
  1096. mon.write(symbol_square_x)
  1097. x_2=x_2-1
  1098. end
  1099.  
  1100. while y_2~=y1+1 do
  1101. mon.setCursorPos(x_2+1,y_2-1)
  1102. mon.write(symbol_square_y)
  1103. y_2=y_2-1
  1104. end
  1105. mon.setBackgroundColor(colors.black)
  1106. end
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113. startup()
  1114. menu()
  1115. screen()
  1116. pull()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement