Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = peripheral.wrap("top")
- rednet.open("top")
- serverID = 0
- session = nul
- cdtServer = 2
- os.loadAPI("APIs/server")
- function getSession()
- local senderID, message, distance = rednet.receive()
- session = message
- end
- function checkSession()
- rednet.send(serverID, "isSessionAlive")
- rednet.send(serverID, session)
- local senderID, message, distance = rednet.receive()
- sessionAlive = message
- end
- --END FUNCTIONS
- server.TestConnection("true")
- shell.run("clear")
- write("Username: ")
- connectionName = io.read()
- write("Password: ")
- connectionPassword = io.read()
- shell.run("clear")
- print("Logging in.")
- server.connect(connectionName, connectionPassword)
- print("Hey, ", connectionName)
- local senderID, message, distance = rednet.receive()
- if message == "login" then
- print("Waiting for session...")
- getSession() --Gets session from server. If this comes back correct the rest of this is client code.
- function running()
- write("Command: ")
- command = io.read()
- if command == "kill-server" then
- write("Are you sure you want to kill the server?: [y/n] ")
- answer = io.read()
- if answer == "y" then
- print("Sending command.")
- rednet.send(serverID, "kill")
- print("Server should be offline. this session ID will be revoked.")
- session = null
- end
- else
- if command == "chat" then
- print("Let's go...")
- shell.run("domain-chat")
- else
- if command == "msgb" then
- rednet.send(serverID, "sendToMon")
- rednet.send(serverID, session)
- local senderID, message, distance = rednet.receive()
- if message == "session_true" then
- write("Display ID: ")
- displayID = tonumber(io.read())
- rednet.send(serverID, displayID)
- write("Message: ")
- local msg = io.read()
- print("Sending")
- rednet.send(serverID, msg)
- running()
- else
- print("Session invalid... Disconnecting and trying again")
- running()
- end
- else
- if command == "check" then
- server.TestConnection(false)
- print("Requesting Session...")
- checkSession()
- print(sessionAlive)
- running()
- else
- if command == "cdt" then
- rednet.send(cdtServer, "deployment-server")
- local senderID, message, distance = rednet.receive(5)
- if message == "cdt-session" then
- print("SessionID: ", session)
- rednet.send(cdtServer, session)
- print("Waiting for domain controller...")
- local senderID, message, distance = rednet.receive(5)
- if message == "cdt-start" then
- print("Starting CDT service.... (This takes a while.)")
- sleep(2)
- local senderID, message, distance = rednet.receive(5)
- loop = message
- loops = 0
- while loops < loop do
- loops = loops + 1
- local senderID, message, distance = rednet.receive(5)
- print("1. ", message)
- end
- write("Image to run: ")
- option = read()
- rednet.send(cdtServer, option)
- local senderID, message, distance = rednet.receive(20)
- if message == "start file install" then
- shell.run("clear")
- print("CDT SERVICE IS PREPEARING....")
- loops = 0
- loop = 10
- while loops < loop do
- loops = loops + 1
- write(".")
- sleep(0.2)
- end
- local senderID, message, distance = rednet.receive(20)
- loops = 0
- loop = message
- while loops < loop do
- local senderID, message, distance = rednet.receive(10)
- shell.run(message)
- end
- end
- end
- else
- print("The server didn't accept the request.")
- running()
- end
- else
- server.disconnect(session)
- end
- end
- end
- end
- end
- end
- running()
- else
- print("Sorry, The server returned: ",message, " Sounds like something is wrong, maybe incorrect username or password?")
- end
Advertisement
Add Comment
Please, Sign In to add comment