Advertisement
programcreator

Main Server

Jan 23rd, 2015
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.90 KB | None | 0 0
  1. modem = peripheral.wrap("bottom")
  2. iniOpts = {"Reboot All PCs","Change Password","Add Door","Remove Door","Lock All Doors","Open All Doors","Reset All Doors","Custom Message","Turtle Run"}
  3. lime = colors.lime
  4. black = colors.black
  5. modem.open(324)
  6. msgTab = {}
  7. turtle = {}
  8. turtleNum = {}
  9. turtleDetails = {}
  10. notNum = true
  11. secretPass = "Ehfks87-i"
  12. secretPass2 = "sgxyg&%UI33%^&HS34DH-N"
  13. turtlePort = 512
  14.  
  15. function clear()
  16.   term.clear()
  17.   term.setCursorPos(1,1)
  18. end
  19.  
  20. function makeString(l)
  21.         if l < 1 then return nil end -- Check for l < 1
  22.         local s = "" -- Start string
  23.         for i = 1, l do
  24.                 s = s .. string.char(math.random(32, 126)) -- Generate random number from 32 to 126, turn it into character and add to string
  25.         end
  26.         return s -- Return string
  27. end
  28.  
  29. function menu(opts)
  30.     doIt = true
  31.     currSelect = 1
  32.  
  33.     while doIt do
  34.     x,y = term.getSize()
  35.     clear()
  36.     term.setCursorPos(x,1)
  37.     term.setBackgroundColor(lime)
  38.     print("^")
  39.     term.setBackgroundColor(black)
  40.  
  41.     if #opts <= y - 4 then
  42.         for i,v in pairs(opts) do
  43.             yPos = 2 + i
  44.             term.setCursorPos(math.floor(x - #v-4)/2,yPos)
  45.             if currSelect == i then
  46.                 print("[["..v.."]]")
  47.             else
  48.                 print("  "..v.."  ")
  49.             end
  50.         end
  51.        
  52.         event , button , xPos , yPos = os.pullEvent()
  53.         if event == "key" then
  54.             if button == keys.up then
  55.                 currSelect = currSelect - 1
  56.             elseif button == keys.down then
  57.                 currSelect = currSelect + 1
  58.             elseif button == keys.enter then
  59.                 doIt = false
  60.                 clear()
  61.             end
  62.         elseif event == "mouse_click" then
  63.             clear()
  64.             doIt = false
  65.             currSelect = yPos - 2
  66.             clear()
  67.         elseif event == "monitor_touch" then
  68.             clear()
  69.             doIt = false
  70.             currSelect = yPos - 2
  71.             clear()
  72.         end
  73.        
  74.         if currSelect == 0 then
  75.             currSelect = #opts
  76.         elseif currSelect == math.floor(#opts + 1) then
  77.             currSelect = 1
  78.         end
  79.        
  80.     else
  81.         for i,v in pairs(opts) do
  82.             yPos = math.floor(y/2) - currSelect + i
  83.             term.setCursorPos(math.floor(x - #v-4)/2,yPos)
  84.             if currSelect == i then
  85.                 print("[["..v.."]]"..i)
  86.             else
  87.                 print("  "..v.."  "..i)
  88.             end
  89.         end
  90.  
  91.         event , button , xPos , yPos = os.pullEvent()
  92.         if event == "key" then
  93.             if button == keys.up then
  94.                 currSelect = currSelect + 1
  95.             elseif button == keys.down then
  96.                 currSelect = currSelect - 1
  97.             elseif button == keys.enter then
  98.                 doIt = false
  99.                 clear()
  100.             end
  101.         elseif event == "mouse_click" then
  102.             doIt = false
  103.             currSelect = yPos - currSelect + math.floor(y/2)
  104.             clear()
  105.         elseif event == "monitor_touch" then
  106.             doIt = false
  107.             currSelect = yPos - math.floor(y/2) + currSelect
  108.             clear()
  109.         end
  110.    
  111.         if currSelect == 0 then
  112.             currSelect = 1
  113.         elseif currSelect == #opts + 1 then
  114.             currSelect = #opts
  115.         end
  116.        
  117.         if currSelect < 1 then
  118.             currSelect = 1
  119.             doIt = true
  120.         elseif currSelect > #opts then
  121.             currSelect = #opts
  122.             doIt = true
  123.         end
  124.     end
  125.   end
  126.  
  127.   return currSelect
  128. end
  129.  
  130. function rebootPc()
  131.     modem.transmit(3721,1,"reboot")
  132. end
  133.  
  134. function changePass()
  135.     clear()
  136.     print("These are the available doors:")
  137.     print()
  138.     fil = {}
  139.     fil = fs.list("disk")
  140.     print("What password do you wish to change? ")
  141.     sel = menu(fil)
  142.     clear()
  143.     if fs.exists("disk/"..fil[sel]) then
  144.         files = fs.open("disk/"..fil[sel], "r")
  145.         print("Current password is: "..files.readAll())
  146.         files.close()
  147.         files = fs.open("disk/"..fil[sel], "w")
  148.         write("Input new password: ")
  149.         files.write(read())
  150.         files.close()
  151.         rebootPc()
  152.     else
  153.         print("This door does not exist!")
  154.         sleep(3)
  155.         changePass()
  156.     end
  157. end
  158.  
  159. function addDoor()
  160.     clear()
  161.     print("What is the name of the new door? ")
  162.     print("(Type <nodoor> if you do not want to create a door.) ")
  163.     write(">")
  164.     desDoor = read()
  165.     if fs.exists("disk/"..desDoor) then
  166.         print("Door does already exist....")
  167.         sleep(2)
  168.         addDoor()
  169.     elseif desDoor == "nodoor" then
  170.         clear()
  171.     else
  172.         clear()
  173.         write("Input desired password: ")
  174.         doorN = fs.open("disk/"..desDoor,"w")
  175.         newP = read()
  176.         doorN.write(newP)
  177.         doorN.close()
  178.         shell.run("startup")
  179.     end
  180. end
  181.  
  182. function deleteDoor()
  183.     clear()
  184.     listF = fs.list("disk")
  185.     delD = menu(listF)
  186.     write("Are you sure you want to delete door "..listF[delD].."? (y/n)")
  187.     sureOrNot = read()
  188.     if sureOrNot == "y" then
  189.         fs.delete("disk/"..listF[delD])
  190.     end
  191. end
  192.  
  193. function lock()
  194.     modem.transmit(3721,1,"lock")
  195. end
  196.  
  197. function rst()
  198.     modem.transmit(3721,1,"reset")
  199. end
  200.  
  201. function openD()
  202.     modem.transmit(3721,1,"open")
  203. end
  204.  
  205. function customMsg()
  206.     clear()
  207.     term.write("Do you want to encrypt the message? <y/n> ")
  208.     answerToQ = read()
  209.     if answerToQ == "n" then
  210.         while notNum do
  211.             clear()
  212.             term.write("Input channel: ")
  213.             chan = tonumber(read())
  214.             if type(chan) == "number" then
  215.                 notNum = false
  216.             end
  217.         end
  218.         term.write("Input message: ")
  219.         messa = read()
  220.         modem.transmit(57, tonumber(chan), messa)
  221.     elseif answerToQ == "y" then
  222.         notNum = true
  223.         while notNum do
  224.             clear()
  225.             term.write("Input channel: ")
  226.             chan = tonumber(read())
  227.             if type(chan) == "number" then
  228.                 notNum = false
  229.             end
  230.         end
  231.         notNum = true
  232.         term.write("Input message: ")
  233.         messa = read()
  234.         while notNum do
  235.             term.write("Input password: <longer than 4 > ")
  236.             passEncr = read()
  237.             if #passEncr > 3 then
  238.                 notNum = false
  239.             end
  240.         end
  241.         messa = encrypt.encrypt(messa,passEncr)
  242.         modem.transmit(57, tonumber(chan), messa)
  243.     end
  244. end
  245.  
  246. function turtleRun()
  247.     local turtle = {}
  248.     local turtleNum = {}
  249.     clear()
  250.     modem.transmit(93,2,textutils.serialize({"turtle"}))
  251.     print("Getting information...")
  252.     local event, side, ch1, ch2, msg = os.pullEvent("modem_message")
  253.     msgTab = textutils.unserialize(msg)
  254.     for i,v in pairs(msgTab) do
  255.         turtleDetails = textutils.unserialize(v)
  256.         turtle[i] = turtleDetails
  257.         turtleNum[i] = tostring(turtleDetails[1])
  258.     end
  259.    
  260.     selectedTurtle = menu(turtleNum)
  261.    
  262.     print("ID: "..turtle[selectedTurtle][1])
  263.     print("X: "..turtle[selectedTurtle][2])
  264.     print("Y: "..turtle[selectedTurtle][3])
  265.     print("Z: "..turtle[selectedTurtle][4])
  266.     write("Did you select the right turtle? <y/n>")
  267.     local answer = read()
  268.     if answer == "y" then
  269.         clear()
  270.         write("What program would you like to run? ")
  271.         modem.transmit(57,512,textutils.serialize({"run",tonumber(turtle[selectedTurtle][1]),read()}))
  272.         --qevent, qside, qch1, qch2, qmsg = os.pullEvent("modem_message")
  273.         --print("msg")
  274.         --sleep(3)
  275.         --modem.transmit(57,turtlePort,encrypt.encrypt(encrypt.decrypt(qmsg,secretPass),secretPass2))
  276.     else
  277.         return false
  278.     end
  279. end
  280.  
  281. function options()
  282.     if iniSelect == 1 then
  283.         rebootPc()
  284.     elseif iniSelect == 2 then
  285.         changePass()
  286.     elseif iniSelect == 3 then
  287.         addDoor()
  288.     elseif iniSelect == 4 then
  289.         deleteDoor()
  290.     elseif iniSelect == 5 then
  291.         lock()
  292.     elseif iniSelect == 6 then
  293.         openD()
  294.     elseif iniSelect == 7 then
  295.         rst()
  296.     elseif iniSelect == 8 then 
  297.         customMsg()
  298.     elseif iniSelect == 9 then
  299.         turtleRun()
  300.     end
  301. end
  302.  
  303. iniSelect = menu(iniOpts)
  304. clear()
  305. options()
  306.  
  307. shell.run("startup")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement