Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --DevelopedLogic's Network Management Server (NMS)
- --This is the equivalent of a real DNS server, however may become much more
- os.loadAPI("/dniconf")
- modemSide = dniconf.modemSide
- DNIPort = dniconf.DNIPort
- networkName = dniconf.networkName
- modem = peripheral.wrap(modemSide)
- if modem.isWireless() then
- error("YOU MAY NOT USE NMS ON A WIRELESS NETWORK AS TOO MANY MODEM MESSAGES PASS BY!")
- end
- if not fs.exists("/domains") then
- fs.makeDir("/domains")
- print("Created domain directory")
- end
- if not fs.exists("/ids") then
- fs.makeDir("/ids")
- print("Created id directory")
- end
- termW, termH = term.getSize()
- term.setPaletteColor(colours.blue, 0, 0, 1)
- term.clear()
- term.setCursorPos(1,1)
- topBar = window.create(term.current(), 1, 1, termW, 1, true)
- bottomBar = window.create(term.current(), 1, termH, termW, 1, true)
- centre = window.create(term.current(), 1, 2, termW, termH-2, true)
- topBar.setBackgroundColour(colours.lightGrey)
- topBar.setTextColour(colours.blue)
- topBar.clear()
- bottomBar.setTextColour(colours.blue)
- bottomBar.setBackgroundColour(colours.lightGrey)
- bottomBar.clear()
- centre.setTextColour(colours.lightGrey)
- centre.setBackgroundColour(colours.blue)
- centre.clear()
- topBar.setCursorPos(1,1)
- topBar.write("Network Management Server - "..networkName)
- bottomBar.setCursorPos(1,1)
- bottomBar.write("Run nmsconfig to manage domains")
- term.redirect(centre)
- modem.open(DNIPort)
- function stok(data)
- if type(data) == "string" then
- return true
- else
- return false
- end
- end
- function numok(data)
- if type(data) == "number" then
- return true
- else
- return false
- end
- end
- function fail(gotoid)
- print("Fail from "..gotoid)
- print()
- data = {gotoid, "failed"}
- modem.transmit(DNIPort, DNIPort, textutils.serialise(data))
- end
- function pass(val, gotoid)
- print("Pass from "..gotoid)
- print()
- data = {gotoid, val}
- modem.transmit(DNIPort, DNIPort, textutils.serialise(data))
- end
- function getdomain(id, goto)
- print(goto.." Requested "..id)
- if not fs.exists("/domains/"..id) then
- fail(goto)
- else
- file = fs.open("/domains/"..id, "r")
- pass(file.readLine(), goto)
- file.close()
- end
- end
- function getid(domain, goto)
- print(goto.." Requested "..domain)
- if not fs.exists("/ids/"..domain) then
- fail(goto)
- else
- file = fs.open("/ids/"..domain, "r")
- pass(file.readLine(), goto)
- file.close()
- end
- end
- function run(msg)
- data = textutils.unserialise(msg)
- if data ~= nil and #data == 4 and stok(data[1]) and stok(data[2]) and stok(data[3]) and numok(data[4]) and data[1] == "nmsreq" then
- if data[2] == "domain" then
- getdomain(data[3], data[4])
- elseif data[2] == "id" then
- getid(data[3], data[4])
- end
- end
- end
- while true do
- message = { os.pullEvent("modem_message") }
- run(message[5])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement