Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function startup()
- dropdown = {}
- dropdown["loaded"] = {}
- dropdown["loaded"]["len"] = 0
- settings = {}
- settings["names"] = {}
- settings["len"] = 0
- old_label={}
- label_save={}
- got_response=0
- connected_pcs={}
- connected_pcs["len"]=0
- connected_pcs["got_response"]={}
- button_positions={}
- button_positions["status"]={}
- connected_pcs["number"]={}
- connected_pcs["number_of_id"]={}
- connected_pcs["labels"]={}
- connected_pcs["labels"]["is_nil"]={}
- connected_pcs["labels"]["len"]=0
- for i=1,3 do
- connected_pcs["labels"]["line"..i]={}
- end
- rednet.open("top")
- connections=fs.open("connections","a")
- connections.close()
- if not fs.exists("connection_code") then
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.green)
- print("Please enter the name you want to use to connect")
- print("to other PC´s")
- print()
- term.setTextColor(colors.white)
- connection_name=read()
- connection_code=fs.open("connection_code","w")
- connection_code.writeLine(connection_name)
- connection_code.flush()
- connection_code.close()
- end
- if not fs.exists("settings") then
- settings_save = fs.open("settings","w")
- settings_save.writeLine("off")
- settings_save.writeLine("right")
- settings_save.flush()
- settings_save.close()
- end
- create_setting("solo")
- create_setting("monitor_side")
- assign_settings()
- assign_name()
- mon=peripheral.wrap(settings["monitor_side"]["status"])
- mon.setTextScale(0.5)
- logs={}
- logs["len"]=0
- logs["entries"]={}
- logs["time"]={}
- assign_connections()
- assign_labels()
- for i=1,connected_pcs["len"] do
- rednet.send(tonumber(connected_pcs["id"][i]),{["sending_to"]=connected_pcs["name"][i],["name"]=connection_name,["status"]="get_info"})
- end
- if settings["monitor_side"]["status"]=="right" then
- create_dropdown_menu("mon_side",{"right","left","top","bottom","front","back"},3,8,11)
- elseif settings["monitor_side"]["status"]=="left" then
- create_dropdown_menu("mon_side",{"left","right","top","bottom","front","back"},3,8,11)
- elseif settings["monitor_side"]["status"]=="top" then
- create_dropdown_menu("mon_side",{"top","right","left","bottom","front","back"},3,8,11)
- elseif settings["monitor_side"]["status"]=="bottom" then
- create_dropdown_menu("mon_side",{"bottom","right","left","top","front","back"},3,8,11)
- elseif settings["monitor_side"]["status"]=="front" then
- create_dropdown_menu("mon_side",{"front","right","left","top","bottom","back"},3,8,11)
- elseif settings["monitor_side"]["status"]=="back" then
- create_dropdown_menu("mon_side",{"back","right","left","top","bottom","front"},3,8,11)
- end
- end
- function screen()
- cur_x1=1
- cur_y1=1
- cur_x2=7
- cur_y2=5
- cur_connection=1
- button_positions["len"]=0
- mon.clear()
- for i=1,math.ceil(connected_pcs["len"]^0.5) do
- for i1=1,math.ceil(connected_pcs["len"]^0.5) do
- if connected_pcs["name"][cur_connection]~=nil then
- if button_positions["status"][cur_connection]=="on" then
- mon_button(connected_pcs["name"][cur_connection],cur_x1,cur_y1,cur_x2,cur_y2)
- end
- if button_positions["status"][cur_connection]=="off" then
- mon_button(connected_pcs["name"][cur_connection],cur_x1,cur_y1,cur_x2,cur_y2,colors.red)
- end
- if button_positions["status"][cur_connection]==nil then
- mon_button(connected_pcs["name"][cur_connection],cur_x1,cur_y1,cur_x2,cur_y2,colors.blue)
- end
- button_positions[cur_connection]={}
- button_positions[cur_connection]={["x1"]=cur_x1,["y1"]=cur_y1,["x2"]=cur_x2,["y2"]=cur_y2,["id"]=connected_pcs["id"][cur_connection],["status"]="on"}
- button_positions["len"]=button_positions["len"]+1
- end
- cur_x1=cur_x1+8
- cur_x2=cur_x2+8
- cur_connection=cur_connection+1
- end
- cur_y1=cur_y1+5
- cur_y2=cur_y2+5
- cur_x1=1
- cur_x2=7
- end
- end
- function menu()
- cur_env="menu"
- term.setBackgroundColor(colors.black)
- term.clear()
- headline("Menu")
- button("Connections",12,7,25,9)
- button("Change name",27,7,40,9)
- button("Settings",27,11,40,13)
- button("Log",12,11,25,13)
- end
- function pull(loop_time)
- if tonumber(loop_time)~=nil then
- timer_id=os.startTimer(loop_time)
- end
- while info_1~="timer" or timer_id~=info_2 do
- last_info_1 = info_1
- last_info_2 = info_2
- last_info_3 = info_3
- last_info_4 = info_4
- info_1=0
- info_2=0
- info_3=0
- info_4=0
- info_1, info_2, info_3, info_4 = os.pullEvent()
- overwrite_dropdown()
- if info_1=="rednet_message" and info_3["sending_to"]==connection_name then
- if info_3["sending_status"] then
- if button_positions["status"][connected_pcs["number"][info_3["name"]]]~=info_3["status"] then
- screen()
- button_positions["status"][connected_pcs["number"][info_3["name"]]]=info_3["status"]
- screen()
- end
- end
- if tonumber(answer_id)==tonumber(info_2) then
- answered=true
- end
- if info_3["status"]=="disconnected" then
- disconnect(connected_pcs["number_of_id"][tonumber(info_2)])
- end
- end
- if info_1=="rednet_message" and info_3["connecting_to"]==connection_name then
- if info_3["is_main"]==true then
- rednet.send(info_2,{["connecting_to"]=info_3["name"],["is_main"]=true,["name"]=connection_name})
- for i=1,connected_pcs["len"] do
- rednet.send(connected_pcs["id"][i],{["name"]=info_3["name"],["connecting_to"]=connected_pcs["name"][i],["is_main"]=true,["id"]=info_2,["send_response"]=true})
- end
- else
- already_connected=false
- same_id=false
- same_name=false
- for i=1,connected_pcs["len"] do
- if tonumber(connected_pcs["id"][i])==tonumber(info_2) then
- same_id=true
- end
- if info_3["name"] == connected_pcs["name"][i] then
- same_name=true
- end
- end
- if not same_id and not same_name then
- connections = fs.open("connections","a")
- connections.writeLine(info_3["name"])
- connections.writeLine(info_2)
- connections.flush()
- connections.close()
- assign_connections()
- assign_labels()
- create_log_entry("Connected to the PC named: "..info_3["name"])
- change_connection_menu=true
- button_positions["status"][connected_pcs["len"]]=info_3["status"]
- screen()
- if not info_3["dont_respond"] then
- rednet.send(info_2,{["name"]=connection_name,["connecting_to"]=info_3["name"]})
- end
- end
- end
- end
- for i=1,button_positions["len"] do
- if mon_button_check(button_positions[i]["x1"],button_positions[i]["y1"],button_positions[i]["x2"],button_positions[i]["y2"]) then
- if settings["solo"]["status"]~="on" then
- rednet.send(tonumber(connected_pcs["id"][i]),{["sending_to"]=connected_pcs["name"][i],["name"]=connection_name,["status"]="change_status"})
- answer_id=connected_pcs["id"][i]
- answered=false
- pull(0.05,true)
- if not answered then
- screen()
- x,y=mon.getSize()
- mon.setCursorPos(math.floor(x/2-string.len("ERROR,open log for more info")/2),math.floor(y/2))
- mon.setTextColor(colors.red)
- mon.write("ERROR,open log for more info")
- create_log_entry("The PC named, "..connected_pcs["name"][i]..", did not respond, its probably not loaded or the programm is not running")
- os.startTimer(0.05)
- pull(3)
- screen()
- end
- else
- answered_pcs=0
- pcs_that_are_on=0
- for i1=1,connected_pcs["len"] do
- if button_positions["status"][i1] == "on" or i1==i then
- pcs_that_are_on=pcs_that_are_on+1
- rednet.send(tonumber(connected_pcs["id"][i1]),{["sending_to"]=connected_pcs["name"][i1],["name"]=connection_name,["status"]="get_info"})
- answer_id=connected_pcs["id"][i1]
- answered=false
- pull(0.01,true)
- if answered then
- answered_pcs=answered_pcs+1
- else
- create_log_entry("The PC named, "..connected_pcs["name"][i1]..", did not respond, its probably not loaded or the programm is not running")
- end
- end
- end
- if answered_pcs==pcs_that_are_on then
- for i1=1,connected_pcs["len"] do
- if button_positions["status"][i1] == "on" or i1==i then
- rednet.send(tonumber(connected_pcs["id"][i1]),{["sending_to"]=connected_pcs["name"][i1],["name"]=connection_name,["status"]="change_status"})
- end
- end
- else
- screen()
- x,y=mon.getSize()
- mon.setCursorPos(math.floor(x/2-string.len("ERROR,open log for more info")/2),math.floor(y/2))
- mon.setTextColor(colors.red)
- mon.write("ERROR,open log for more info")
- pull(3)
- screen()
- end
- end
- end
- end
- if cur_env=="menu" then
- if button_check(27,7,40,9) then
- change_name()
- end
- if button_check(12,11,25,13) then
- log()
- end
- if button_check(12,7,25,9) then
- connection_menu()
- end
- if button_check(27,11,40,13) then
- settings_menu()
- end
- end
- if cur_env=="log" then
- if change_log then
- log()
- end
- if button_check(44,17,51,19) then
- menu()
- end
- end
- if cur_env=="connection_menu" then
- if button_check(44,17,51,19) then
- menu()
- end
- if button_check(34,17,42,19) then
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.green)
- print("Please enter the name of the PC you want to")
- print("connect to")
- print()
- term.setTextColor(colors.white)
- connecting_to=read()
- for i=1,1000 do
- rednet.send(i,{["connecting_to"]=connecting_to,["name"]=connection_name,["status"]=status,["is_main"]=true})
- end
- connected=false
- timer=os.startTimer(5)
- while info_1~="timer" and not connected do
- info_1 ,info_2, info_3, info_4 = os.pullEvent()
- if info_1=="rednet_message" and info_3["connecting_to"]==connection_name and info_3["is_main"] then
- connected=true
- end
- if info_1=="rednet_message" and info_3["connecting_to"]==connection_name and not info_3["is_main"] then
- if info_3["status"]=="disconnected" then
- fs.delete("connections")
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.green)
- if info_3["same_name"] then
- print("A PC with this name was already connected,")
- print("please use a different name.")
- fs.delete("connection_code")
- sleep(3)
- change_connection_menu=true
- end
- if info_3["same_id"] then
- print("A PC with this id was already connected,")
- print("please use a different PC.")
- sleep(3)
- change_connection_menu=true
- end
- end
- if info_3["name"]==connecting_to and info_3["connecting_to"]==connection_name then
- connections=fs.open("connections","a")
- connections.writeLine(connecting_to)
- connections.writeLine(info_2)
- connections.flush()
- connections.close()
- assign_connections()
- connected=true
- button_positions["status"][connected_pcs["number"][info_3["name"]]]=info_3["cur_status"]
- create_log_entry("Connected to the PC named: "..info_3["name"])
- end
- end
- os.cancelTimer(timer)
- end
- info_1=0
- change_connection_menu=true
- assign_labels()
- screen()
- end
- for i=1,connected_pcs["len"] do
- if info_1=="mouse_click" and info_4==i+3 then
- connection_menu()
- term.setBackgroundColor(colors.red)
- term.setCursorPos(1,i+3)
- term.setTextColor(colors.green)
- term.write("[Id-"..tonumber(connected_pcs["id"][i]).."]")
- for i1=1,9-string.len("[Id-"..tonumber(connected_pcs["id"][i]).."]") do
- write(" ")
- end
- term.setTextColor(colors.white)
- term.write(connected_pcs["name"][i])
- for i1=1,51-string.len(connected_pcs["name"][i])-9 do
- term.write(" ")
- end
- button("Delete",1,17,10,19,colors.red)
- button("Settings",12,17,22,19)
- if i~=clicked_connection then
- clicked_connection=i
- else
- clicked_connection=nil
- connection_menu()
- end
- end
- end
- if clicked_connection~=nil then
- if button_check(1,17,10,19) then
- disconnect(clicked_connection)
- clicked_connection=nil
- connection_menu()
- end
- if button_check(12,17,22,19) then
- connection_settings(clicked_connection)
- end
- end
- if change_connection_menu then
- connection_menu()
- if clicked_connection~=nil then
- term.setBackgroundColor(colors.red)
- term.setCursorPos(1,clicked_connection+3)
- term.setTextColor(colors.green)
- term.write("[Id-"..tonumber(connected_pcs["id"][clicked_connection]).."]")
- for i1=1,9-string.len("[Id-"..tonumber(connected_pcs["id"][clicked_connection]).."]") do
- write(" ")
- end
- term.setTextColor(colors.white)
- term.write(connected_pcs["name"][clicked_connection])
- for i1=1,51-string.len(connected_pcs["name"][clicked_connection])-9 do
- term.write(" ")
- end
- button("Delete",1,17,10,19,colors.red)
- button("Settings",12,17,22,19)
- end
- change_connection_menu=false
- end
- if clicked_connection~=nil then
- 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
- if info_4-3 < connected_pcs["len"]+1 and info_4-3>0 then
- change_connection_order(clicked_connection,info_4-3)
- end
- end
- end
- end
- if cur_env=="change_name" then
- if info_1=="rednet_message" and info_3["sending_to"]==connection_name then
- if info_3["sending_status"] then
- button_positions["status"][connected_pcs["number"][info_3["name"]]]=info_3["status"]
- screen()
- got_response=got_response+1
- connected_pcs["got_response"][connected_pcs["number"][info_3["name"]]]=true
- end
- end
- end
- if cur_env=="connection_settings" then
- if button_check(44,17,51,19) then
- connection_menu()
- end
- if button_check(3,3,16,5) then
- label_settings(clicked_connection)
- end
- end
- if cur_env=="label_settings" then
- if button_check(44,17,51,19) then
- connection_settings(clicked_connection)
- end
- if info_1=="mouse_click" and info_4 < 6 and info_4 > 2 then
- term.setTextColor(colors.green)
- term.setCursorPos(1,info_4)
- term.write("Line "..tostring(info_4-2)..": ")
- term.setTextColor(colors.white)
- for i=1,42 do
- write(" ")
- end
- term.setCursorPos(9,info_4)
- new_text=read()
- edit_label(clicked_connection,info_4-2,new_text)
- end
- end
- if cur_env=="settings" then
- if button_check(44,17,51,19) then
- close_dropdown_menus()
- menu()
- end
- if button_check(3,3,12,5) then
- if settings["solo"]["status"]=="on" then
- change_setting("solo","off")
- settings_menu()
- else
- change_setting("solo","on")
- settings_menu()
- end
- settings_menu()
- end
- if dropdown_menu_check("mon_side")=="changed" then
- change_setting("monitor_side",dropdown["mon_side"]["option"..1])
- mon.clear()
- mon=peripheral.wrap(settings["monitor_side"]["status"])
- mon.setTextScale(0.5)
- screen()
- end
- end
- end
- info_1=nil
- end
- function settings_menu()
- cur_env="settings"
- info_1=nil
- term.clear()
- headline("Settings")
- button("Back",44,17,51,19)
- if settings["solo"]["status"] == "on" then
- button("Solo",3,3,12,5)
- else
- button("Solo",3,3,12,5,colors.red)
- end
- term.setCursorPos(3,7)
- term.setTextColor(colors.green)
- term.write("Monitor:")
- load_dropdown_menu("mon_side")
- end
- function create_setting(name)
- settings[name] = {}
- settings["len"]=settings["len"]+1
- settings["names"][settings["len"]] = name
- settings[name]["number"] = settings["len"]
- end
- function create_dropdown_menu(name,options,pos_x1,pos_y,pos_x2)
- dropdown[name] = {}
- dropdown[name]["pos_x1"] = pos_x1
- dropdown[name]["pos_x2"] = pos_x2
- dropdown[name]["pos_y"] = pos_y
- dropdown[name]["is_open"] = false
- dropdown[name]["len"] = 0
- i=1
- while options[i]~= nil do
- dropdown[name]["len"] = dropdown[name]["len"]+1
- dropdown[name]["option"..i] = options[i]
- i=i+1
- end
- end
- function print_dropdown_menu(name)
- for i=1,dropdown[name]["len"] do
- term.setCursorPos(dropdown[name]["pos_x1"],dropdown[name]["pos_y"]+i-1)
- if not (i%2==0) then
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- else
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.black)
- end
- if dropdown[name]["is_open"] or i==1 then
- term.write(dropdown[name]["option"..i])
- for i1=1,(dropdown[name]["pos_x2"]-dropdown[name]["pos_x1"])-string.len(dropdown[name]["option"..i]) do
- term.write(" ")
- end
- end
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function dropdown_menu_check(name)
- if dropdown[name]["is_open"] then
- if info_1=="dropdown_menu" and info_3 < dropdown[name]["pos_x2"]+1 and info_3 > dropdown[name]["pos_x1"]-1 and info_4==dropdown[name]["pos_y"] then
- dropdown[name]["is_open"]=false
- print_menu(cur_env)
- return "closed"
- end
- if info_1=="dropdown_menu" and info_3 < dropdown[name]["pos_x2"]+1 and info_3 > dropdown[name]["pos_x1"]-1 and info_4 < dropdown[name]["pos_y"]+dropdown[name]["len"]+1 and info_4 > dropdown[name]["pos_y"] then
- option_save = dropdown[name]["option"..1]
- dropdown[name]["option"..1] = dropdown[name]["option"..info_4-dropdown[name]["pos_y"]+1]
- dropdown[name]["option"..info_4-dropdown[name]["pos_y"]+1] = option_save
- dropdown[name]["is_open"]=false
- print_menu(cur_env)
- return "changed"
- end
- else
- if info_1=="dropdown_menu" and info_3 < dropdown[name]["pos_x2"]+1 and info_3 > dropdown[name]["pos_x1"]-1 and info_4==dropdown[name]["pos_y"] then
- dropdown[name]["is_open"]=true
- print_dropdown_menu(name)
- return "opened"
- end
- end
- end
- function load_dropdown_menu(name)
- dropdown["loaded"]["len"] = dropdown["loaded"]["len"]+1
- dropdown["loaded"][dropdown["loaded"]["len"]] = name
- print_dropdown_menu(name)
- end
- function close_dropdown_menus()
- dropdown["loaded"]["len"]=0
- end
- function overwrite_dropdown()
- for i=1,dropdown["loaded"]["len"] do
- if not dropdown[dropdown["loaded"][i]]["is_open"] then
- if info_1=="mouse_click" and info_3 < dropdown[dropdown["loaded"][i]]["pos_x2"]+1 and info_3 > dropdown[dropdown["loaded"][i]]["pos_x1"]-1 and info_4==dropdown[dropdown["loaded"][i]]["pos_y"] then
- info_1 = "dropdown_menu"
- end
- else
- if info_1=="mouse_click" and info_3 < dropdown[dropdown["loaded"][i]]["pos_x2"]+1 and info_3 > dropdown[dropdown["loaded"][i]]["pos_x1"]-1 and info_4 < dropdown[dropdown["loaded"][i]]["pos_y"]+dropdown[dropdown["loaded"][i]]["len"] and info_4 > dropdown[dropdown["loaded"][i]]["pos_y"]-1 then
- info_1 = "dropdown_menu"
- end
- end
- end
- end
- function print_menu(env)
- if env=="menu" then
- menu()
- end
- if env=="log" then
- log()
- end
- if env=="connection_menu" then
- connection_menu()
- end
- if env=="change_name" then
- change_name()
- end
- if env=="connection_settings" then
- connection_settings(clicked_connection)
- end
- if env=="label_settings" then
- label_settings(clicked_connection)
- end
- if env=="settings" then
- settings_menu()
- end
- end
- function assign_settings()
- settings_save = fs.open("settings","r")
- for i=1,settings["len"] do
- settings[i] = {}
- settings[settings["names"][i]]["status"] = settings_save.readLine()
- settings[i]["status"] = settings[settings["names"][i]]["status"]
- end
- settings_save.close()
- end
- function change_setting(name,new_status)
- settings_save = fs.open("settings","w")
- for i=1,settings[name]["number"]-1 do
- settings_save.writeLine(settings[i]["status"])
- end
- settings_save.writeLine(new_status)
- for i=1,settings["len"]-settings[name]["number"] do
- settings_save.writeLine(settings[i+settings[name]["number"]]["status"])
- end
- settings_save.flush()
- settings_save.close()
- assign_settings()
- end
- function change_connection_order(changing,change_to)
- connection_save_name = connected_pcs["name"][changing]
- connection_save_id = connected_pcs["id"][changing]
- status_save = button_positions["status"][changing]
- for i=1,3 do
- label_save[i] = connected_pcs["labels"]["line"..i][changing]
- end
- connected_pcs["name"][changing] = connected_pcs["name"][change_to]
- connected_pcs["id"][changing] = connected_pcs["id"][change_to]
- button_positions["status"][changing] = button_positions["status"][change_to]
- for i=1,3 do
- connected_pcs["labels"]["line"..i][changing] = connected_pcs["labels"]["line"..i][change_to]
- end
- connected_pcs["name"][change_to] = connection_save_name
- connected_pcs["id"][change_to] = connection_save_id
- button_positions["status"][change_to] = status_save
- for i=1,3 do
- connected_pcs["labels"]["line"..i][change_to] = label_save[i]
- end
- connections = fs.open("connections","w")
- for i=1,connected_pcs["len"] do
- connections.writeLine(connected_pcs["name"][i])
- connections.writeLine(connected_pcs["id"][i])
- end
- connections.flush()
- connections.close()
- if clicked_connection==changing then
- clicked_connection=change_to
- end
- assign_connections()
- change_connection_menu=true
- screen()
- end
- function connection_menu()
- if cur_env~="connection_menu" then
- info_1=nil
- end
- cur_env="connection_menu"
- term.setBackgroundColor(colors.black)
- term.clear()
- headline("Connections")
- button("Back",44,17,51,19)
- button("Connect",34,17,42,19)
- term.setCursorPos(1,4)
- for i=1,connected_pcs["len"] do
- term.setTextColor(colors.green)
- term.write("[Id-"..tonumber(connected_pcs["id"][i]).."]")
- for i1=1,9-string.len("[Id-"..tonumber(connected_pcs["id"][i]).."]") do
- write(" ")
- end
- term.setTextColor(colors.white)
- print(connected_pcs["name"][i])
- end
- end
- function assign_name()
- connection_code = fs.open("connection_code","r")
- connection_name = connection_code.readLine()
- connection_code.close()
- end
- function change_name()
- cur_env="change_name"
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.green)
- print("Please enter the name you want to use to connect")
- print("to other PC´s")
- print()
- term.write("Old name: ")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.blue)
- print(" "..connection_name.." ")
- print()
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- new_name=read()
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.green)
- write("Changing name...")
- for i=1,connected_pcs["len"] do
- rednet.send(tonumber(connected_pcs["id"][i]),{["sending_to"]=connected_pcs["name"][i],["name"]=connection_name,["status"]="get_info"})
- end
- got_response=0
- for i=1,connected_pcs["len"] do
- connected_pcs["got_response"][i]=false
- end
- pull(1)
- if not (got_response < connected_pcs["len"]) then
- for i=1,connected_pcs["len"] do
- rednet.send(tonumber(connected_pcs["id"][i]),{["sending_to"]=connected_pcs["name"][i],["name"]=connection_name,["status"]="changing_name",["new_name"]=new_name})
- end
- connection_name = new_name
- connection_code=fs.open("connection_code","w")
- connection_code.writeLine(connection_name)
- connection_code.flush()
- connection_code.close()
- else
- for i=1,connected_pcs["len"] do
- if not connected_pcs["got_response"][i] then
- create_log_entry("The name could not be changed, because the PC named:, "..connected_pcs["name"][i]..", did not respond.")
- end
- end
- term.clear()
- term.setTextColor(colors.red)
- term.setCursorPos(1,1)
- term.write("ERROR,open log for more info")
- pull(3)
- menu()
- end
- menu()
- end
- function log()
- cur_env="log"
- term.setBackgroundColor(colors.black)
- term.clear()
- button("Back",44,17,51,19)
- headline("Log")
- term.setCursorPos(1,4)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- if logs["len"] < 13 then
- for i=1,12 do
- if logs["time"][i]~=nil then
- term.setTextColor(colors.green)
- write("[")
- write(math.floor(logs["time"][i]))
- write(":")
- write(math.floor( math.floor( (logs["time"][i]-math.floor(logs["time"][i])) *100 ) /1.6666666 ) )
- write("]")
- 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
- write(" ")
- end
- term.setTextColor(colors.white)
- print(logs["entries"][i])
- end
- end
- else
- for i=1,12 do
- if logs["time"][logs["len"]-12+i]~=nil then
- term.setTextColor(colors.green)
- write("[")
- write(math.floor(logs["time"][logs["len"]-12+i]))
- write(":")
- write(math.floor( math.floor( (logs["time"][logs["len"]-12+i]-math.floor(logs["time"][logs["len"]-12+i])) *100 ) /1.6666666 ) )
- write("]")
- 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
- write(" ")
- end
- term.setTextColor(colors.white)
- print(logs["entries"][logs["len"]-12+i])
- end
- end
- end
- change_log=false
- end
- function assign_connections()
- connections=fs.open("connections","r")
- connected_pcs["name"]={}
- connected_pcs["len"]=0
- connected_pcs["id"]={}
- connected_pcs["id"][0]="0"
- i=0
- while tonumber(connected_pcs["id"][i])~=nil do
- i=i+1
- connected_pcs["name"][i] = connections.readLine()
- connected_pcs["id"][i] = connections.readLine()
- if tonumber(connected_pcs["id"][i])~=nil then
- connected_pcs["len"]=connected_pcs["len"]+1
- connected_pcs["number"][connected_pcs["name"][i]]=i
- connected_pcs["number_of_id"][tonumber(connected_pcs["id"][i])]=i
- connected_pcs["id"][i]=tonumber(connected_pcs["id"][i])
- end
- end
- connections.close()
- assign_labels()
- end
- function disconnect(disconnect_number)
- sleep(0.05)
- if tonumber(connected_pcs["id"][disconnect_number])~=nil and connected_pcs["name"][disconnect_number]~=nil then
- rednet.send(connected_pcs["id"][disconnect_number],{["name"]=connection_name,["sending_to"]=connected_pcs["name"][disconnect_number],["status"]="disconnected"})
- connections = fs.open("connections","w")
- for i=1,connected_pcs["len"]-1 do
- if i < disconnect_number then
- connections.writeLine(connected_pcs["name"][i])
- connections.writeLine(connected_pcs["id"][i])
- end
- if i > disconnect_number-1 then
- connections.writeLine(connected_pcs["name"][i+1])
- connections.writeLine(connected_pcs["id"][i+1])
- end
- fs.delete("button label "..connected_pcs["name"][disconnect_number])
- end
- connections.flush()
- connections.close()
- create_log_entry("The PC named: "..connected_pcs["name"][disconnect_number].." was disconnect")
- change_connection_menu=true
- assign_connections()
- assign_labels()
- screen()
- end
- end
- function create_log_entry(entry)
- logs["len"]=logs["len"]+math.ceil((string.len(entry)+8)/51)
- logs["entries"][logs["len"]]=entry
- logs["time"][logs["len"]]=os.time()
- change_log=true
- end
- function connection_settings(connection)
- cur_env="connection_settings"
- term.clear()
- headline("Settings for: "..connected_pcs["name"][connection])
- button("Button label",3,3,16,5)
- button("Back",44,17,51,19)
- end
- function label_settings(connection)
- cur_env="label_settings"
- info_4=0
- term.clear()
- headline("Label settings for: "..connected_pcs["name"][connection])
- button("Back",44,17,51,19)
- for i=1,3 do
- term.setCursorPos(1,2+i)
- term.setTextColor(colors.green)
- term.write("Line "..i..": ")
- term.setTextColor(colors.white)
- print(connected_pcs["labels"]["line"..i][connection])
- end
- end
- function assign_labels()
- connected_pcs["labels"]["len"]=0
- for i=1,connected_pcs["len"] do
- if fs.exists("button label "..connected_pcs["name"][i]) then
- connected_pcs["labels"]["len"]=connected_pcs["labels"]["len"]+1
- read_label = fs.open("button label "..connected_pcs["name"][i],"r")
- connected_pcs["labels"]["line"..1][i] = read_label.readLine()
- connected_pcs["labels"]["line"..2][i] = read_label.readLine()
- connected_pcs["labels"]["line"..3][i] = read_label.readLine()
- 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
- connected_pcs["labels"]["is_nil"][i]=true
- else
- connected_pcs["labels"]["is_nil"][i]=false
- end
- read_label.close()
- else
- open_label = fs.open("button label "..connected_pcs["name"][i],"w")
- open_label.flush()
- open_label.close()
- connected_pcs["labels"]["len"]=connected_pcs["labels"]["len"]+1
- read_label = fs.open("button label "..connected_pcs["name"][i],"r")
- connected_pcs["labels"]["line"..1][i] = read_label.readLine()
- connected_pcs["labels"]["line"..2][i] = read_label.readLine()
- connected_pcs["labels"]["line"..3][i] = read_label.readLine()
- read_label.close()
- end
- end
- end
- function edit_label(connection,line,new_label)
- read_label = fs.open("button label "..connected_pcs["name"][connection],"r")
- for i=1,3 do
- old_label[i] = read_label.readLine()
- end
- read_label.close()
- write_label = fs.open("button label "..connected_pcs["name"][connection],"w")
- for i=1,3 do
- if i==line then
- write_label.writeLine(new_label)
- else
- write_label.writeLine(old_label[i])
- end
- end
- write_label.flush()
- write_label.close()
- assign_labels()
- screen()
- end
- function headline(headline)
- headline_lenght=string.len(" "..headline.." ")
- headline_pos=27-headline_lenght/2
- term.setCursorPos(headline_pos,1)
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.blue)
- term.write(" "..headline.." ")
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,button_color)
- term.setTextColor(colors.green)
- if button_color~=nil then
- term.setTextColor(button_color)
- end
- square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
- 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)
- term.write(button_text)
- end
- function mon_button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,button_color)
- mon.setTextColor(colors.green)
- if button_color~=nil then
- mon.setTextColor(button_color)
- end
- mon_square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
- if connected_pcs["labels"]["is_nil"][connected_pcs["number"][button_text]] then
- 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)
- mon.write(button_text)
- else
- for i=1,button_pos_y2-button_pos_y1-1 do
- mon.setCursorPos(button_pos_x1+1,button_pos_y1+i)
- mon.write(connected_pcs["labels"]["line"..i][connected_pcs["number"][button_text]])
- end
- end
- end
- function button_check(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
- 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
- return true
- else
- return false
- end
- end
- function mon_button_check(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
- 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
- return true
- else
- return false
- end
- end
- function square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
- x_1=x1
- y_1=y1
- x_2=x2
- y_2=y2
- while x_1~=x2+1 do
- term.setBackgroundColor(back_color_square)
- term.setCursorPos(x_1,y_1)
- if text_color~=nil then
- term.setTextColor(text_color)
- end
- term.write(symbol_square_x)
- x_1=x_1+1
- end
- while y_1~=y2-1 do
- term.setCursorPos(x_1-1,y_1+1)
- term.write(symbol_square_y)
- y_1=y_1+1
- end
- x2=x2-1
- while x_2~=x1-1 do
- term.setCursorPos(x_2,y_2)
- term.write(symbol_square_x)
- x_2=x_2-1
- end
- while y_2~=y1+1 do
- term.setCursorPos(x_2+1,y_2-1)
- term.write(symbol_square_y)
- y_2=y_2-1
- end
- term.setBackgroundColor(colors.black)
- end
- function mon_square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
- x_1=x1
- y_1=y1
- x_2=x2
- y_2=y2
- while x_1~=x2+1 do
- mon.setBackgroundColor(back_color_square)
- mon.setCursorPos(x_1,y_1)
- if text_color~=nil then
- term.setTextColor(text_color)
- end
- mon.write(symbol_square_x)
- x_1=x_1+1
- end
- while y_1~=y2-1 do
- mon.setCursorPos(x_1-1,y_1+1)
- mon.write(symbol_square_y)
- y_1=y_1+1
- end
- x2=x2-1
- while x_2~=x1-1 do
- mon.setCursorPos(x_2,y_2)
- mon.write(symbol_square_x)
- x_2=x_2-1
- end
- while y_2~=y1+1 do
- mon.setCursorPos(x_2+1,y_2-1)
- mon.write(symbol_square_y)
- y_2=y_2-1
- end
- mon.setBackgroundColor(colors.black)
- end
- startup()
- menu()
- screen()
- pull()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement