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

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