computercam

Domain Client (CC)

Dec 8th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.94 KB | None | 0 0
  1. n = peripheral.wrap("top")
  2. rednet.open("top")
  3. serverID = 0
  4. session = nul
  5. cdtServer = 2
  6. os.loadAPI("APIs/server")
  7. function getSession()
  8.     local senderID, message, distance = rednet.receive()
  9.     session = message
  10. end
  11. function checkSession()
  12.     rednet.send(serverID, "isSessionAlive")
  13.     rednet.send(serverID, session)
  14.     local senderID, message, distance = rednet.receive()
  15.     sessionAlive = message
  16. end
  17. --END FUNCTIONS
  18. server.TestConnection("true")
  19. shell.run("clear")
  20. write("Username: ")
  21. connectionName = io.read()
  22. write("Password: ")
  23. connectionPassword = io.read()
  24. shell.run("clear")
  25. print("Logging in.")
  26. server.connect(connectionName, connectionPassword)
  27. print("Hey, ", connectionName)
  28. local senderID, message, distance = rednet.receive()
  29. if message == "login" then
  30.     print("Waiting for session...")
  31.     getSession() --Gets session from server. If this comes back correct the rest of this is client code.
  32.     function running()
  33.         write("Command: ")
  34.         command = io.read()
  35.         if command == "kill-server" then
  36.             write("Are you sure you want to kill the server?: [y/n] ")
  37.             answer = io.read()
  38.             if answer == "y" then
  39.                 print("Sending command.")
  40.                 rednet.send(serverID, "kill")
  41.                 print("Server should be offline. this session ID will be revoked.")
  42.                 session = null
  43.             end
  44.         else
  45.             if command == "chat" then
  46.                 print("Let's go...")
  47.                 shell.run("domain-chat")
  48.             else
  49.                 if command == "msgb" then
  50.                     rednet.send(serverID, "sendToMon")
  51.                     rednet.send(serverID, session)
  52.                     local senderID, message, distance = rednet.receive()
  53.                     if message == "session_true" then
  54.                         write("Display ID: ")
  55.                         displayID = tonumber(io.read())
  56.                         rednet.send(serverID, displayID)
  57.                         write("Message: ")
  58.                         local msg = io.read()
  59.                         print("Sending")
  60.                         rednet.send(serverID, msg)
  61.                         running()
  62.                     else
  63.                         print("Session invalid... Disconnecting and trying again")
  64.                         running()
  65.                     end
  66.  
  67.                 else
  68.                     if command == "check" then
  69.                         server.TestConnection(false)
  70.                         print("Requesting Session...")
  71.                         checkSession()
  72.                         print(sessionAlive)
  73.                         running()
  74.                     else
  75.                         if command == "cdt" then
  76.                             rednet.send(cdtServer, "deployment-server")
  77.                             local senderID, message, distance = rednet.receive(5)
  78.                             if message == "cdt-session" then
  79.                                 print("SessionID: ", session)
  80.                                 rednet.send(cdtServer, session)
  81.                                 print("Waiting for domain controller...")
  82.                                 local senderID, message, distance = rednet.receive(5)
  83.                                 if message == "cdt-start" then
  84.                                     print("Starting CDT service.... (This takes a while.)")
  85.                                     sleep(2)
  86.                                     local senderID, message, distance = rednet.receive(5)
  87.                                     loop = message
  88.                                     loops = 0
  89.                                     while loops < loop do
  90.                                         loops = loops + 1
  91.                                         local senderID, message, distance = rednet.receive(5)
  92.                                         print("1. ", message)
  93.                                     end
  94.                                     write("Image to run: ")
  95.                                     option = read()
  96.                                     rednet.send(cdtServer, option)
  97.                                     local senderID, message, distance = rednet.receive(20)
  98.                                     if message == "start file install" then
  99.                                         shell.run("clear")
  100.                                         print("CDT SERVICE IS PREPEARING....")
  101.                                         loops = 0
  102.                                         loop = 10
  103.                                         while loops < loop do
  104.                                             loops = loops + 1
  105.                                             write(".")
  106.                                             sleep(0.2)
  107.                                         end
  108.                                         local senderID, message, distance = rednet.receive(20)
  109.                                         loops = 0
  110.                                         loop = message
  111.                                         while loops < loop do
  112.                                             local senderID, message, distance = rednet.receive(10)
  113.                                             shell.run(message)
  114.                                         end
  115.                                     end
  116.                                 end
  117.                             else
  118.                                 print("The server didn't accept the request.")
  119.                                 running()
  120.                             end
  121.                         else
  122.                             server.disconnect(session)
  123.                         end
  124.                         end
  125.                     end
  126.                 end
  127.             end
  128.         end
  129.     running()
  130. else
  131.     print("Sorry, The server returned: ",message, " Sounds like something is wrong, maybe incorrect username or password?")
  132. end
Advertisement
Add Comment
Please, Sign In to add comment