This repository has been archived on 2024-04-19. You can view files and clone it, but cannot push or open issues or pull requests.
FREAX/etc/lib/net
2022-07-18 19:33:40 +02:00

70 lines
2.1 KiB
Text

local isOnline = false
function getHTTP(url)
local handlex = http.get(url)
local contents = handlex.readAll()
handlex.close()
return contents
end
function openModems()
for n,sModem in ipairs( peripheral.getNames() ) do
if peripheral.getType( sModem ) == "modem" then
if not rednet.isOpen( sModem ) then
rednet.open( sModem )
end
end
end
end
function closeModems()
for n,sModem in ipairs( peripheral.getNames() ) do
if peripheral.getType( sModem ) == "modem" then
if rednet.isOpen( sModem ) then
rednet.close( sModem )
end
end
end
end
function getModemStatus(side)
kerneldraw.printAppInfo("net", side .. " modem status: " .. tostring(rednet.isOpen(side)))
return rednet.isOpen(side)
end
-- DNS self-hosting functions
function setWorkstationStatus(state)
if state == true and isOnline == false then
local label = os.getComputerLabel() or kernel.getOS()
rednet.host("freax_dns", tostring(os.getComputerID()).."_"..label)
isOnline = true
log.writeSyslog("Now susceptible for DNS lookup")
log.writeMessage("Assigned DNS label "..tostring(os.getComputerID()).."_"..label)
elseif state == false and isOnline == true then
local label = os.getComputerLabel or kernel.getOS()
rednet.host("freax_dns", tostring(os.getComputerID()).."_"..label)
isOnline = false
log.writeSyslog("No longer susceptible for DNS lookup")
log.writeMessage("De-assigned DNS label "..tostring(os.getComputerID()).."_"..label)
elseif state == true and isOnline == true then
kerneldraw.printAppWarning("net", "workstation already online")
elseif state == false and isOnline == false then
kerneldraw.printAppWarning("net", "workstation already offline")
else
log.writeSyslog("RedNet interface error")
return nil, "Error in RNI, please consult developer"
end
end
function getWorkstationStatus()
return isOnline
end
function findWorkstation(query)
if rednet.lookup("freax_dns", query) ~= nil then
return true, rednet.lookup("freax_dns", query)
else
return false, nil
end
end