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

@ -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()
-- 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 if result == 1 then
local message = state.lastReceivedMessage local message = state.lastReceivedMessage
state.lastReceivedMessage = nil state.lastReceivedMessage = nil
if message:sub(1, 6) == "SGCS_V" then
if message and message:sub(1, 6) == "SGCS_V" then
state.remoteHasComputer = true state.remoteHasComputer = true
local version = message:sub(7) local version = message:sub(7)
utils.log("Remote gate has control system version " .. version) 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,6 +723,44 @@ local function handleOutgoingDial()
utils.log("WARNING: Remote iris is " .. remoteIrisState .. "% closed!") utils.log("WARNING: Remote iris is " .. remoteIrisState .. "% closed!")
end end
-- 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.setBackgroundColor(colors.red)
mon.clear() mon.clear()
mon.setTextScale(1) mon.setTextScale(1)
@ -713,8 +776,17 @@ local function handleOutgoingDial()
mon.write("Connection unsafe") mon.write("Connection unsafe")
display.drawIrisStatus() display.drawIrisStatus()
display.drawDisconnectButton() display.drawDisconnectButton()
end
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