Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local serverName = ""
- local modem = nil
- local port = 0
- local cableSide = "bottom"
- local color = colors.white
- local w, h = term.getSize()
- local names = {}
- function init(col, name, side, p, c)
- color = col
- port = p
- serverName = name
- cableSide = c
- modem = peripheral.wrap(side)
- modem.open(p)
- gui()
- listen()
- end
- function gui()
- term.setTextColor(color)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1,1)
- info("ROBCO INDUSTRIES UNIFIED OPERATING SYSTEM", true)
- info("COPYRIGHT 2019-2020 ROBCO INDUSTRIES", true)
- info("-Server "..port.."-", true)
- info(nil, false)
- info(serverName, false)
- hr()
- term.setCursorPos(1, h)
- end
- function info(text, isCenter)
- term.clearLine()
- if text == nil then
- term.setCursorPos(1, y+2)
- elseif isCenter then
- x, y = term.getCursorPos()
- x = (w - #text) / 2
- term.setCursorPos(x, y)
- write(text)
- term.setCursorPos(1, y+1)
- else
- print(text)
- end
- end
- function longInfo(text, isCenter)
- line = ""
- for k,s in pairs(split(text, " ")) do
- length = string.len(line) + string.len(s) + 1
- if w >= length then
- a = line .. " " .. s
- line = a
- else
- info(line, isCenter)
- line = " "..s
- end
- end
- info(line, isCenter)
- end
- function hr()
- x, y = term.getCursorPos()
- for i = 1, w, 1 do
- write("-")
- end
- term.setCursorPos(1, y+1)
- end
- function msg(message)
- print(message)
- gui()
- end
- function name(id)
- local n = names[id]
- if n then return n
- else return id end
- end
- function listen()
- local loop = true
- while loop do
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- if string.starts(message, "name") then
- local n = split(message, ":")[2]
- names[replyChannel] = n
- msg("["..name(replyChannel).."] connected")
- modem.transmit(replyChannel, port, serverName)
- elseif string.starts(message, "toggle") then
- local color = tonumber(split(message, " ")[2])
- toggleBundledColor(color)
- msg("["..name(replyChannel).."] toggled "..color)
- modem.transmit(replyChannel, port, "toggled")
- elseif string.starts(message, "pulse") then
- local color = tonumber(split(message, " ")[2])
- toggleBundledColor(color)
- sleep(1)
- toggleBundledColor(color)
- modem.transmit(replyChannel, port, "triggered")
- msg("["..name(replyChannel).."] triggered "..color)
- elseif string.starts(message, "check") then
- local color = tonumber(split(message, " ")[2])
- local bundledColors = rs.getBundledOutput(cableSide)
- local f = colors.test(bundledColors, color)
- --msg("Terminal "..senderChannel.." has checked "..color)
- modem.transmit(replyChannel, port, f)
- elseif message == "stop" then
- loop = false
- msg("["..name(replyChannel).."] stopped the server")
- modem.transmit(replyChannel, port, "stopped")
- else
- msg("The message was "..message)
- modem.transmit(replyChannel, port, "invalid")
- end
- end
- end
- function setBundledColor(color, state)
- if state then
- if not colors.test(rs.getBundledOutput(cableSide), color) then
- rs.setBundledOutput(cableSide, colors.combine(rs.getBundledOutput(cableSide), color))
- end
- else
- if colors.test(rs.getBundledOutput(cableSide), color) then
- rs.setBundledOutput(cableSide, colors.subtract(rs.getBundledOutput(cableSide), color))
- end
- end
- end
- function toggleBundledColor(color)
- rs.setBundledOutput(cableSide, (colors.test(rs.getBundledOutput(cableSide), color) and colors.subtract(rs.getBundledOutput(cableSide), color) or colors.combine(rs.getBundledOutput(cableSide), color)))
- end
- function split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- function string.starts(String,Start)
- return string.sub(String,1,string.len(Start))==Start
- end
- function isEmpty(s)
- return s == nil or s == ''
- end
Add Comment
Please, Sign In to add comment