G2A Many GEOs
SHARE
TWEET

TrainControl Signal Server

PeachGaming Mar 31st, 2020 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Signal Server
  2. --PeachMaster's MTC and Digital Interlocking System
  3.  
  4. local craw = fs.open("config", "r")
  5. local config
  6. local signalBlocks
  7. local bundledIO = peripheral.find("bio")
  8.  
  9. local function saveTableFile(path, watchuwant) -- Quicker way to do things w o a h
  10.     local handle = fs.open(path, "w")
  11.     handle.write(textutils.serialise(whatchuwant))
  12.     handle.close()
  13. end
  14.  
  15. local function loadTableFile(path) -- Quiciker way to do things w o a h
  16.     local handle = fs.open(path, "r")
  17.     local thing = textutils.unserialise(handle.readAll())
  18.     handle.close()
  19.     return thing
  20. end
  21.  
  22. local function getSomethingFromTable(theTable, thingWanted) -- A workaround to crappy CC/Lua. >:(
  23.     for k, v in pairs(theTable) do
  24.         if k == thingWanted then
  25.             return v
  26.         end
  27.       end
  28. end
  29.  
  30.  
  31. local function doEncrypt(thing1)
  32.  
  33.     -- local ok = encrypt.encrypt(thing1, "kgkg499tgi34ikg39koowklfow0o349")
  34.      --return ok
  35.      return thing1
  36.  end
  37.  
  38.  local function doDecrypt(thing)
  39.     -- local ok = encrypt.decrypt(thing, "kgkg499tgi34ikg39koowklfow0o349")
  40.     -- return ok
  41.     return thing
  42.  end
  43.  
  44.  local function findPeripheral( t, e )
  45.     t = t:lower()
  46.     for _,s in pairs(rs.getSides()) do
  47.           if peripheral.getType(s) == t then
  48.             return peripheral.wrap(s)
  49.           end
  50.     end
  51.     error("No "..(e or t).." attached to the computer.", 0)
  52.   end
  53.  
  54.  
  55. local function doControlls()
  56.     rednet.open(findPeripheral("modem", "Rednet Modem"))
  57.    while true do
  58.     event, senderId, message, protocol = os.pullEvent()
  59.     if senderId == getSomethingFromTable(config, "serverID") then
  60.     if event == "rednet_message" then
  61.         local response = doDecrypt(message)
  62.  
  63.         if protocol == "HelloPing" then
  64.             rednet.send(getSomethingFromTable(config, "serverID"), "HellO!", "HelloBack")
  65.             print("Server just pinged!")
  66.         end
  67.  
  68.         if protocol == "RemoteConfigUpdate" then
  69.  
  70.         end
  71.    end
  72. end
  73.    if event == "redstone" then
  74.         local input = senderId
  75.  
  76.         for k, v in pairs(signalBlocks) do
  77.             if bundledIO.testBundledInput(getSomethingFromTable(v,"signalColorInput")) then
  78.                 signalBlocks[k].status = 3
  79.                 print(k + " is active!")
  80.             else
  81.                 signalBlocks[k].status = 0
  82.             end
  83.  
  84.         end
  85.  
  86.     --Alright, send signals.
  87.     rednet.send(getSomethingFromTable(config, "serverID"), textutils.serialise(signalBlocks), "SignalUpdate")
  88.  
  89.  
  90.    end
  91.  
  92. end
  93.  
  94. end
  95.  
  96. --Do startup!
  97. print("TrainControl Rednet Signal Server (beta) 1.2 ")
  98.  
  99. if fs.exists("config") then
  100.     config = loadTableFile("config")
  101.     signalDatabase = loadTableFile("signalDatabase")
  102. else
  103.    
  104. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top