computercam

CC_Domain_Server

Feb 29th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.57 KB | None | 0 0
  1. shell.run("clear")
  2. print("---------------------Server------------------------")
  3. print("Initilizing....")
  4. m = peripheral.wrap("right")
  5. rednet.open("top")
  6. function isUser(name)
  7.     print("User Database locating: ", name)
  8.     local file = fs.open("users","r")
  9.     local data = file.readAll()
  10.     file.close()
  11.     users = textutils.unserialize(data)
  12.     for k, v in pairs(users) do
  13.         if v == name then
  14.             print("User Database: Lookup Complete")
  15.             return true
  16.  
  17.         end
  18.     end
  19.     print("User Database: Invaild Lookup")
  20.     return false
  21. end
  22. function getPass(name)
  23.     for k, v in pairs(users) do
  24.         if v == name then
  25.             return users[k + 1]
  26.         end
  27.     end
  28. end
  29.  
  30. print("Starting server...")
  31. local users = fs.open("users.txt", "r")
  32. running = true
  33. print("Server is live.")
  34. while running do
  35.     local senderID, message, distance = rednet.receive()
  36.     connectionID = senderID
  37.     print("Incomming message: (", senderID, "): ",message)
  38.     if message == "domain_connect" then
  39.         print(senderID, " Is attempting connection too the server. Awaiting username and password")
  40.         local senderID, message, distance = rednet.receive()
  41.         tempUser = message
  42.         if isUser(message) == true then
  43.             print(senderID, "Connected a user called: ", message)
  44.             local senderID, message, distance = rednet.receive()
  45.             if message == getPass(tempUser) then
  46.                 print(username2, " with the id: ", senderID, " Has logged in too the server.")
  47.                 rednet.send(senderID, "login")
  48.             else
  49.                 rednet.send(senderID, "fail_login")
  50.             end
  51.         else
  52.             sleep(2)
  53.             rednet.send(senderID, "fail_login")
  54.         end
  55.     else
  56.         if message == "domain_disconnect" then
  57.             rednet.send(senderID, "disconnected")
  58.             print(username, " (",senderID, ") has dropped out from the server.")
  59.  
  60.             isconnected = false
  61.         else
  62.             if message == "kill" then
  63.                 print("Server killed by: ",senderID)
  64.                 rednet.close("top")
  65.                 running = false    
  66.                 print("Power down complete.")
  67.             else
  68.                 if message == "ping" then
  69.                     rednet.send(senderID, "pong")
  70.                     print(connectionID, " Requested a network test")
  71.                 else
  72.                     if message == "chat" then
  73.                         print("Ponging")
  74.                     else
  75.                         if message == "sendToMon" then
  76.                             print(senderID, ": Starting montior connection.")
  77.                             rednet.send(senderID, "Monitor Ready")
  78.                             connectionID = senderID
  79.                             local senderID, message, distance = rednet.receive()
  80.                             monitorconnection = message
  81.                             print(monitorconnection)
  82.                             rednet.send(monitorconnection, "sendTo")
  83.                             print(senderID, "Is asking for ", monitorconnection, "Waiting for message. The server will now hang.")
  84.                             function grabAndHang()
  85.                                 senderID, message, distance = rednet.receive()
  86.                                 if message == "ping" then
  87.                                     print("A user tried to connect while the server was busy. We recommmend you get more servers.")
  88.                                     rednet.send(senderID, "server_busy")
  89.                                     grabAndHang()
  90.                                 end
  91.                             end
  92.                             grabAndHang()
  93.                             rednet.send(monitorconnection, message)
  94.                             print("Monitor connection complete!")
  95.  
  96.                                 else
  97.                                     if message == "restart" then
  98.                                         print(senderID, " Wants to restart the server.")
  99.                                         sleep(0.5)
  100.                                         print("Server going down....")
  101.                                         sleep(1)
  102.                                         os.reboot()
  103.                                     else
  104.                                         if message == "dump-table" then
  105.                                             print("Booty call!")
  106.                                             sleep(4)
  107.                                             rednet.send(senderID, users[2])
  108.                                             sleep(1)
  109.                                             rednet.send(senderID, users[3])
  110.                                         end
  111.                                 end
  112.                             end
  113.                         end
  114.                     end
  115.                 end
  116.             end
  117.         end
  118.         end
  119.  
  120. print("Server offline.")
  121. print("---------------------------------------------------")
Advertisement
Add Comment
Please, Sign In to add comment