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")
- username = "Cameron"
- password = "test"
- username2 = "Account2"
- password2 = "test2"
- monitor = "monitor"
- monpass = "password-monitor-password"
- session1 = "null"
- session2 = "null"
- session3 = "null"
- session4 = "null"
- session5 = "null"
- print("Starting server...")
- running = true
- print("Server is live.")
- function sessionID()
- if session1 == "null" then
- session1 = math.random(1, 2000)
- session = session1
- session1 = session
- else
- if session2 == "null" then
- session2 = math.random(1, 2000)
- session = session2
- session2 = session
- else
- if session3 == "null" then
- session3 = math.random(1, 2000)
- session = session3
- session3 = session
- else
- if session4 == "null" then
- session4 = math.random(1, 2000)
- session = session4
- session4 = session
- else
- if session5 == "null" then
- session5 = math.random(1, 2000)
- session = session5
- session5 = session
- else
- rednet.send(senderiD, "session_error") --Add more sessions your lazy person.
- end
- end
- end
- end
- end
- end
- function isSessionTrue(input)
- if session1 == input then
- rednet.send(connectionID, "session_true")
- print("Allowed connection")
- else
- if session2 == input then
- rednet.send(connectionID, "session_true")
- print("Allowed connection")
- else
- if session3 == input then
- rednet.send(connectionID, "session_true")
- print("Allowed connection")
- else
- if session4 == input then
- rednet.send(connectionID, "session_true")
- print("Allowed connection")
- else
- if session5 == input then
- rednet.send(connectionID, "session_true")
- print("Allowed connection")
- else
- rednet.send(connectionID, "session_false")
- print("Denied connection")
- end
- end
- end
- end
- end
- end
- function activesession(input)
- if session1 == input then
- session1 = "null"
- else
- if session2 == input then
- session2 = "null"
- else
- if session3 == input then
- session3 = "null"
- else
- if session4 == input then
- session4 = "null"
- else
- if session5 == input then
- session5 = "null"
- else
- activeSession = "null"
- end
- end
- end
- end
- end
- end
- 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()
- if message == username then
- print(username, " Has logged in with the id: ", senderID)
- print("Awaiting password...")
- local senderID, message, distance = rednet.receive()
- if message == password then
- print(username, " with the id: ", senderID, " Has logged in too the server.")
- rednet.send(senderID, "login")
- connected = true
- sleep(0.2)
- sessionID()
- rednet.send(senderID, session)
- else
- rednet.send(senderID, "fail_login")
- end
- else
- if message == username2 then
- print(username2, " Has logged in with the id: ", senderID)
- print("Awaiting password...")
- local senderID, message, distance = rednet.receive()
- if message == password2 then
- print(username2, " with the id: ", senderID, " Has logged in too the server.")
- rednet.send(senderID, "login")
- connected = true
- else
- rednet.send(senderID, "fail_login")
- end
- else
- if message == monitor then
- print(senderID, " Is claiming to be a montior. Waiting for password.")
- local senderID, message, distance = rednet.receive()
- if message == monpass then
- print(senderID, ": Is a monitor, It's online and waiting. Will send login command.")
- rednet.send(senderID, "login")
- rednet.send(senderID, "")
- else
- print(senderID, " Failed to provide correct login details and will be ignored.")
- rednet.send(senderID, "fail_login")
- end
- else
- if message == "cdtserver" then
- print(senderID, "Is attempting a login as a CDT-Server. Now waiting for password.")
- local senderID, message, distance = rednet.receive()
- if message == "cdtauthorization" then
- print(senderID, ": Is a CDT-Server, It's online and waiting. Will send login command.")
- rednet.send(senderID, "login")
- sessionID()
- rednet.send(senderID, session)
- else
- print(senderID, " Failed to provide correct login details and will be ignored.")
- rednet.send(senderID, "fail_login")
- end
- else
- rednet.send(senderID, "fail_login")
- end
- end
- end
- end
- else
- if message == "domain_disconnect" then
- local senderID, message, distance = rednet.receive()
- activesession(message)
- rednet.send(senderID, "disconnected")
- print(username, " (",senderID, ") has dropped out from the server.")
- isconnected = false
- elseif message == "kill" then
- print("Server killed by: ",senderID)
- rednet.close("top")
- running = false
- else
- if message == "ping" then
- rednet.send(connectionID, "pong")
- print(connectionID, " Requested a network test")
- else
- if message == "chat" then
- print("Ponging")
- else
- if message == "sendToMon" then
- print(senderID, ": Starting montior connection.")
- local senderID, message, distance = rednet.receive()
- connectionID = senderID
- isSessionTrue(message)
- 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.")
- local senderID, message, distance = rednet.receive()
- rednet.send(monitorconnection, message)
- print("Monitor connection complete!")
- else
- if message == "isSessionAlive" then
- print(sessionID, ": Request ISA-Server")
- local senderID, message, distance = rednet.receive(10)
- print(message)
- connectionID = senderID
- isSessionTrue(message)
- print("Finished ")
- else
- if message == "poll" then
- print(senderID, " Is requsting a poll. Sending back sessions")
- connected = 0
- if session1 == "null" then
- else
- connected = connected + 1
- print(session1)
- end
- if session2 == "null" then
- else
- connected = connected + 1
- print(session2)
- end
- if session3 == "null" then
- else
- connected = connected + 1
- print(session3)
- end
- if session4 == "null" then
- else
- connected = connected + 1
- print(session4)
- end
- if session5 == "null" then
- else
- connected = connected + 1
- print(session5)
- end
- rednet.send(senderID, connected)
- else
- if message == "restart" then
- print(senderID, " Wants to restart the server.")
- sleep(0.5)
- print("Server going down....")
- sleep(1)
- os.reboot()
- end
- end
- end
- end
- end
- end
- end
- end
- end
- print("Server offline.")
- print("---------------------------------------------------")
Advertisement
Add Comment
Please, Sign In to add comment