LDShadowLord

Stargate

Jul 2nd, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.54 KB | None | 0 0
  1. tArgs = {...}
  2.  
  3. os.loadAPI("nerdtalk")
  4.  
  5. sgb = peripheral.wrap("stargate_base_15")
  6.  
  7. function isInit()
  8.  return peripheral.call("stargate_base_15", "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 == "exit" or (input == "exit()") then
  61.       nerdtalk.centerPrint("Exiting...")
  62.       sleep(1)
  63.       running = false
  64.     elseif input == "connect" or (input == "c") then
  65.       nerdtalk.leftWrite("Address: ")
  66.       newinput1 = read()
  67.       newinput = string.upper(newinput1)
  68.       if pcall(sgb.connect,newinput) then
  69.         nerdtalk.leftWrite("Connecting to: ")
  70.         nerdtalk.rightPrint(newinput)
  71.       else
  72.          nerdtalk.leftPrint("Failed to connect!")
  73.       end
  74.     elseif input == "disconnect" or (input == "dc") then
  75.       nerdtalk.leftPrint("Disconnecting From Peer ")
  76.       sgb.disconnect()
  77.     elseif input == "help" then
  78.       nerdtalk.leftPrint("list, ls. connect, c. disconnect, dc. refresh. help. exit")
  79.     elseif input == "refresh" then
  80.       main()
  81.     elseif input == "list" or (input == "ls") then
  82.       nerdtalk.centerPrint("ERROR: None found")
  83.     elseif input == "lock" then
  84.       parallel.waitForAny(lockGate, main)
  85.     elseif input == "unlock" then
  86.       unlock()
  87.       main()
  88.     else
  89.       print("Error: Command not recognized")  
  90.     end
  91.   end
  92. end
  93.  
  94. function isLocked()
  95.  return tostring(locked==true)
  96. end
  97.  
  98. main()
Advertisement
Add Comment
Please, Sign In to add comment