Attempt to fix the password prompt

This commit is contained in:
2026-01-01 22:47:17 -05:00
parent 955b0b867b
commit 7684cccf13
2 changed files with 114 additions and 41 deletions

View File

@ -16,6 +16,7 @@ local state = {
lastReceivedMessage = nil, lastReceivedMessage = nil,
enteringPassword = false, enteringPassword = false,
remoteHasComputer = false, remoteHasComputer = false,
remotePasswordRequired = false,
destAddress = {}, destAddress = {},
destAddressname = "" destAddressname = ""
} }

View File

@ -25,9 +25,9 @@ local function autoUpdate()
if not (config.autoUpdate and http) then if not (config.autoUpdate and http) then
return false return false
end end
print("Checking for program updates...") print("Checking for program updates...")
local filesToUpdate = { local filesToUpdate = {
"startup.lua", "startup.lua",
"addresses.lua", "addresses.lua",
@ -36,17 +36,17 @@ local function autoUpdate()
"events.lua", "events.lua",
"handlers.lua" "handlers.lua"
} }
local updated = false local updated = false
for _, filename in ipairs(filesToUpdate) do for _, filename in ipairs(filesToUpdate) do
local url = config.repoBaseUrl .. filename local url = config.repoBaseUrl .. filename
local response = http.get(url) local response = http.get(url)
if response then if response then
local newContent = response.readAll() local newContent = response.readAll()
response.close() response.close()
-- Check if file exists and compare content -- Check if file exists and compare content
local needsUpdate = true local needsUpdate = true
if fs.exists(filename) then if fs.exists(filename) then
@ -54,7 +54,7 @@ local function autoUpdate()
if file then if file then
local currentContent = file.readAll() local currentContent = file.readAll()
file.close() file.close()
-- Only update if content is different -- Only update if content is different
if currentContent == newContent then if currentContent == newContent then
needsUpdate = false needsUpdate = false
@ -62,13 +62,13 @@ local function autoUpdate()
end end
end end
end end
if needsUpdate then if needsUpdate then
-- Delete old file if it exists -- Delete old file if it exists
if fs.exists(filename) then if fs.exists(filename) then
fs.delete(filename) fs.delete(filename)
end end
local file = fs.open(filename, "w") local file = fs.open(filename, "w")
if file then if file then
file.write(newContent) file.write(newContent)
@ -83,7 +83,7 @@ local function autoUpdate()
print(" [SKIP] Could not download " .. filename) print(" [SKIP] Could not download " .. filename)
end end
end end
return updated return updated
end end
@ -335,6 +335,10 @@ local function MonitorRemoteIris()
if lastIrisState and lastIrisState > 0 then if lastIrisState and lastIrisState > 0 then
-- Iris just opened -- Iris just opened
utils.log("Remote iris opened - connection safe") utils.log("Remote iris opened - connection safe")
-- Open local iris now that connection is safe
if config.irisEnabled then
utils.openIris()
end
end end
display.showConnected(state.destAddressname, state.destAddress) display.showConnected(state.destAddressname, state.destAddress)
end end
@ -660,27 +664,46 @@ local function handleOutgoingDial()
os.pullEvent("stargate_outgoing_wormhole") os.pullEvent("stargate_outgoing_wormhole")
-- Open local iris for outgoing connection -- Wait briefly for version message and password request from remote gate
if config.irisEnabled then
sleep(2)
utils.openIris()
end
-- Wait briefly for version message from remote gate
state.remoteHasComputer = false state.remoteHasComputer = false
local function WaitForVersion() state.remotePasswordRequired = false
sleep(1) -- Wait up to 1 second for version message local messagesReceived = 0
local maxMessages = 2 -- Version + potential password request
local function WaitForMessages()
while messagesReceived < maxMessages do
sleep(0.1)
end
return -1 return -1
end end
local result = parallel.waitForAny(GetMessage, WaitForVersion) local function CollectMessages()
if result == 1 then -- Wait up to 3 seconds total for messages
local message = state.lastReceivedMessage sleep(3)
state.lastReceivedMessage = nil return -1
if message:sub(1, 6) == "SGCS_V" then end
state.remoteHasComputer = true
local version = message:sub(7) -- Collect messages for up to 3 seconds
utils.log("Remote gate has control system version " .. version) local startTime = os.clock()
while (os.clock() - startTime) < 3 and gate.isStargateConnected() do
local result = parallel.waitForAny(GetMessage, function()
sleep(0.1); return -1
end)
if result == 1 then
local message = state.lastReceivedMessage
state.lastReceivedMessage = nil
if message and message:sub(1, 6) == "SGCS_V" then
state.remoteHasComputer = true
local version = message:sub(7)
utils.log("Remote gate has control system version " .. version)
messagesReceived = messagesReceived + 1
elseif message == "IRIS_PASSWORD_REQUIRED" then
state.remotePasswordRequired = true
utils.log("Remote gate requires password for entry")
messagesReceived = messagesReceived + 1
break -- Got both messages we care about
end
end end
end end
@ -690,6 +713,8 @@ local function handleOutgoingDial()
remoteIrisState = transceiver.checkConnectedShielding() remoteIrisState = transceiver.checkConnectedShielding()
end end
local connectionSafe = false
if remoteIrisState and remoteIrisState > 0 then if remoteIrisState and remoteIrisState > 0 then
-- Remote iris is closed (partially or fully) -- Remote iris is closed (partially or fully)
if remoteIrisState == 100 then if remoteIrisState == 100 then
@ -698,23 +723,70 @@ local function handleOutgoingDial()
utils.log("WARNING: Remote iris is " .. remoteIrisState .. "% closed!") utils.log("WARNING: Remote iris is " .. remoteIrisState .. "% closed!")
end end
mon.setBackgroundColor(colors.red) -- If password is required and remote has computer, show prompt now
mon.clear() if state.remotePasswordRequired and remoteIrisState == 100 then
mon.setTextScale(1) utils.log("Showing password prompt for remote gate")
mon.setCursorPos(6, 5)
mon.write("REMOTE IRIS") local password = HandlePasswordEntry()
mon.setCursorPos(8, 7) utils.sendPasswordAttempt(password)
if remoteIrisState == 100 then
mon.write("CLOSED!") -- Wait for response
else local function WaitForResponse()
mon.write(remoteIrisState .. "% CLOSED") sleep(3) -- Wait up to 3 seconds for response
return nil
end
local result = parallel.waitForAny(GetMessage, WaitForResponse)
if result == 1 then
local response = state.lastReceivedMessage
state.lastReceivedMessage = nil
if response == "IRIS_OPEN" then
display.showPasswordResult(true)
utils.log("Password accepted - iris opened")
sleep(1)
-- Re-check iris state
if transceiver then
remoteIrisState = transceiver.checkConnectedShielding()
end
if not remoteIrisState or remoteIrisState == 0 then
connectionSafe = true
end
elseif response == "IRIS_DENIED" then
display.showPasswordResult(false)
utils.log("Password rejected")
sleep(2)
end
end
end
-- Show warning screen if iris still closed
if not connectionSafe and remoteIrisState and remoteIrisState > 0 then
mon.setBackgroundColor(colors.red)
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(6, 5)
mon.write("REMOTE IRIS")
mon.setCursorPos(8, 7)
if remoteIrisState == 100 then
mon.write("CLOSED!")
else
mon.write(remoteIrisState .. "% CLOSED")
end
mon.setCursorPos(3, 10)
mon.write("Connection unsafe")
display.drawIrisStatus()
display.drawDisconnectButton()
end end
mon.setCursorPos(3, 10)
mon.write("Connection unsafe")
display.drawIrisStatus()
display.drawDisconnectButton()
else else
-- Remote iris is open or no iris present -- Remote iris is open or no iris present
connectionSafe = true
end
-- Only open local iris if connection is safe
if connectionSafe and config.irisEnabled then
utils.openIris()
display.showConnected(state.destAddressname, state.destAddress)
elseif connectionSafe then
display.showConnected(state.destAddressname, state.destAddress) display.showConnected(state.destAddressname, state.destAddress)
end end