Advertisement
HandieAndy

Station/Server Installation

Jan 21st, 2017
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | None | 0 0
  1. local STATION_URL = "2CwStA8E"
  2. local SERVER_URL = "giJN22xf"
  3.  
  4. --Writes text at a specific position.
  5. function writeC(text, tc)
  6.     term.setTextColor(tc)
  7.     print(text)
  8. end
  9.  
  10. --Trims a string.
  11. function trim(s)
  12.     return (s:gsub("^%s*(.-)%s*$", "%1"))
  13. end
  14.  
  15. --Loops until a choice is made.
  16. function getInput()
  17.     local answer
  18.     while (true) do
  19.         writeC("Is this computer a station or server?", colors.lightBlue)
  20.         term.setTextColor(colors.white)
  21.         answer = trim(string.lower(read()))
  22.         if (answer == "station" or answer == "server") then
  23.             return answer
  24.         end
  25.     end
  26. end
  27.  
  28. writeC("Welcome to HandieAndy's Railcraft Station installation.", colors.blue)
  29. local answer = getInput()
  30. if (answer == "station") then
  31.     writeC("Installing station program.", colors.yellow)
  32.     local x, y = term.getCursorPos()
  33.     term.setCursorPos(1,y+1)
  34.     term.setTextColor(colors.lightGray)
  35.     shell.run("pastebin", "get", STATION_URL, "station")
  36.     local x, y = term.getCursorPos()
  37.     term.setCursorPos(1, y+1)
  38.     writeC("Got program, creating startup script.", colors.yellow)
  39.     local f = fs.open("startup", "w")
  40.     f.write('shell.run("station")')
  41.     f.close()
  42.     writeC("Startup script done.", colors.blue)
  43.     writeC("Starting config generation.", colors.yellow)
  44.     local config = {tracks = {}}
  45.     writeC("What is the ID of the server that will be controlling this station?", colors.lightBlue)
  46.     term.setTextColor(colors.white)
  47.     config.server_id = tonumber(read())
  48.     writeC("What is the unique destination name of this station?", colors.lightBlue)
  49.     term.setTextColor(colors.white)
  50.     config.dest = read()
  51.     writeC("What is the cosmetic name?", colors.lightBlue)
  52.     term.setTextColor(colors.white)
  53.     config.name = read()
  54.     writeC("Enter monitor ID: (Example: 'monitor_0')", colors.lightBlue)
  55.     term.setTextColor(colors.white)
  56.     config.monitor_id = read()
  57.     writeC("Enter noteblock ID: (Example: 'note_block_0')", colors.lightBlue)
  58.     term.setTextColor(colors.white)
  59.     config.note_block_id = read()
  60.     writeC("How many tracks does this station have?", colors.lightBlue)
  61.     term.setTextColor(colors.white)
  62.     local trackCount = tonumber(read())
  63.     for i=1,trackCount do
  64.         config.tracks[i] = {train = -1,}
  65.         writeC("Enter track "..i.."'s sensor ID: ", colors.lightBlue)
  66.         term.setTextColor(colors.white)
  67.         config.tracks[i].sensor_id = read()
  68.         writeC("Enter track "..i.."'s detector decimal color code. For more info, see www.computercraft.info/wiki/Colors_(API).", colors.lightBlue)
  69.         term.setTextColor(colors.white)
  70.         config.tracks[i].detectorColor = tonumber(read())
  71.         writeC("Enter track "..i.."'s ticket retriever color code.", colors.lightBlue)
  72.         term.setTextColor(colors.white)
  73.         config.tracks[i].ticketColor = tonumber(read())
  74.     end
  75.     local f = fs.open("station_config", "w")
  76.     f.write(textutils.serialize(config))
  77.     f.close()
  78.     writeC("Setup is now complete. Remember to double check that everything has been set up properly, and if so, this station is ready for operation after a restart. You may also restart the server for optimal performance.", colors.lime)
  79. elseif (answer == "server") then
  80.     writeC("Installing server program.", colors.yellow)
  81.     local x, y = term.getCursorPos()
  82.     term.setCursorPos(1,y+1)
  83.     term.setTextColor(colors.lightGray)
  84.     shell.run("pastebin", "get", SERVER_URL, "server")
  85.     local x, y = term.getCursorPos()
  86.     term.setCursorPos(1, y+1)
  87.     writeC("Got program, creating startup script.", colors.yellow)
  88.     local f = fs.open("startup", "w")
  89.     f.write('shell.run("server")')
  90.     f.close()
  91.     writeC("Startup script done.", colors.blue)
  92.     writeC("Server installed successfully. Place a wireless modem on top of this computer, and restart it.", colors.lime)
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement