Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local c = require("component")
- local term = require("term")
- local fs = require("filesystem")
- local shell = require("shell")
- local event = require("event")
- local s = require("serialization")
- local text = require("text")
- local m
- local gpu
- local logged = false
- local port = 121
- term.clear()
- if not c.isAvailable("gpu") then
- c.computer.beep(1500,2)
- os.exit()
- else
- gpu = c.gpu
- end
- if c.isAvailable("modem") then
- if c.isAvailable("tunnel") then
- print("Linked card and wireless card discovered! Use Linked[1] or Wireless[2]?")
- local valid = false
- while not valid do
- local choice = io.read()
- if choice == "1" then
- print("Linked card selected for network")
- m = c.tunnel
- valid = true
- mode = "tunnel"
- elseif choice == "2" then
- print("Wireless card selected for network")
- m = c.modem
- m.open(port)
- mode = "wireless"
- valid = true
- else
- print("Invalid input. please enter [1] or [2].")
- end
- end
- else
- m = c.modem
- mode = "wireless"
- m.open(port)
- print("Wireless card selected for network")
- end
- elseif c.isAvailable("tunnel") then
- m = c.tunnel
- mode = "tunnel"
- print("Linked card selected for network")
- end
- function ping(time)
- if mode == "wireless" then
- print("sending wireless request")
- m.broadcast(port, s.serialize({"ping"}))
- elseif mode == "tunnel" then
- print("Sending linked request")
- m.send(s.serialize({"ping"}))
- end
- local Type, _, _, _, _, message = event.pull(10,"modem_message")
- if not Type then
- print("No response from server, check server is online and you are in range")
- os.exit()
- elseif message == "pong" then
- print("Response recieved!")
- end
- end
- function login(time, user)
- if mode == "wireless" then
- m.broadcast(port, s.serialize(user))
- elseif mode == "tunnel" then
- m.send(s.serialize(user))
- end
- local Type, _, _, _, _, message = event.pull(10,"modem_message")
- if not Type then
- print("\nRequest timed out.")
- os.exit()
- elseif message == "valid" then
- print("\nCredentials valid!")
- logged = true
- elseif message == "invalid" then
- print("\nCredentials invalid!")
- end
- end
- gpu.setForeground(0xFF00FF)
- print("Attempting to contact authorisation servers.")
- ping(10)
- gpu.setForeground(0x00FF00)
- while not logged do
- print("Enter username: ")
- local x, y = term.getCursor()
- term.setCursor(17, y-1)
- local username = io.read()
- print("\nEnter Password: ")
- local x, y = term.getCursor()
- term.setCursor(17, y-1)
- local password = text.trim(term.read(nil, false, nil, "*"))
- local user = {username, password}
- login(5, user)
- end
- while true do
- while logged do
- gpu.setForeground(0xFF0000)
- local wd = shell.getWorkingDirectory()
- print(wd.." # ")
- gpu.setForeground(0xFFFFFF)
- local x, y = term.getCursor()
- term.setCursor(string.len(wd)+4, y-1)
- local input = io.read()
- os.execute(input)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement