computercam

Domain controller (CC)

Dec 8th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.43 KB | None | 0 0
  1. shell.run("clear")
  2. print("---------------------Server------------------------")
  3. print("Initilizing....")
  4. m = peripheral.wrap("right")
  5. rednet.open("top")
  6. username = "Cameron"
  7. password = "test"
  8. username2 = "Account2"
  9. password2 = "test2"
  10. monitor = "monitor"
  11. monpass = "password-monitor-password"
  12. session1 = "null"
  13. session2 = "null"
  14. session3 = "null"
  15. session4 = "null"
  16. session5 = "null"
  17. print("Starting server...")
  18. running = true
  19. print("Server is live.")
  20. function sessionID()
  21.     if session1 == "null" then
  22.         session1 = math.random(1, 2000)
  23.         session = session1
  24.         session1 = session
  25.     else
  26.         if session2 == "null" then
  27.             session2 = math.random(1, 2000)
  28.             session = session2
  29.             session2 = session
  30.         else
  31.             if session3 == "null" then
  32.                 session3 = math.random(1, 2000)
  33.                 session = session3
  34.                 session3 = session
  35.             else
  36.                 if session4 == "null" then
  37.                     session4 = math.random(1, 2000)
  38.                     session = session4
  39.                     session4 = session
  40.                 else
  41.                     if session5 == "null" then
  42.                         session5 = math.random(1, 2000)
  43.                         session = session5
  44.                         session5 = session
  45.                     else
  46.                         rednet.send(senderiD, "session_error") --Add more sessions your lazy person.
  47.                     end
  48.                 end
  49.             end
  50.         end
  51.     end
  52. end
  53. function isSessionTrue(input)
  54.     if session1 == input then
  55.         rednet.send(connectionID, "session_true")
  56.         print("Allowed connection")
  57.     else
  58.         if session2 == input then
  59.             rednet.send(connectionID, "session_true")
  60.             print("Allowed connection")
  61.         else
  62.             if session3 == input then
  63.                 rednet.send(connectionID, "session_true")
  64.                 print("Allowed connection")
  65.             else
  66.                 if session4 == input then
  67.                     rednet.send(connectionID, "session_true")
  68.                     print("Allowed connection")
  69.                 else
  70.                     if session5 == input then
  71.                         rednet.send(connectionID, "session_true")
  72.                         print("Allowed connection")
  73.                     else
  74.                         rednet.send(connectionID, "session_false")
  75.                         print("Denied connection")
  76.                     end
  77.                 end
  78.             end
  79.         end
  80.     end
  81. end
  82. function activesession(input)
  83.     if session1 == input then
  84.         session1 = "null"
  85.     else
  86.         if session2 == input then
  87.             session2 = "null"
  88.         else
  89.             if session3 == input then
  90.                 session3 = "null"
  91.             else
  92.                 if session4 == input then
  93.                     session4 = "null"
  94.                 else
  95.                     if session5 == input then
  96.                         session5 = "null"
  97.                     else
  98.                         activeSession = "null"
  99.                     end
  100.                 end
  101.             end
  102.         end
  103.     end
  104. end
  105. while running do
  106.     local senderID, message, distance = rednet.receive()
  107.     connectionID = senderID
  108.     print("Incomming message: (", senderID, "): ",message)
  109.     if message == "domain_connect" then
  110.         print(senderID, " Is attempting connection too the server. Awaiting username and password")
  111.         local senderID, message, distance = rednet.receive()
  112.         if message == username then
  113.             print(username, " Has logged in with the id: ", senderID)
  114.             print("Awaiting password...")
  115.             local senderID, message, distance = rednet.receive()
  116.             if message == password then
  117.                 print(username, " with the id: ", senderID, " Has logged in too the server.")
  118.                 rednet.send(senderID, "login")
  119.                 connected = true
  120.                 sleep(0.2)
  121.                 sessionID()
  122.                 rednet.send(senderID, session)
  123.             else
  124.  
  125.                 rednet.send(senderID, "fail_login")
  126.             end
  127.         else
  128.             if message == username2 then
  129.                 print(username2, " Has logged in with the id: ", senderID)
  130.                 print("Awaiting password...")
  131.                 local senderID, message, distance = rednet.receive()
  132.                 if message == password2 then
  133.                     print(username2, " with the id: ", senderID, " Has logged in too the server.")
  134.                     rednet.send(senderID, "login")
  135.  
  136.                     connected = true
  137.                 else
  138.                     rednet.send(senderID, "fail_login")
  139.                 end
  140.             else
  141.                 if message == monitor then
  142.                     print(senderID, " Is claiming to be a montior. Waiting for password.")
  143.                     local senderID, message, distance = rednet.receive()
  144.                     if message == monpass then
  145.                         print(senderID, ": Is a monitor, It's online and waiting. Will send login command.")
  146.                         rednet.send(senderID, "login")
  147.                         rednet.send(senderID, "")
  148.                     else
  149.                         print(senderID, " Failed to provide correct login details and will be ignored.")
  150.                         rednet.send(senderID, "fail_login")
  151.                     end
  152.                 else
  153.                     if message == "cdtserver" then
  154.                         print(senderID, "Is attempting a login as a CDT-Server. Now waiting for password.")
  155.                         local senderID, message, distance = rednet.receive()
  156.                         if message == "cdtauthorization" then
  157.                             print(senderID, ": Is a CDT-Server, It's online and waiting. Will send login command.")
  158.                             rednet.send(senderID, "login")
  159.                             sessionID()
  160.                             rednet.send(senderID, session)
  161.                         else
  162.                             print(senderID, " Failed to provide correct login details and will be ignored.")
  163.                             rednet.send(senderID, "fail_login")
  164.                         end
  165.                     else
  166.                         rednet.send(senderID, "fail_login")
  167.                     end
  168.                 end
  169.             end
  170.         end
  171.     else
  172.         if message == "domain_disconnect" then
  173.             local senderID, message, distance = rednet.receive()
  174.             activesession(message)
  175.             rednet.send(senderID, "disconnected")
  176.             print(username, " (",senderID, ") has dropped out from the server.")
  177.  
  178.             isconnected = false
  179.         elseif message == "kill" then
  180.             print("Server killed by: ",senderID)
  181.             rednet.close("top")
  182.             running = false
  183.         else
  184.             if message == "ping" then
  185.                 rednet.send(connectionID, "pong")
  186.                 print(connectionID, " Requested a network test")
  187.             else
  188.                 if message == "chat" then
  189.                     print("Ponging")
  190.                 else
  191.                     if message == "sendToMon" then
  192.                         print(senderID, ": Starting montior connection.")
  193.                         local senderID, message, distance = rednet.receive()
  194.                         connectionID = senderID
  195.                         isSessionTrue(message)
  196.                         local senderID, message, distance = rednet.receive()
  197.                         monitorconnection = message
  198.                         print(monitorconnection)
  199.                         rednet.send(monitorconnection, "sendTo")
  200.                         print(senderID, "Is asking for ", monitorconnection, "Waiting for message. The server will now hang.")
  201.                         local senderID, message, distance = rednet.receive()
  202.                         rednet.send(monitorconnection, message)
  203.                         print("Monitor connection complete!")
  204.  
  205.                     else
  206.                         if message == "isSessionAlive" then
  207.                             print(sessionID, ": Request ISA-Server")
  208.                             local senderID, message, distance = rednet.receive(10)
  209.                             print(message)
  210.                             connectionID = senderID
  211.                             isSessionTrue(message)
  212.                             print("Finished ")
  213.                         else
  214.                             if message == "poll" then
  215.                                 print(senderID, " Is requsting a poll. Sending back sessions")
  216.                                 connected = 0
  217.                                 if session1 == "null" then
  218.                                 else
  219.                                     connected = connected + 1
  220.                                     print(session1)
  221.                                 end
  222.                                 if session2 == "null" then
  223.                                 else
  224.                                     connected = connected + 1
  225.                                     print(session2)
  226.                                 end
  227.                                 if  session3 == "null" then
  228.                                 else
  229.                                     connected = connected + 1
  230.                                     print(session3)
  231.                                 end
  232.                                 if session4 == "null" then
  233.                                 else
  234.                                     connected = connected + 1
  235.                                     print(session4)
  236.                                 end
  237.                                 if session5 == "null" then
  238.                                 else
  239.                                     connected = connected + 1
  240.                                     print(session5)
  241.                                 end
  242.  
  243.                                 rednet.send(senderID, connected)
  244.                             else
  245.                                 if message == "restart" then
  246.                                     print(senderID, " Wants to restart the server.")
  247.                                     sleep(0.5)
  248.                                     print("Server going down....")
  249.                                     sleep(1)
  250.                                     os.reboot()
  251.                             end
  252.                         end
  253.                     end
  254.                 end
  255.             end
  256.         end
  257.     end
  258. end
  259. end
  260. print("Server offline.")
  261. print("---------------------------------------------------")
Advertisement
Add Comment
Please, Sign In to add comment