local path = "/usr/lib/emerald/" local component = require("component") local computer = require("computer") local fs = require("filesystem") local ser = require("serialization") local term = require("term") local emerald = require("emerald") local modem = component.modem local bPort = 20 -- INIT FUNCTION -- function init() if not fs.exists(path..".eConfig.cfg") then local file = io.open(path..".eConfig.cfg", "w") file:write("{}") file:close() end end -- READ FUNCTION -- function read() local file = io.open(path..".eConfig.cfg", "r") local stream = file:read() file:close() return ser.unserialize(stream) end -- WRITE FUNCTION -- function write(data) local stream = ser.serialize(data) local file = io.open(path..".eConfig.cfg", "w") file:write(stream) file:close() end -- HOSTNAME FUNCTION -- function hostname() term.clear() print("New hostname:") term.write("> ") data["hostname"] = io.read() write(data) end -- GATEWAY FUNCTION -- function gateway() term.clear() print("Searching...") local routerList = emerald.who() term.clear() print("Select the new gateway:\n") for k, v in pairs(routerList) do print(k, v) end term.write("\n> ") gatewayAlias = io.read() if routerList[gatewayAlias] then data["router"] = routerList[gatewayAlias] write(data) else print("Wrong selection.") os.sleep(0.5) end end init() data = read() while true do term.clear() if data["hostname"] then print("HOSTNAME: "..data["hostname"]) else print("HOSTNAME: ") end if data["router"] then print("GATEWAY: "..data["router"]) else print("GATEWAY: ") end print() print([[ 1. Change hostname 2. Change gateway 3. Quit ]]) term.write("> ") choice = io.read() if choice == "1" then hostname() elseif choice == "2" then gateway() elseif choice == "3" then break end end