Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Signal Server
- --PeachMaster's MTC and Digital Interlocking System
- local craw = fs.open("config", "r")
- local config
- local signalBlocks
- local bundledIO = peripheral.find("bio")
- local function saveTableFile(path, watchuwant) -- Quicker way to do things w o a h
- local handle = fs.open(path, "w")
- handle.write(textutils.serialise(whatchuwant))
- handle.close()
- end
- local function loadTableFile(path) -- Quiciker way to do things w o a h
- local handle = fs.open(path, "r")
- local thing = textutils.unserialise(handle.readAll())
- handle.close()
- return thing
- end
- local function getSomethingFromTable(theTable, thingWanted) -- A workaround to crappy CC/Lua. >:(
- for k, v in pairs(theTable) do
- if k == thingWanted then
- return v
- end
- end
- end
- local function doEncrypt(thing1)
- -- local ok = encrypt.encrypt(thing1, "kgkg499tgi34ikg39koowklfow0o349")
- --return ok
- return thing1
- end
- local function doDecrypt(thing)
- -- local ok = encrypt.decrypt(thing, "kgkg499tgi34ikg39koowklfow0o349")
- -- return ok
- return thing
- end
- local function findPeripheral( t, e )
- t = t:lower()
- for _,s in pairs(rs.getSides()) do
- if peripheral.getType(s) == t then
- return peripheral.wrap(s)
- end
- end
- error("No "..(e or t).." attached to the computer.", 0)
- end
- local function doControlls()
- rednet.open(findPeripheral("modem", "Rednet Modem"))
- while true do
- event, senderId, message, protocol = os.pullEvent()
- if senderId == getSomethingFromTable(config, "serverID") then
- if event == "rednet_message" then
- local response = doDecrypt(message)
- if protocol == "HelloPing" then
- rednet.send(getSomethingFromTable(config, "serverID"), "HellO!", "HelloBack")
- print("Server just pinged!")
- end
- if protocol == "RemoteConfigUpdate" then
- end
- end
- end
- if event == "redstone" then
- local input = senderId
- for k, v in pairs(signalBlocks) do
- if bundledIO.testBundledInput(getSomethingFromTable(v,"signalColorInput")) then
- signalBlocks[k].status = 3
- print(k + " is active!")
- else
- signalBlocks[k].status = 0
- end
- end
- --Alright, send signals.
- rednet.send(getSomethingFromTable(config, "serverID"), textutils.serialise(signalBlocks), "SignalUpdate")
- end
- end
- end
- --Do startup!
- print("TrainControl Rednet Signal Server (beta) 1.2 ")
- if fs.exists("config") then
- config = loadTableFile("config")
- signalDatabase = loadTableFile("signalDatabase")
- else
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement