Add auto-updating address list

This commit is contained in:
2026-01-01 21:40:37 -05:00
parent fed51c6b07
commit a7157fe95d
3 changed files with 94 additions and 21 deletions

View File

@ -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://raw.githubusercontent.com/yourusername/StargateControl/main/addresses.lua"
return config

View File

@ -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,29 +69,49 @@ end
function display.screenWrite(list, fcount, fy)
for i = 1, #list do
local x1, x2 = 0, 0
local entryAddress = list[i][2]
if fcount == 0 then
x = 2
fcount = 1
elseif fcount == 1 then
x = 11
fcount = 2
else
x = 20
fcount = 0
fy = fy + 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
mon.setCursorPos(x, fy)
mon.write(list[i][1])
-- Skip if this is the local gate
if not isLocalGate then
local x1, x2 = 0, 0
x1 = x
x2 = x + 7
if fcount == 0 then
x = 2
fcount = 1
elseif fcount == 1 then
x = 11
fcount = 2
else
x = 20
fcount = 0
fy = fy + 2
end
table.insert(buttonXY, { x1, x2, fy })
table.insert(computerNames, list[i][1])
table.insert(computerAddresses, list[i][2])
mon.setCursorPos(x, fy)
mon.write(list[i][1])
x1 = x
x2 = x + 7
table.insert(buttonXY, { x1, x2, fy })
table.insert(computerNames, list[i][1])
table.insert(computerAddresses, list[i][2])
end
end
local oldterm = term.redirect(mon)

View File

@ -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