tg_server_name = "tg_server" local args = {...} local function split(str, divider) local t = {} for part in string.gmatch(str, "([^" .. divider .. "]+)") do table.insert(t, part) end return t end local function establish_connection() local peripherals = peripheral.getNames() for _, side in ipairs(peripherals) do if peripheral.getType(side) == "modem" then rednet.open(side) print("Opened modem: "..side) return true end end print("No modem found!") return false end function validate_clearance(computer_id, clearance_level) if establish_connection() then tg_server_id = rednet.lookup("tg", tg_server_name) rednet.send(tg_server_id, "validate_clearance,"..computer_id..","..clearance_level) local id, msg, proto = rednet.receive("tg") if msg == "granted" then return true else return false, "authentication failed" end else return false, "modem not found" end end function validate_key(minimum_clearance) if establish_connection() then if fs.exists("/disk/key") then key_file = fs.open("/disk/key","r") key = key_file.readLine() tg_server_id = rednet.lookup('tg', tg_server_name) rednet.send(tg_server_id, "validate_key,"..key..","..minimum_clearance, "tg") id, msg, _ = rednet.receive("tg") if msg == "authentication successful" then return true else return false, "authentication error: "..msg end else return false, "key file not found" end else return false, "modem not found" end end if fs.exists('/disk/key') then key_file = fs.open('/disk/key', 'r') key = key_file.readLine() if establish_connection() then tg_server_id = rednet.lookup("tg", tg_server_name) rednet.send(tg_server_id, "authenticate,"..key,"tg") local id, msg, proto = rednet.receive("tg") if msg == "authentication successful" then key_parts = split(key,',') local card_holder = key_parts[1] local card_clearance = key_parts[2] print("Authentication was successful.") print("Hello "..card_holder..", you were granted clearance level "..card_clearance.." for this computer.") else print("Authentication failed.") end else return false, "modem not found" end key_file.close() else print("Key file not found. Aborting.") end