Add auto-updating address list
This commit is contained in:
@ -68,4 +68,12 @@ config.blacklist = {
|
||||
config.enableLogging = true
|
||||
config.logFile = "stargate.log"
|
||||
|
||||
---------------------------------------------
|
||||
-- AUTO-UPDATE
|
||||
---------------------------------------------
|
||||
|
||||
-- Auto-update addresses file from git repository
|
||||
config.autoUpdateAddresses = true
|
||||
config.addressesRepoUrl = "https://git.munebase.dev/Munelit/StargateControl/raw/branch/master/addresses.lua"
|
||||
|
||||
return config
|
||||
|
||||
24
display.lua
24
display.lua
@ -10,6 +10,7 @@ local mon
|
||||
local config
|
||||
local addresses
|
||||
local utils
|
||||
local localGateAddress
|
||||
|
||||
-- State variables
|
||||
local buttonXY = {}
|
||||
@ -17,11 +18,12 @@ local computerAddresses = {}
|
||||
local computerNames = {}
|
||||
local x, y = 0, 0
|
||||
|
||||
function display.init(monitor, cfg, addr, utilsModule)
|
||||
function display.init(monitor, cfg, addr, utilsModule, localAddr)
|
||||
mon = monitor
|
||||
config = cfg
|
||||
addresses = addr
|
||||
utils = utilsModule
|
||||
localGateAddress = localAddr
|
||||
end
|
||||
|
||||
function display.getButtonData()
|
||||
@ -67,6 +69,25 @@ end
|
||||
|
||||
function display.screenWrite(list, fcount, fy)
|
||||
for i = 1, #list do
|
||||
local entryAddress = list[i][2]
|
||||
|
||||
-- Skip this entry if it matches local gate address
|
||||
local isLocalGate = false
|
||||
if localGateAddress and entryAddress then
|
||||
-- Compare addresses (excluding point of origin which is last element)
|
||||
if #localGateAddress == #entryAddress then
|
||||
isLocalGate = true
|
||||
for j = 1, #localGateAddress - 1 do -- Skip last element (point of origin)
|
||||
if localGateAddress[j] ~= entryAddress[j] then
|
||||
isLocalGate = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Skip if this is the local gate
|
||||
if not isLocalGate then
|
||||
local x1, x2 = 0, 0
|
||||
|
||||
if fcount == 0 then
|
||||
@ -91,6 +112,7 @@ function display.screenWrite(list, fcount, fy)
|
||||
table.insert(computerNames, list[i][1])
|
||||
table.insert(computerAddresses, list[i][2])
|
||||
end
|
||||
end
|
||||
|
||||
local oldterm = term.redirect(mon)
|
||||
paintutils.drawFilledBox(23, 17, 28, 19, colors.red)
|
||||
|
||||
45
startup.lua
45
startup.lua
@ -16,6 +16,40 @@
|
||||
---------------------------------------------
|
||||
|
||||
local config = require("config")
|
||||
|
||||
-- Auto-update addresses file if enabled
|
||||
local function updateAddressesFile()
|
||||
if config.autoUpdateAddresses and http then
|
||||
print("Checking for addresses file update...")
|
||||
local response = http.get(config.addressesRepoUrl)
|
||||
if response then
|
||||
local content = response.readAll()
|
||||
response.close()
|
||||
|
||||
local file = fs.open("addresses.lua", "w")
|
||||
if file then
|
||||
file.write(content)
|
||||
file.close()
|
||||
print("Addresses file updated successfully")
|
||||
return true
|
||||
else
|
||||
print("Failed to write addresses file")
|
||||
end
|
||||
else
|
||||
print("Failed to download addresses file - using local version")
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Try to update addresses file
|
||||
local addressesUpdated = updateAddressesFile()
|
||||
|
||||
-- Reload addresses module if updated
|
||||
if addressesUpdated then
|
||||
package.loaded["addresses"] = nil
|
||||
end
|
||||
|
||||
local addresses = require("addresses")
|
||||
local utils = require("utils")
|
||||
local display = require("display")
|
||||
@ -51,9 +85,17 @@ if gate.getIris() == nil then
|
||||
config.irisEnabled = false
|
||||
end
|
||||
|
||||
-- Get local gate address
|
||||
local localGateAddress = gate.getLocalAddress()
|
||||
if localGateAddress then
|
||||
print("Local gate address: " .. gate.addressToString(localGateAddress))
|
||||
else
|
||||
print("WARNING: Could not read local gate address")
|
||||
end
|
||||
|
||||
-- Initialize modules
|
||||
utils.init(config, gate)
|
||||
display.init(mon, config, addresses, utils)
|
||||
display.init(mon, config, addresses, utils, localGateAddress)
|
||||
handlers.init(config, gate, mon, utils, display, events)
|
||||
|
||||
-- Ensure gate starts disconnected
|
||||
@ -572,6 +614,7 @@ local function handleOutgoingDial()
|
||||
|
||||
-- Open local iris for outgoing connection
|
||||
if config.irisEnabled then
|
||||
sleep(2)
|
||||
utils.openIris()
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user