Advertisement
Guest User

startup

a guest
Jun 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 24.23 KB | None | 0 0
  1. mon = peripheral.find("monitor")
  2. sg = peripheral.find("stargate")
  3.  
  4. mon.setBackgroundColor(colors.black)
  5. mon.clear()
  6. maxEng = 50000
  7. dialling = {}
  8.  
  9. local function alarmSet(set)
  10.   rs.setOutput("left", set)
  11.   return
  12. end
  13.  
  14. function drawPowerBar() -- checks power levels and writes power bar to monitor
  15.   x,y = mon.getSize()
  16.   engPercent = (sg.energyAvailable() / (maxEng +1)) * 100 -- returns percent
  17.   for i = y, (y - y / 100 * engPercent), -1 do
  18.     mon.setCursorPos(x-2,i)
  19.     if i > y/4*3 then
  20.       mon.setBackgroundColor(colors.red)
  21.       mon.setTextColor(colors.red)
  22.     elseif i > y/2 then
  23.       mon.setBackgroundColor(colors.orange)
  24.       mon.setTextColor(colors.orange)
  25.     elseif i > y/4 then
  26.       mon.setBackgroundColor(colors.green)
  27.       mon.setTextColor(colors.green)
  28.     else
  29.       mon.setBackgroundColor(colors.lime)
  30.       mon.setTextColor(colors.lime)
  31.     end
  32.     mon.write("  ")
  33.   end
  34.   mon.setBackgroundColor(colors.black)
  35.   mon.setCursorPos(x-9,y)
  36.   mon.write(math.floor(sg.energyAvailable() / 1000).."k SU ")
  37. end
  38.  
  39. function drawChevrons() --draws cheyvrons on the screen
  40.   x,y = mon.getSize()
  41.   chevX1 = x/3
  42.   chevX2 = x/3*2+1
  43.   chevY1 = y/3-2
  44.   chevY2 = y/3*2 +2
  45.   mon.setBackgroundColor(colors.black)
  46.   for yc = chevY1-2, chevY2-2 do
  47.     for xc = chevX1-2, chevX2-2 do
  48.       mon.setCursorPos(xc, yc)
  49.       mon.write(" ")
  50.     end
  51.   end
  52.   mon.setBackgroundColor(colors.lightGray)
  53.   for i = chevX1+2, chevX2-2 do
  54.     mon.setCursorPos(i,chevY1)
  55.     mon.write(" ")
  56.   end
  57.   for i = chevX1+2, chevX2-2 do
  58.     mon.setCursorPos(i,chevY2)
  59.     mon.write(" ")
  60.   end
  61.   for i = chevY1+2, chevY2-2 do
  62.     mon.setCursorPos(chevX1,i)
  63.     mon.write(" ")
  64.   end
  65.   for i = chevY1+2, chevY2-2 do
  66.     mon.setCursorPos(chevX2, i)
  67.     mon.write(" ")
  68.   end
  69.   chev1pos = {chevX1, chevY2 }
  70.   mon.setBackgroundColor(colors.gray)
  71.   mon.setTextColor(colors.black)
  72.   mon.setCursorPos(math.floor(chev1pos[1]), math.floor(chev1pos[2])-1)
  73.   mon.write(" 4 ")
  74.   chev2pos = {chevX1, chevY1 + ((chevY2 - chevY1) / 2) }
  75.   mon.setCursorPos(math.floor(chev2pos[1]-1), math.floor(chev2pos[2]))
  76.   mon.write(" 5 ")
  77.   chev3pos = {chevX1, chevY1 }
  78.   mon.setCursorPos(math.floor(chev3pos[1]), math.floor(chev3pos[2]+1))
  79.   mon.write(" 6 ")
  80.   chev4pos = {chevX1 + ((chevX2 - chevX1) / 2), chevY1 }
  81.   mon.setCursorPos(math.floor(chev4pos[1]-1), math.floor(chev4pos[2]))
  82.   mon.write(" 7 ")
  83.   chev5pos = {chevX2, chevY1 }
  84.   mon.setCursorPos(math.floor(chev5pos[1]-2), math.floor(chev5pos[2])+1)
  85.   mon.write(" 1 ")
  86.   chev6pos = {chevX2, chevY1 + ((chevY2 - chevY1) / 2) }
  87.   mon.setCursorPos(math.floor(chev6pos[1]-1), math.floor(chev6pos[2]))
  88.   mon.write(" 2 ")
  89.   chev7pos = {chevX2, chevY2 }
  90.   mon.setCursorPos(math.floor(chev7pos[1]-2), math.floor(chev7pos[2]-1))
  91.   mon.write(" 3 ")
  92.   chev8pos = {chevX1 + ((chevX2 - chevX1) /2), chevY2 }
  93.   mon.setCursorPos(math.floor(chev8pos[1]-1), math.floor(chev8pos[2]))
  94.   mon.write(" 8 ")
  95.   chev9pos = {chevX1 + ((chevX2 - chevX1) /2), chevY2 }
  96.   mon.setCursorPos(math.floor(chev8pos[1]-1), chevY1 + ((chevY2 - chevY1) / 2))
  97.   mon.write(" 9 ")
  98.   mon.setBackgroundColor(colors.black)
  99.   mon.setCursorPos(x/2 - 4, y/2 - 1)
  100.   mon.write("           ")
  101.   mon.setCursorPos(x/2-1, y/2+4)
  102.   mon.write("     ")
  103. end
  104.  
  105. function drawChev( chevInfo )
  106.   mon.setBackgroundColor(colors.gray)
  107.   x,y = mon.getSize()
  108.   chevX1 = x/3
  109.   chevX2 = x/3*2+1
  110.   chevY1 = y/3-2
  111.   chevY2 = y/3*2 +2
  112.   if chevInfo[1] == 4 then
  113.     chev1pos = {chevX1, chevY2 }
  114.     mon.setBackgroundColor(colors.gray)
  115.     mon.setCursorPos(math.floor(chev1pos[1]), math.floor(chev1pos[2])-1)
  116.     mon.write(" "..chevInfo[2].." ")
  117.   elseif chevInfo[1] == 5 then
  118.     chev2pos = {chevX1, chevY1 + ((chevY2 - chevY1) / 2) }
  119.     mon.setCursorPos(math.floor(chev2pos[1]-1), math.floor(chev2pos[2]))
  120.     mon.write(" "..chevInfo[2].." ")
  121.   elseif chevInfo[1] == 6 then
  122.     chev3pos = {chevX1, chevY1 }
  123.     mon.setCursorPos(math.floor(chev3pos[1]), math.floor(chev3pos[2]+1))
  124.     mon.write(" "..chevInfo[2].." ")
  125.   elseif chevInfo[1] == 7 then
  126.     chev4pos = {chevX1 + ((chevX2 - chevX1) / 2), chevY1 }
  127.     mon.setCursorPos(math.floor(chev4pos[1]-1), math.floor(chev4pos[2]))
  128.     mon.write(" "..chevInfo[2].." ")
  129.   elseif chevInfo[1] == 1 then
  130.     chev5pos = {chevX2, chevY1 }
  131.     mon.setCursorPos(math.floor(chev5pos[1]-2), math.floor(chev5pos[2])+1)
  132.     mon.write(" "..chevInfo[2].." ")
  133.   elseif chevInfo[1] == 2 then
  134.     chev6pos = {chevX2, chevY1 + ((chevY2 - chevY1) / 2) }
  135.     mon.setCursorPos(math.floor(chev6pos[1]-1), math.floor(chev6pos[2]))
  136.     mon.write(" "..chevInfo[2].." ")
  137.   elseif chevInfo[1] == 3 then
  138.     chev7pos = {chevX2, chevY2 }
  139.     mon.setCursorPos(math.floor(chev7pos[1]-2), math.floor(chev7pos[2]-1))
  140.     mon.write(" "..chevInfo[2].." ")
  141.   elseif chevInfo[1] == 8 then
  142.     chev8pos = {chevX1 + ((chevX2 - chevX1) /2), chevY2 }
  143.     mon.setCursorPos(math.floor(chev8pos[1]-1), math.floor(chev8pos[2]))
  144.     mon.write(" "..chevInfo[2].." ")
  145.   elseif chevInfo[1] == 9 then
  146.     chev9pos = {chevX1 + ((chevX2 - chevX1) /2), chevY2 }
  147.     mon.setCursorPos(math.floor(chev8pos[1]-1), chevY1 + ((chevY2 - chevY1) / 2))
  148.     mon.write(" "..chevInfo[2].." ")
  149.   mon.setBackgroundColor(colors.black)
  150. end
  151.  
  152. end
  153.  
  154. function drawSgStatus(status) -- draws stargate status
  155.   if status ~= "Idle" then
  156.   term.setCursorPos(1,2)
  157.   write(status) --needed for sting length because sting.len() won't work with stargateStatus()
  158.   xc, yc = term.getCursorPos()
  159.   term.clear()
  160.   term.setCursorPos(1,2)
  161.   write("> ")
  162.   if xc%2 == 1 then
  163.     xc = xc+1
  164.     even = true
  165.   else
  166.     even = false
  167.   end
  168.   mon.setBackgroundColor(colors.black)
  169.   if status == "Connected" then
  170.     mon.setTextColor(colors.lightBlue)
  171.     redstone.setOutput("back",false)
  172.   elseif status == "Dialling" then
  173.     mon.setTextColor(colors.orange)
  174.     redstone.setOutput("back",true)
  175.   else
  176.     mon.setTextColor(colors.green)
  177.   end
  178.   x,y = mon.getSize()
  179.   mon.setCursorPos((x/2+1) - 6, y/2+2)
  180.   mon.write("            ")
  181.   mon.setCursorPos((x/2+1) - (xc/2-1), y/2+2)
  182.   mon.write(status)
  183.   if even == true then
  184.     mon.write(".")
  185.   end
  186.   end
  187. end
  188.  
  189. function drawIris(state) --draws button to control the Iris
  190.   mon.setBackgroundColor(colors.lightGray)
  191.   ok, result = pcall(sg.openIris)
  192.   if ok == false then
  193.     mon.setTextColor(colors.red)
  194.   elseif state == true then
  195.     sg.closeIris()
  196.     mon.setTextColor(colors.lime)
  197.   else
  198.     mon.setTextColor(colors.black)
  199.     sg.openIris()
  200.   end
  201.   s = "   IRIS   "
  202.   i = 1
  203.   for  yc = y/3-1, y/3*2 +1 do
  204.     char = string.sub(s, i, i)
  205.     mon.setCursorPos(6, yc)
  206.     mon.write(" "..char.." ")
  207.     i = i+1
  208.   end
  209.   if state == true then
  210.     mon.setTextColor(colors.lime)
  211.   else
  212.     mon.setTextColor(colors.black)
  213.   end
  214. end
  215.  
  216. function drawLocalAddress() -- draws the address stargate being controlled
  217.   x,y = mon.getSize()
  218.   mon.setBackgroundColor(colors.black)
  219.   mon.setTextColor(colors.lightGray)
  220.   mon.setCursorPos(x/2-7, 1)
  221.   mon.write("Stargate Address:")
  222.   mon.setCursorPos(x/2-3, 2)
  223.   mon.write(sg.localAddress())
  224. end
  225.  
  226. function drawDial() -- draws the button to access the dialing menu
  227.   x,y = mon.getSize()
  228.   state, int = sg.stargateState()
  229.   for yc = y-3, y-1 do
  230.     for xc = x/2-5, x/2 do
  231.       if state == "Idle" then
  232.         mon.setBackgroundColor(colors.lightGray)
  233.       else
  234.         mon.setBackgroundColor(colors.gray)
  235.       end
  236.       mon.setCursorPos(xc,yc)
  237.       mon.write(" ")
  238.     end
  239.   end
  240.   mon.setCursorPos(x/2-4, y-2)
  241.   mon.setTextColor(colors.black)
  242.   mon.write("DIAL")
  243. end
  244.  
  245. function drawTerm() -- draws the button to terminate the stargate connection to another gate
  246.   x,y = mon.getSize()
  247.   state, int = sg.stargateState()
  248.   for yc = y-3, y-1 do
  249.     for xc = x/2+2, x/2+7 do
  250.       if state == "Connected" or state == "Connecting" or state == "Dialling" then
  251.         mon.setBackgroundColor(colors.lightGray)
  252.       else
  253.         mon.setBackgroundColor(colors.gray)
  254.       end
  255.       mon.setCursorPos(xc,yc)
  256.       mon.write(" ")
  257.     end
  258.   end
  259.   mon.setCursorPos(x/2+3, y-2)
  260.   mon.setTextColor(colors.black)
  261.   mon.write("TERM")
  262. end
  263.  
  264. function securityButton() -- draws the button to access the security menu
  265.   x,y = mon.getSize()
  266.   mon.setBackgroundColor(colors.lightGray)
  267.   sOK, result = pcall(sg.openIris)
  268.   if sOK == false then
  269.     mon.setTextColor(colors.red)
  270.   else
  271.     mon.setTextColor(colors.black)
  272.   end
  273.   s = " DEFENCE "
  274.   i = 1
  275.   for  yc = y/3-1, y/3*2 +1 do
  276.     char = string.sub(s, i, i)
  277.     mon.setCursorPos(2, yc)
  278.     mon.write(" "..char.." ")
  279.     i = i+1
  280.   end
  281.   mon.setBackgroundColor(colors.black)
  282. end
  283.  
  284. function drawSecurityPageTop() --draws the top of the security menu, all the addresses stored in the security table
  285.   mon.setBackgroundColor(colors.black)
  286.   mon.clear()
  287.   mon.setTextColor(colors.black)
  288.   x,y = mon.getSize()
  289.   for yc = 1,y-3 do
  290.     if yc%2 == 1 then
  291.       mon.setBackgroundColor(colors.lightBlue)
  292.     else
  293.       mon.setBackgroundColor(colors.lightGray)
  294.     end
  295.     for xc = 1,x do
  296.       mon.setCursorPos(xc, yc)
  297.       mon.write(" ")
  298.     end
  299.     mon.setCursorPos(x/2-4, yc)
  300.     mon.write("Add Address")
  301.   end
  302.   if fs.exists("secList") then
  303.     file = fs.open("secList","r")
  304.     secInfo = textutils.unserialize(file.readAll())
  305.     file.close()
  306.     if string.len(textutils.serialize(secInfo)) > 7 then
  307.     for k,v in pairs(secInfo) do
  308.       mon.setCursorPos(1,i)
  309.         if k%2 == 1 then
  310.           mon.setBackgroundColor(colors.lightBlue)
  311.         else
  312.           mon.setBackgroundColor(colors.lightGray)
  313.         end
  314.         mon.setCursorPos(1, k)
  315.         mon.write(v.name)
  316.         mon.setCursorPos(x/2-4, k)
  317.         mon.write("           ")
  318.         mon.setCursorPos(x/2 - string.len(v.address)/2 +1, k)
  319.         mon.write(v.address)
  320.         mon.setCursorPos(x,k)
  321.         mon.setBackgroundColor(colors.red)
  322.         mon.write("X")
  323.     end
  324.     end
  325.   end
  326.   mon.setBackgroundColor(colors.black)
  327. end
  328.  
  329. function drawSecurityPageBottom(listType) -- draws the buttons at the bottom of the security page
  330.   for yc = y-2, y do
  331.     for xc = 1, x do
  332.       mon.setCursorPos(xc, yc)
  333.       if listType == "BLACKLIST" then
  334.         mon.setBackgroundColor(colors.black)
  335.         mon.setTextColor(colors.white)
  336.       elseif listType == "WHITELIST" then
  337.         mon.setBackgroundColor(colors.white)
  338.         mon.setTextColor(colors.black)
  339.       elseif listType == "NONE" then
  340.         mon.setBackgroundColor(colors.gray)
  341.         mon.setTextColor(colors.white)
  342.       end
  343.       mon.write(" ")
  344.     end
  345.   end
  346.   mon.setCursorPos((x/2 - tonumber(string.len(listType)/2)+1), y-1)
  347.   mon.write(listType)
  348.   mon.setCursorPos(x-5, y-1)
  349.   mon.write("BACK")
  350.   mon.setBackgroundColor(colors.black)
  351. end  
  352.  
  353. function drawHome() -- draws the home screen
  354.   mon.setBackgroundColor(colors.black)
  355.   x,y = mon.getSize()
  356.   mon.clear()
  357.   mon.setCursorPos(1,y)
  358.   mon.setTextColor(colors.gray)
  359.   mon.setBackgroundColor(colors.black)
  360.   mon.write("thatParadox")
  361.   drawPowerBar()
  362.   drawChevrons()
  363.   status, int = sg.stargateState()
  364.   drawSgStatus(tostring(status))
  365.   drawHistoryButton()
  366.   if sg.irisState()  == "Open" then
  367.     drawIris(false)
  368.   else
  369.     drawIris(true)
  370.   end
  371.   drawLocalAddress()
  372.   securityButton()
  373.   drawDial()
  374.   mon.setCursorBlink(false)
  375.   drawTerm()
  376. end
  377.  
  378. function drawBookmarksPage()
  379.   mon.setBackgroundColor(colors.black)
  380.   mon.clear()
  381.   mon.setTextColor(colors.black)
  382.   x,y = mon.getSize()
  383.   for yc = 1,y-3 do
  384.     if yc%2 == 1 then
  385.       mon.setBackgroundColor(colors.lightBlue)
  386.     else
  387.       mon.setBackgroundColor(colors.lightGray)
  388.     end
  389.     for xc = 1,x do
  390.       mon.setCursorPos(xc, yc)
  391.       mon.write(" ")
  392.     end
  393.   end
  394.   for i= 1,y do
  395.     if i%2 == 1 then
  396.       mon.setBackgroundColor(colors.lightBlue)
  397.     else
  398.       mon.setBackgroundColor(colors.lightGray)
  399.     end
  400.     if fs.exists(tostring(i)) then
  401.       file = fs.open(tostring(i),"r")
  402.       bookmark = textutils.unserialize(file.readAll())
  403.       file.close()
  404.       mon.setCursorPos(1,i)
  405.       for k,v in pairs(bookmark) do
  406.         if k == "name" then
  407.           mon.write(v)
  408.           mon.setCursorPos(x/2, i)
  409.           mon.write(bookmark.address)
  410.           mon.setCursorPos(x,i)
  411.           mon.setBackgroundColor(colors.red)
  412.           mon.write("X")
  413.         end
  414.       end
  415.     elseif i < y-2 then
  416.       mon.setCursorPos(1, i)
  417.       mon.write("Add Address")
  418.     end
  419.   end
  420.   mon.setCursorPos(x/2, y-1)
  421.   mon.setBackgroundColor(colors.black)
  422.   mon.setTextColor(colors.white)
  423.   mon.write("BACK")
  424. end
  425.  
  426. function drawRemoteIris()
  427.   mon.setBackgroundColor(colors.black)
  428.   x,y = mon.getSize()
  429.   mon.setCursorPos(x/2-1, y/2+4)
  430.   mon.write("IRIS.")
  431. end
  432.  
  433. function inputPage(type)
  434.   mon.clear()
  435.   term.redirect(mon)
  436.   term.setBackgroundColor(colors.lightGray)
  437.   term.clear()
  438.   x,y = term.getSize()
  439.   term.setCursorPos(x/2-8, y/2-2)
  440.   print("Set an address name")
  441.   term.setCursorPos(x/2 - 4, y/2)
  442.   print("         ")
  443.   term.setCursorPos(x/2 - 4, y/2)
  444.   nameInput = read()
  445.   addressInput = "nil"
  446.   term.setBackgroundColor(colors.lightGray)
  447.   term.clear()
  448.   term.setCursorPos(x/2-9, y/2-4)
  449.   print("Enter Stargate address")
  450.   if type == "secEntry" then
  451.     term.setCursorPos(x/2-10, y/2-2)
  452.     print("DO NOT ENTER ANY HYPHONS")
  453.   end
  454.   term.setBackgroundColor(colors.black)
  455.   term.setCursorPos(x/2 - 5, y/2)
  456.   print("           ")
  457.   term.setCursorPos(x/2 - 5, y/2)
  458.   addressInput = string.upper(read())
  459.   newGate ={name = nameInput, address = addressInput}
  460.   term.redirect(term.native())
  461.   return newGate
  462. end
  463.  
  464. function drawRemoteAddress()
  465.   mon.setBackgroundColor(colors.black)
  466.   x,y = mon.getSize()
  467.   mon.setCursorPos((x/2+1) - string.len(sg.remoteAddress())/2, y/2-2)
  468.   mon.write(sg.remoteAddress())
  469. end
  470.  
  471. function drawHistoryButton()
  472.   mon.setBackgroundColor(colors.lightGray)
  473.   mon.setTextColor(colors.black)
  474.   s = " HISTORY "
  475.   i = 1
  476.   for  yc = y/3-1, y/3*2 +1 do
  477.     char = string.sub(s, i, i)
  478.     mon.setCursorPos(x-7, yc)
  479.     mon.write(" "..char.." ")
  480.     i = i+1
  481.   end
  482. end
  483.  
  484. function addToHistory(address)
  485.   if fs.exists("history") then
  486.     file = fs.open("history", "r")
  487.     history = textutils.unserialize(file.readAll())
  488.     file.close()
  489.   else
  490.     history ={}
  491.     print("")
  492.     print("")
  493.     print("no history file")
  494.   end
  495.   if textutils.serialize(history) == false then
  496.     history = {}
  497.     print("")
  498.     print("")
  499.     print("couldn't serialize")
  500.   end
  501.   test = textutils.serialize(historyTable)
  502.   --if string.len(test) < 7 then
  503.     --history = {}
  504.     --print("")
  505.     --print("")
  506.     --print("string.len too short")
  507.   --end
  508.   table.insert(history, 1, address)
  509.   file = fs.open("history", "w")
  510.   file.write(textutils.serialize(history))
  511.   file.close()
  512. end
  513.  
  514. function drawHistoryPage()
  515.   mon.setBackgroundColor(colors.black)
  516.   mon.clear()
  517.   mon.setTextColor(colors.black)
  518.   x,y = mon.getSize()
  519.   for yc = 1,y-3 do
  520.     if yc%2 == 1 then
  521.       mon.setBackgroundColor(colors.lightBlue)
  522.     else
  523.       mon.setBackgroundColor(colors.lightGray)
  524.     end
  525.     for xc = 1,x do
  526.       mon.setCursorPos(xc, yc)
  527.       mon.write(" ")
  528.     end
  529.   end
  530.   if fs.exists("history") then
  531.     file = fs.open("history","r")
  532.     historyTable = textutils.unserialize(file.readAll())
  533.     file.close()
  534.     test = textutils.serialize(historyTable)
  535.     if string.len(test) > 7 then
  536.       for k,v in pairs(historyTable) do
  537.         if k%2 == 1 then
  538.           mon.setBackgroundColor(colors.lightBlue)
  539.         else
  540.           mon.setBackgroundColor(colors.lightGray)
  541.         end
  542.         mon.setCursorPos(1,k)
  543.         mon.write(v)
  544.         mon.setCursorPos(x/2+7, k)
  545.         mon.setBackgroundColor(colors.blue)
  546.         mon.write("SAVE")
  547.         mon.setCursorPos(x-8, k)
  548.         mon.setBackgroundColor(colors.red)
  549.         mon.write("BAN/ALLOW")
  550.         clickLimit = k
  551.       end
  552.     end
  553.     test = {}
  554.   end
  555.   mon.setBackgroundColor(colors.black)
  556.   for yc = y-2, y do
  557.     for xc = 1,x do
  558.       mon.setCursorPos(xc, yc)
  559.       mon.write(" ")
  560.     end
  561.   end
  562.   mon.setCursorPos(x/2, y-1)
  563.   mon.setTextColor(colors.white)
  564.   mon.write("BACK")
  565. end
  566.  
  567. function historyInputPage(address)
  568.   cx, cy = term.getCursorPos()
  569.   mon.clear()
  570.   term.redirect(mon)
  571.   term.setBackgroundColor(colors.lightGray)
  572.   term.clear()
  573.   x,y = term.getSize()
  574.   term.setCursorPos(x/2-8, y/2-2)
  575.   print("Set an address name")
  576.   term.setCursorPos(x/2 - 4, y/2)
  577.   print("         ")
  578.   term.setCursorPos(x/2 - 4, y/2)
  579.   nameInput = read()
  580.   addressInput = "nil"
  581.   newGate ={name = nameInput, address = address}
  582.   term.redirect(term.native())
  583.   term.clear()
  584.   term.setCursorPos(1,1)
  585.   return newGate
  586. end
  587.  
  588.  
  589. if fs.exists("currentSec") then -- checks to see if there's list of gates stored for security reasons
  590.   file = fs.open("currentSec", "r")
  591.   currentSec = file.readAll()
  592.   file.close()
  593. else
  594.   currentSec = "NONE"
  595. end
  596. mon.setTextScale(1)
  597. drawHome()
  598. while true do
  599.   event, param1, param2, param3 = os.pullEvent()
  600.   if event == "monitor_touch" then
  601.     x,y = mon.getSize()
  602.     if param2 >= 6 and param2 <= 8 and param3 >= y/3-2 and param3 <= y/3*2+1 then --opens or closes the Iris
  603.       if sg.irisState() == "Closed" then
  604.         ok, result = pcall(sg.openIris)
  605.         if ok then
  606.           drawIris(false)
  607.         end
  608.       else
  609.         ok, result = pcall(sg.closeIris)
  610.           if ok then
  611.             drawIris(true)
  612.           end
  613.       end
  614.     elseif param2 >= 2 and param2 <= 4 and param3 >= y/3-2 and param3 <= y/3*2+1 then -- click has opened the security menu
  615.       sOK, result = pcall(sg.openIris)
  616.       if sOK then
  617.       while true do
  618.         drawSecurityPageTop()
  619.         drawSecurityPageBottom(currentSec)
  620.         event, param1, param2, param3 = os.pullEvent()
  621.         if event == "monitor_touch" then
  622.           if param3 >= y-2 then --checks if the user's touch is at the bottom of the screen with the buttons
  623.             if param2 >= x-8 then -- "back" button has been pushed, returns user to home menu
  624.               drawHome()
  625.               break
  626.             elseif param2 < x-6 then -- Click has changed the security type, cycles through "BLACKLIST", "WHITELIST", "NONE"
  627.               if currentSec == "BLACKLIST" then
  628.                 currentSec = "WHITELIST"
  629.               elseif currentSec == "WHITELIST" then
  630.                 currentSec = "NONE"        
  631.               elseif currentSec == "NONE" then
  632.                   currentSec = "BLACKLIST"
  633.               end
  634.               file = fs.open("currentSec", "w")
  635.               file.write(currentSec)
  636.               file.close()
  637.             end
  638.           elseif param2 > x - 3 then -- delete record
  639.               file = fs.open("secList", "r")
  640.               secList = textutils.unserialize(file.readAll())
  641.               file.close()
  642.               table.remove(secList, param3)
  643.               file = fs.open("secList", "w")
  644.               file.write(textutils.serialize(secList))
  645.               file.close()
  646.               drawSecurityPageTop()
  647.           elseif param3 < y - 2 then -- check if empty, if so add new entry  
  648.             if fs.exists("secList") == false then
  649.               secList = {}
  650.               table.insert(secList, 1, inputPage())
  651.               file = fs.open("secList", "w")
  652.               file.write(textutils.serialize(secList))
  653.               file.close()
  654.             else
  655.               file = fs.open("secList", "r")
  656.               secList = textutils.unserialize(file.readAll())
  657.               file.close()
  658.               table.insert(secList, 1, inputPage("secEntry"))
  659.               file = fs.open("secList", "w")
  660.               file.write(textutils.serialize(secList))
  661.               file.close()
  662.             end
  663.             drawSecurityPageTop()
  664.             drawSecurityPageBottom(currentSec)
  665.           end
  666.         else -- if an event that isn't a users touch happens the screen will return to the home screen (in case of incoming connection)
  667.           drawHome()
  668.           break
  669.         end
  670.       end
  671.       end
  672.     elseif param2 > x/2-5 and param2 <= x/2 and param3 >= y-3 and param3 <= y-1 then -- Click has opened dial menu
  673.       status, int = sg.stargateState()
  674.       if status == "Idle" then
  675.       while true do
  676.         drawBookmarksPage()
  677.         event, param1, param2, param3 = os.pullEvent()
  678.         if event == "monitor_touch" then
  679.           if param3 >= y-2 then -- user clicked back
  680.             drawHome()
  681.             break
  682.           elseif param2 > x-2 then -- user clicked delete on a bookmark
  683.             if fs.exists(tostring(param3)) then
  684.               fs.delete(tostring(param3))
  685.             end
  686.           else -- user has clicked on a bookmark
  687.             if fs.exists(tostring(param3)) then
  688.               file = fs.open(tostring(param3), "r")
  689.               gateData = textutils.unserialize(file.readAll()) -- GATE DATA VARIABLE!!!
  690.               file.close()
  691.               drawHome()
  692.               for k,v in pairs(gateData) do
  693.                 if k == "address" then
  694.                   ok, result = pcall(sg.dial, v)
  695.                   if ok then
  696.                     status, int = sg.stargateState()
  697.                     drawSgStatus(status)
  698.                     address = v
  699.                     addToHistory(v)
  700.                   else
  701.                     drawSgStatus("Error")
  702.                   end
  703.                 end
  704.                 sleep(.5)
  705.               end
  706.               break
  707.             else
  708.               x,y = mon.getSize()
  709.               for i = 1,y do
  710.                 if fs.exists(tostring(i)) == false then
  711.                   file = fs.open(tostring(i), "w")
  712.                   file.write(textutils.serialize(inputPage()))
  713.                   file.close()
  714.                   break
  715.                 end
  716.               end
  717.             end
  718.           end
  719.         else
  720.           drawHome()
  721.           break
  722.         end
  723.       end
  724.       end
  725.     elseif param2 > x-7 and param2 < x-4 and param3 >= y/3-2 and param3 <= y/3*2+1 then -- Click has opened history menu
  726.       while true do
  727.         drawHistoryPage()
  728.         event, param1, param2, param3 = os.pullEvent()
  729.         if event == "monitor_touch" then
  730.           if param3 >= y-2 then -- user clicked back
  731.             drawHome()
  732.             break --might break everything
  733.           elseif param2 >= x/2+7 and param2 <= x/2+10 and param3 <= clickLimit then -- user has clicked save.
  734.             if fs.exists("history") then
  735.               file = fs.open("history", "r")
  736.               history = textutils.unserialize(file.readAll())
  737.               file.close()
  738.               for i = 1,y do
  739.                 if fs.exists(tostring(i)) == false then
  740.                   file = fs.open(tostring(i), "w")
  741.                   file.write(textutils.serialize(historyInputPage(history[param3])))
  742.                   file.close()
  743.                   break
  744.                 end
  745.               end
  746.             end
  747.           elseif param2 >= x-9 and param3 <= clickLimit then -- user click "ban/allow"
  748.             if fs.exists("history") then
  749.               file = fs.open("history", "r")
  750.               history = textutils.unserialize(file.readAll())
  751.               file.close()
  752.               if fs.exists("secList") == false then
  753.                 secList = {}
  754.                 table.insert(secList, 1, historyInputPage(history[param3]))
  755.                 file = fs.open("secList", "w")
  756.                 file.write(textutils.serialize(secList))
  757.                 file.close()
  758.               else
  759.                 file = fs.open("secList", "r")
  760.                 secList = textutils.unserialize(file.readAll())
  761.                 file.close()
  762.                 table.insert(secList, 1, historyInputPage(history[param3]))
  763.                 file = fs.open("secList", "w")
  764.                 file.write(textutils.serialize(secList))
  765.                 file.close()
  766.               end
  767.             end
  768.           end
  769.           drawHome()
  770.           break  
  771.         end    
  772.       end
  773.     elseif param2 > x/2+2 and param2 <= x/2+7 and param3 >= y-3 and param3 <= y-1 then -- user clicked TERM
  774.       ok, result = pcall(sg.disconnect)
  775.       drawChevrons()
  776.     end
  777.   elseif event == "sgDialIn" then
  778.     mon.setTextColor(colors.orange)
  779.     drawRemoteAddress()
  780.     alarmSet(true)
  781.     if fs.exists("currentSec") then
  782.       file = fs.open("currentSec", "r")
  783.       currentSec = file.readAll()
  784.       file.close()
  785.     end
  786.     if fs.exists("secList") then
  787.       file = fs.open("secList", "r")
  788.       secList = textutils.unserialize(file.readAll())
  789.       for k,v in pairs(secList) do
  790.         address = v.address
  791.         if string.sub(v.address,1,7) == param2 or v.address == param2 then
  792.           if currentSec == "BLACKLIST" then
  793.             sg.closeIris()
  794.             drawIris(true)
  795.           elseif currentSec == "WHITELIST" then
  796.               sg.openIris()
  797.               drawIris(false)
  798.           else
  799.             sg.openIris()
  800.             drawIris(false)
  801.           end
  802.           secGate = true
  803.         end
  804.       end
  805.     end
  806.     if secGate == true and currentSec == "WHITELIST" then
  807.       sg.openIris()
  808.       drawIris(false)
  809.       gateSec = false
  810.     end
  811.     addToHistory(param2)
  812.   elseif event == "sgMessageReceived" then
  813.     if param2 == "Open" then
  814.       mon.setTextColor(colors.lime)
  815.       drawRemoteIris()
  816.     elseif param2 == "Closed" then
  817.       mon.setTextColor(colors.red)
  818.       drawRemoteIris()
  819.     end  
  820.   elseif event == "sgStargateStateChange" or "sgChevronEngaged" then
  821.     drawDial()
  822.     drawPowerBar()
  823.     drawTerm()
  824.     status, int = sg.stargateState()
  825.     drawSgStatus(tostring(status))
  826.     if status == "idle" then
  827.       isConnected = false
  828.     else
  829.       isConnected = true
  830.     end
  831.     if event == "sgChevronEngaged" then
  832.       mon.setTextColor(colors.orange)
  833.       drawChev({param2, param3})
  834.       if param2 == 1 then
  835.         dialling = {}
  836.       end
  837.       table.insert(dialling, param2, param3)
  838.       drawRemoteAddress()
  839.     elseif param2 == "Idle" then
  840.       alarmSet(false)
  841.       drawChevrons()
  842.     elseif param2 == "Connected" then
  843.       alarmSet(false)
  844.       mon.setTextColor(colors.lightBlue)
  845.       drawRemoteAddress()
  846.       for k,v in pairs(dialling) do
  847.         drawChev({k,v})
  848.       end
  849.       sg.sendMessage(sg.irisState())
  850.     end
  851.   end
  852. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement