Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("right")
- print("DNS server started")
- local dnsTable = {}
- local function registerComputer(name, id)
- dnsTable[name] = id
- print("Registation successful")
- print("PC: " .. name .. " ID: " .. id)
- end
- local function isNameRegistered(name)
- return dnsTable[name] ~= nil
- end
- local function getComputerID(name)
- return dnsTable[name]
- end
- local function getAllComputers()
- return dnsTable
- end
- while true do
- local senderID, message, protocol = rednet.receive()
- local data = textutils.unserialise(message)
- if protocol == "dns_register" then
- if data and data.name and data.id then
- registerComputer(data.name, data.id)
- rednet.send(senderID, "Registation has been successful", "dns_ack")
- else
- rednet.send(SenderID, "Registration fail", "dns_ack")
- end
- elseif protocol == "dns_list" then
- local allComputers = getAllComputers()
- local listMessage = textutils.serialize(allComputers)
- rednet.send(senderID, listMessage, "dns_list_response")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement