Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("clear")
- print("---------------------Server------------------------")
- print("Initilizing....")
- m = peripheral.wrap("right")
- rednet.open("top")
- function isUser(name)
- print("User Database locating: ", name)
- local file = fs.open("users","r")
- local data = file.readAll()
- file.close()
- users = textutils.unserialize(data)
- for k, v in pairs(users) do
- if v == name then
- print("User Database: Lookup Complete")
- return true
- end
- end
- print("User Database: Invaild Lookup")
- return false
- end
- function getPass(name)
- for k, v in pairs(users) do
- if v == name then
- return users[k + 1]
- end
- end
- end
- print("Starting server...")
- local users = fs.open("users.txt", "r")
- running = true
- print("Server is live.")
- while running do
- local senderID, message, distance = rednet.receive()
- connectionID = senderID
- print("Incomming message: (", senderID, "): ",message)
- if message == "domain_connect" then
- print(senderID, " Is attempting connection too the server. Awaiting username and password")
- local senderID, message, distance = rednet.receive()
- tempUser = message
- if isUser(message) == true then
- print(senderID, "Connected a user called: ", message)
- local senderID, message, distance = rednet.receive()
- if message == getPass(tempUser) then
- print(username2, " with the id: ", senderID, " Has logged in too the server.")
- rednet.send(senderID, "login")
- else
- rednet.send(senderID, "fail_login")
- end
- else
- sleep(2)
- rednet.send(senderID, "fail_login")
- end
- else
- if message == "domain_disconnect" then
- rednet.send(senderID, "disconnected")
- print(username, " (",senderID, ") has dropped out from the server.")
- isconnected = false
- else
- if message == "kill" then
- print("Server killed by: ",senderID)
- rednet.close("top")
- running = false
- print("Power down complete.")
- else
- if message == "ping" then
- rednet.send(senderID, "pong")
- print(connectionID, " Requested a network test")
- else
- if message == "chat" then
- print("Ponging")
- else
- if message == "sendToMon" then
- print(senderID, ": Starting montior connection.")
- rednet.send(senderID, "Monitor Ready")
- connectionID = senderID
- local senderID, message, distance = rednet.receive()
- monitorconnection = message
- print(monitorconnection)
- rednet.send(monitorconnection, "sendTo")
- print(senderID, "Is asking for ", monitorconnection, "Waiting for message. The server will now hang.")
- function grabAndHang()
- senderID, message, distance = rednet.receive()
- if message == "ping" then
- print("A user tried to connect while the server was busy. We recommmend you get more servers.")
- rednet.send(senderID, "server_busy")
- grabAndHang()
- end
- end
- grabAndHang()
- rednet.send(monitorconnection, message)
- print("Monitor connection complete!")
- else
- if message == "restart" then
- print(senderID, " Wants to restart the server.")
- sleep(0.5)
- print("Server going down....")
- sleep(1)
- os.reboot()
- else
- if message == "dump-table" then
- print("Booty call!")
- sleep(4)
- rednet.send(senderID, users[2])
- sleep(1)
- rednet.send(senderID, users[3])
- end
- end
- end
- end
- end
- end
- end
- end
- end
- print("Server offline.")
- print("---------------------------------------------------")
Advertisement
Add Comment
Please, Sign In to add comment