Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Bundled Cable Server for Network Control--
- --for tow Bundled Cable--
- -- config--
- local channel = 21
- local CableSide = "right" --set cable side here
- local CableSide_1 = "left" --set cable side here
- modem = peripheral.wrap("back")
- --vars--
- local power = true
- --cable state 0
- local white_st = 0
- local orange_st = 0
- local magenta_st = 0
- local lightblue_st = 0
- local yellow_st = 0
- local lime_st = 0
- local pink_st = 0
- local grey_st = 0
- local lightgrey_st = 0
- local cyan_st = 0
- local purple_st = 0
- local blue_st = 0
- local brown_st = 0
- local green_st = 0
- local red_st = 0
- local black_st = 0
- --cable state 1
- local white_st_1 = 0
- local orange_st_1 = 0
- local magenta_st_1 = 0
- local lightblue_st_1 = 0
- local yellow_st_1 = 0
- local lime_st_1 = 0
- local pink_st_1 = 0
- local grey_st_1 = 0
- local lightgrey_st_1 = 0
- local cyan_st_1 = 0
- local purple_st_1 = 0
- local blue_st_1 = 0
- local brown_st_1 = 0
- local green_st_1 = 0
- local red_st_1 = 0
- local black_st_1 = 0
- --decode--
- function decode(msg)
- if msg == "off" then
- white_st = 0
- orange_st = 0
- magenta_st = 0
- lightblue_st = 0
- yellow_st = 0
- lime_st = 0
- pink_st = 0
- grey_st = 0
- lightgrey_st = 0
- cyan_st = 0
- purple_st = 0
- blue_st = 0
- brown_st = 0
- green_st = 0
- red_st = 0
- black_st = 0
- white_st_1 = 0
- orange_st_1 = 0
- magenta_st_1 = 0
- lightblue_st_1 = 0
- yellow_st_1 = 0
- lime_st_1 = 0
- pink_st_1 = 0
- grey_st_1 = 0
- lightgrey_st_1 = 0
- cyan_st_1 = 0
- purple_st_1 = 0
- blue_st_1 = 0
- brown_st_1 = 0
- green_st_1 = 0
- red_st_1 = 0
- black_st_1 = 0
- end
- if msg == "on" then
- white_st = 1
- orange_st = 1
- magenta_st = 1
- lightblue_st = 1
- yellow_st = 1
- lime_st = 1
- pink_st = 1
- grey_st = 1
- lightgrey_st = 1
- cyan_st = 1
- purple_st = 1
- blue_st = 1
- brown_st = 1
- green_st = 1
- red_st = 1
- black_st = 1
- white_st_1 = 1
- orange_st_1 = 1
- magenta_st_1 = 1
- lightblue_st_1 = 1
- yellow_st_1 = 1
- lime_st_1 = 1
- pink_st_1 = 1
- grey_st_1 = 1
- lightgrey_st_1 = 1
- cyan_st_1 = 1
- purple_st_1 = 1
- blue_st_1 = 1
- brown_st_1 = 1
- green_st_1 = 1
- red_st_1 = 1
- black_st_1 = 1
- end
- if msg == "white" then
- if white_st == 0 then
- white_st = 1
- elseif white_st == 1 then
- white_st = 0
- end
- end
- if msg == "orange" then
- if orange_st == 0 then
- orange_st = 1
- elseif orange_st == 1 then
- orange_st = 0
- end
- end
- if msg == "magenta" then
- if magenta_st == 0 then
- magenta_st = 1
- elseif magenta_st == 1 then
- magenta_st = 0
- end
- end
- if msg == "lightblue" then
- if lightblue_st == 0 then
- lightblue_st = 1
- elseif lightblue_st == 1 then
- lightblue_st = 0
- end
- end
- if msg == "yellow" then
- if yellow_st == 0 then
- yellow_st = 1
- elseif yellow_st == 1 then
- yellow_st = 0
- end
- end
- if msg == "lime" then
- if lime_st == 0 then
- lime_st = 1
- elseif lime_st == 1 then
- lime_st = 0
- end
- end
- if msg == "pink" then
- if pink_st == 0 then
- pink_st = 1
- elseif pink_st == 1 then
- pink_st = 0
- end
- end
- if msg == "gray" then
- if grey_st == 0 then
- grey_st = 1
- elseif grey_st == 1 then
- grey_st = 0
- end
- end
- if msg == "lightgray" then
- if lightgrey_st == 0 then
- lightgrey_st = 1
- elseif lightgrey_st == 1 then
- lightgrey_st = 0
- end
- end
- if msg == "cyan" then
- if cyan_st == 0 then
- cyan_st = 1
- elseif cyan_st == 1 then
- cyan_st = 0
- end
- end
- if msg == "purple" then
- if purple_st == 0 then
- purple_st = 1
- elseif purple_st == 1 then
- purple_st = 0
- end
- end
- if msg == "blue" then
- if blue_st == 0 then
- blue_st = 1
- elseif blue_st == 1 then
- blue_st = 0
- end
- end
- if msg == "brown" then
- if brown_st == 0 then
- brown_st = 1
- elseif brown_st == 1 then
- brown_st = 0
- end
- end
- if msg == "green" then
- if green_st == 0 then
- green_st = 1
- elseif green_st == 1 then
- green_st = 0
- end
- end
- if msg == "red" then
- if red_st == 0 then
- red_st = 1
- elseif red_st == 1 then
- red_st = 0
- end
- end
- if msg == "black" then
- if black_st == 0 then
- black_st = 1
- elseif black_st == 1 then
- black_st = 0
- end
- end
- if msg == "white-1" then
- if white_st_1 == 0 then
- white_st_1 = 1
- elseif white_st_1 == 1 then
- white_st_1 = 0
- end
- end
- if msg == "orange-1" then
- if orange_st_1 == 0 then
- orange_st_1 = 1
- elseif orange_st_1 == 1 then
- orange_st_1 = 0
- end
- end
- if msg == "magenta-1" then
- if magenta_st_1 == 0 then
- magenta_st_1 = 1
- elseif magenta_st_1== 1 then
- magenta_st_1 = 0
- end
- end
- if msg == "lightblue-1" then
- if lightblue_st_1 == 0 then
- lightblue_st_1 = 1
- elseif lightblue_st_1 == 1 then
- lightblue_st_1 = 0
- end
- end
- if msg == "yellow-1" then
- if yellow_st_1 == 0 then
- yellow_st_1 = 1
- elseif yellow_st_1 == 1 then
- yellow_st_1 = 0
- end
- end
- if msg == "lime-1" then
- if lime_st_1 == 0 then
- lime_st_1 = 1
- elseif lime_st_1 == 1 then
- lime_st_1 = 0
- end
- end
- if msg == "pink-1" then
- if pink_st_1 == 0 then
- pink_st_1 = 1
- elseif pink_st_1 == 1 then
- pink_st_1 = 0
- end
- end
- if msg == "gray-1" then
- if grey_st_1 == 0 then
- grey_st_1 = 1
- elseif grey_st_1 == 1 then
- grey_st_1 = 0
- end
- end
- if msg == "lightgray-1" then
- if lightgrey_st_1 == 0 then
- lightgrey_st_1 = 1
- elseif lightgrey_st_1 == 1 then
- lightgrey_st_1 = 0
- end
- end
- if msg == "cyan-1" then
- if cyan_st_1 == 0 then
- cyan_st_1 = 1
- elseif cyan_st_1 == 1 then
- cyan_st_1 = 0
- end
- end
- if msg == "purple-1" then
- if purple_st_1 == 0 then
- purple_st_1 = 1
- elseif purple_st_1 == 1 then
- purple_st_1 = 0
- end
- end
- if msg == "blue-1" then
- if blue_st_1 == 0 then
- blue_st_1 = 1
- elseif blue_st_1 == 1 then
- blue_st_1 = 0
- end
- end
- if msg == "brown-1" then
- if brown_st_1 == 0 then
- brown_st_1 = 1
- elseif brown_st_1 == 1 then
- brown_st_1 = 0
- end
- end
- if msg == "green-1" then
- if green_st_1 == 0 then
- green_st_1 = 1
- elseif green_st_1 == 1 then
- green_st_1 = 0
- end
- end
- if msg == "red-1" then
- if red_st_1 == 0 then
- red_st_1 = 1
- elseif red_st_1 == 1 then
- red_st_1 = 0
- end
- end
- if msg == "black-1" then
- if black_st_1 == 0 then
- black_st_1 = 1
- elseif black_st_1 == 1 then
- black_st_1 = 0
- end
- end
- if msg == "shutdown" then
- shell.run("shutdown")
- else
- shell.run("delete backup.db")
- local file = fs.open("backup.db","w")
- file.writeLine(tostring(white_st))
- file.writeLine(tostring(orange_st))
- file.writeLine(tostring(magenta_st))
- file.writeLine(tostring(lightblue_st))
- file.writeLine(tostring(yellow_st))
- file.writeLine(tostring(lime_st))
- file.writeLine(tostring(pink_st))
- file.writeLine(tostring(grey_st))
- file.writeLine(tostring(lightgrey_st))
- file.writeLine(tostring(cyan_st))
- file.writeLine(tostring(purple_st))
- file.writeLine(tostring(blue_st))
- file.writeLine(tostring(brown_st))
- file.writeLine(tostring(green_st))
- file.writeLine(tostring(red_st))
- file.writeLine(tostring(black_st))
- file.writeLine(tostring(white_st_1))
- file.writeLine(tostring(orange_st_1))
- file.writeLine(tostring(magenta_st_1))
- file.writeLine(tostring(lightblue_st_1))
- file.writeLine(tostring(yellow_st_1))
- file.writeLine(tostring(lime_st_1))
- file.writeLine(tostring(pink_st_1))
- file.writeLine(tostring(grey_st_1))
- file.writeLine(tostring(lightgrey_st_1))
- file.writeLine(tostring(cyan_st_1))
- file.writeLine(tostring(purple_st_1))
- file.writeLine(tostring(blue_st_1))
- file.writeLine(tostring(brown_st_1))
- file.writeLine(tostring(green_st_1))
- file.writeLine(tostring(red_st_1))
- file.writeLine(tostring(black_st_1))
- file.close()
- set_cable(msg)
- end
- end
- --set cable
- function set_cable(cable)
- color_set = colors.black
- if white_st == 1 then
- color_set = color_set + colors.white
- end
- if orange_st == 1 then
- color_set = color_set + colors.orange
- end
- if magenta_st == 1 then
- color_set = color_set + colors.magenta
- end
- if lightblue_st == 1 then
- color_set = color_set + colors.lightBlue
- end
- if yellow_st == 1 then
- color_set = color_set + colors.yellow
- end
- if lime_st == 1 then
- color_set = color_set + colors.lime
- end
- if pink_st == 1 then
- color_set = color_set + colors.pink
- end
- if grey_st == 1 then
- color_set = color_set + colors.gray
- end
- if lightgrey_st == 1 then
- color_set = color_set + colors.lightGray
- end
- if cyan_st == 1 then
- color_set = color_set + colors.cyan
- end
- if purple_st == 1 then
- color_set = color_set + colors.purple
- end
- if blue_st == 1 then
- color_set = color_set + colors.blue
- end
- if brown_st == 1 then
- color_set = color_set + colors.brown
- end
- if green_st == 1 then
- color_set = color_set + colors.green
- end
- if red_st == 1 then
- color_set = color_set + colors.red
- end
- sleep(2)
- rs.setBundledOutput(CableSide,color_set)
- set_cable_1(cable)
- end
- --set cable 1
- function set_cable_1(cable_1)
- color_set_1 = colors.black
- if white_st_1 == 1 then
- color_set_1 = color_set_1 + colors.white
- end
- if orange_st_1 == 1 then
- color_set_1 = color_set_1 + colors.orange
- end
- if magenta_st_1 == 1 then
- color_set_1 = color_set_1 + colors.magenta
- end
- if lightblue_st_1 == 1 then
- color_set_1 = color_set_1 + colors.lightBlue
- end
- if yellow_st_1 == 1 then
- color_set_1 = color_set_1 + colors.yellow
- end
- if lime_st_1 == 1 then
- color_set_1 = color_set_1 + colors.lime
- end
- if pink_st_1 == 1 then
- color_set_1 = color_set_1 + colors.pink
- end
- if grey_st_1 == 1 then
- color_set_1 = color_set_1 + colors.gray
- end
- if lightgrey_st_1 == 1 then
- color_set_1 = color_set_1 + colors.lightGray
- end
- if cyan_st_1 == 1 then
- color_set_1 = color_set_1 + colors.cyan
- end
- if purple_st_1 == 1 then
- color_set_1 = color_set_1 + colors.purple
- end
- if blue_st_1 == 1 then
- color_set_1 = color_set_1 + colors.blue
- end
- if brown_st_1 == 1 then
- color_set_1 = color_set_1 + colors.brown
- end
- if green_st_1 == 1 then
- color_set_1 = color_set_1 + colors.green
- end
- if red_st_1 == 1 then
- color_set_1 = color_set_1 + colors.red
- end
- sleep(2)
- rs.setBundledOutput(CableSide_1,color_set_1)
- end
- --program-
- print("start cable Server");
- print("start modem on channel "..channel)
- print("bundled cable on side "..CableSide.." and "..CableSide_1)
- modem.open(channel)
- local found = fs.exists("backup.db")
- if found == true then
- print("load backup")
- file = fs.open("backup.db","r")
- local fileData = {}
- local line = file.readLine()
- repeat
- table.insert(fileData,line)
- line = file.readLine()
- until line == nil
- file.close()
- white_st = tonumber(fileData[1])
- orange_st = tonumber(fileData[2])
- magenta_st = tonumber(fileData[3])
- lightblue_st = tonumber(fileData[4])
- yellow_st = tonumber(fileData[5])
- lime_st = tonumber(fileData[6])
- pink_st = tonumber(fileData[7])
- grey_st = tonumber(fileData[8])
- lightgrey_st = tonumber(fileData[9])
- cyan_st = tonumber(fileData[10])
- purple_st = tonumber(fileData[11])
- blue_st = tonumber(fileData[12])
- brown_st = tonumber(fileData[13])
- green_st = tonumber(fileData[14])
- red_st = tonumber(fileData[15])
- black_st = tonumber(fileData[16])
- white_st_1 = tonumber(fileData[17])
- orange_st_1 = tonumber(fileData[18])
- magenta_st_1 = tonumber(fileData[19])
- lightblue_st_1 = tonumber(fileData[20])
- yellow_st_1 = tonumber(fileData[21])
- lime_st_1 = tonumber(fileData[22])
- pink_st_1 = tonumber(fileData[23])
- grey_st_1 = tonumber(fileData[24])
- lightgrey_st_1 = tonumber(fileData[25])
- cyan_st_1 = tonumber(fileData[26])
- purple_st_1 = tonumber(fileData[27])
- blue_st_1 = tonumber(fileData[28])
- brown_st_1 = tonumber(fileData[29])
- green_st_1 = tonumber(fileData[30])
- red_st_1 = tonumber(fileData[31])
- black_st_1 = tonumber(fileData[32])
- set_cable(msg)
- end
- print("cable Server started")
- --open pull event--
- while power == true do
- event, modemside, sendchan, replaychan, message, dist = os.pullEvent("modem_message")
- print(message)
- decode(message)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement