Guest User

startup

a guest
Sep 14th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.83 KB | None | 0 0
  1. tArgs = {...}
  2.  
  3. os.loadAPI("nerdtalk")
  4.  
  5. sgb = peripheral.wrap("stargate_base_4")
  6.  
  7. function isInit()
  8.  return peripheral.call("stargate_base_4", "isInitiator")=="true"
  9. end
  10.  
  11. locked = true
  12.  
  13. function lockGate()
  14. locked = true
  15.  repeat
  16.   sleep(1)
  17.   if isInit()==false then
  18.    sgb.disconnect()
  19.   elseif isInit()==true then
  20.  
  21.   end
  22.  until locked==false
  23. end
  24.  
  25. function unlock()
  26.  locked = false
  27. end
  28.  
  29. local function main()
  30.   local hadd = sgb.getHomeAddress()
  31.   local isconn = sgb.isConnected()
  32.   local isini = sgb.isInitiator()
  33.   local diaadd = sgb.getDialledAddress()
  34.  
  35.   nerdtalk.clearPage()
  36.   nerdtalk.centerPrint("Stargate Prompt V0.1")
  37.   nerdtalk.centerPrint("----------------------")
  38.   nerdtalk.leftWrite("   Home Address: ")
  39.   nerdtalk.rightPrint(hadd.."     ")
  40.   nerdtalk.leftWrite("      Is Locked: ")
  41.   nerdtalk.rightPrint(isLocked().."       ")
  42.   nerdtalk.leftWrite("   Is Connected: ")
  43.   nerdtalk.rightPrint(isconn.."       ")
  44.   nerdtalk.leftWrite("   Is Initiator:")
  45.   nerdtalk.rightPrint(isini.."       ")
  46.   nerdtalk.leftWrite("Dialled Address:")
  47.   nerdtalk.rightPrint(diaadd.."     ")
  48.   nerdtalk.centerPrint(" ")
  49.   nerdtalk.centerPrint("----------------")
  50.   nerdtalk.centerPrint("Command Prompt")
  51.   nerdtalk.centerPrint("----------------")
  52.  command()
  53. end
  54.  
  55. running = true
  56. function command()
  57.   while running do
  58.     write(">")
  59.     input = read()
  60.     if input == "terminalock" then
  61.       nerdtalk.centerPrint("Terminal Locked")
  62.       lockingterm = true
  63.       while lockingterm do
  64.         inputw = read()
  65.         if input == passwordofthegods then
  66.           print("unlocked terminal!")
  67.           lockingterm=false
  68.         end
  69.       end
  70.     end
  71.     if input == "exit" or (input == "exit()") then
  72.       nerdtalk.centerPrint("Exiting...")
  73.       sleep(1)
  74.       running = false
  75.     elseif input == "connect" or (input == "c") then
  76.       nerdtalk.leftWrite("Address: ")
  77.       newinput1 = read()
  78.       newinput = string.upper(newinput1)
  79.       if pcall(sgb.connect,newinput) then
  80.         nerdtalk.leftWrite("Connecting to: ")
  81.         nerdtalk.rightPrint(newinput)
  82.       else
  83.          nerdtalk.leftPrint("Failed to connect!")
  84.       end
  85.     elseif input == "disconnect" or (input == "dc") then
  86.       nerdtalk.leftPrint("Disconnecting From Peer ")
  87.       sgb.disconnect()
  88.     elseif input == "help" then
  89.       nerdtalk.leftPrint("list, ls. connect, c. disconnect, dc. refresh. help. exit")
  90.     elseif input == "refresh" then
  91.       main()
  92.     elseif input == "list" or (input == "ls") then
  93.       nerdtalk.centerPrint("ERROR: None found")
  94.     elseif input == "lock" then
  95.       parallel.waitForAny(lockGate, main)
  96.     elseif input == "unlock" then
  97.       unlock()
  98.       main()
  99.     else
  100.       print("Error: Command not recognized")  
  101.     end
  102.   end
  103. end
  104.  
  105. function isLocked()
  106.  return tostring(locked)
  107. end
  108.  
  109. main()
Advertisement
Add Comment
Please, Sign In to add comment