From d11641693be3de71f3d9e68720be669b9c96f321 Mon Sep 17 00:00:00 2001 From: Moonlit Productions Date: Fri, 2 Jan 2026 00:17:57 -0500 Subject: [PATCH] And it's fixed, but also another problem happened. Lets fix that too --- handlers.lua | 95 +++++++++++++++++++++++++++++++++++----------------- startup.lua | 69 +++++++++++++++++++++----------------- 2 files changed, 104 insertions(+), 60 deletions(-) diff --git a/handlers.lua b/handlers.lua index b9cb28e..1e521c5 100644 --- a/handlers.lua +++ b/handlers.lua @@ -6,7 +6,7 @@ local handlers = {} -- Module references (set by init) -local config, gate, mon, utils, display, events +local config, gate, mon, utils, display, events, transceiver -- State variables local state = { @@ -23,13 +23,14 @@ local state = { lastGDOMatches = false } -function handlers.init(cfg, gateInterface, monitor, utilsModule, displayModule, eventsModule) +function handlers.init(cfg, gateInterface, monitor, utilsModule, displayModule, eventsModule, transceiverPeripheral) config = cfg gate = gateInterface mon = monitor utils = utilsModule display = displayModule events = eventsModule + transceiver = transceiverPeripheral end function handlers.getState() @@ -58,43 +59,77 @@ function handlers.handlePasswordInput() -- Wait for password submission - handle events directly without the event system while state.enteringPassword do - local _, _, x, y = os.pullEvent("monitor_touch") - - -- Check number buttons (1-9) - if y >= 7 and y <= 15 then - local row = math.floor((y - 7) / 3) - local col = math.floor((x - 8) / 5) - - if col >= 0 and col <= 2 and row >= 0 and row <= 2 then - local num = row * 3 + col + 1 - if num >= 1 and num <= 9 then - password = password .. tostring(num) - display.updatePasswordDisplay(password) - end + -- Check if iris has opened (via GDO or other means) + if config.irisEnabled and transceiver then + local remoteIrisState = transceiver.checkConnectedShielding() + if not remoteIrisState or remoteIrisState == 0 then + -- Iris opened! Exit password prompt + utils.log("Remote iris opened, canceling password prompt") + state.enteringPassword = false + return "IRIS_OPENED" end end - -- Check bottom row buttons - if y >= 16 and y <= 18 then - if x >= 8 and x <= 11 then - -- Clear button - password = "" - display.updatePasswordDisplay(password) - elseif x >= 13 and x <= 16 then - -- Zero button - password = password .. "0" - display.updatePasswordDisplay(password) - elseif x >= 18 and x <= 21 then - -- OK button - submit password + -- Wait for event with timeout + local event = { os.pullEvent() } + local eventType = event[1] + + -- Handle GDO events + if eventType == "transceiver_transmission_received" then + -- Pass to GDO handler + handlers.handleGDOTransmission(table.unpack(event)) + -- Continue loop to check iris state + elseif eventType == "stargate_message_received" then + -- Pass to message handler + handlers.handleMessage(table.unpack(event)) + -- Check if iris opened + if state.lastReceivedMessage == "IRIS_OPEN" then + state.lastReceivedMessage = nil state.enteringPassword = false + return "IRIS_OPENED" + end + elseif eventType == "monitor_touch" then + local x, y = event[3], event[4] + + -- Check number buttons (1-9) + if y >= 7 and y <= 15 then + local row = math.floor((y - 7) / 3) + local col = math.floor((x - 8) / 5) + + if col >= 0 and col <= 2 and row >= 0 and row <= 2 then + local num = row * 3 + col + 1 + if num >= 1 and num <= 9 then + password = password .. tostring(num) + display.updatePasswordDisplay(password) + end + end + end + + -- Check bottom row buttons + if y >= 16 and y <= 18 then + if x >= 8 and x <= 11 then + -- Clear button + password = "" + display.updatePasswordDisplay(password) + elseif x >= 13 and x <= 16 then + -- Zero button + password = password .. "0" + display.updatePasswordDisplay(password) + elseif x >= 18 and x <= 21 then + -- OK button - submit password + state.enteringPassword = false + end end end end - -- Send password attempt - utils.sendPasswordAttempt(password) + -- If we got here with a password, send it + if password ~= "" then + utils.sendPasswordAttempt(password) + return password + end - return password + return nil end --------------------------------------------- diff --git a/startup.lua b/startup.lua index 00e686e..e6248cf 100644 --- a/startup.lua +++ b/startup.lua @@ -146,7 +146,7 @@ end -- Initialize modules utils.init(config, gate, chatBox) display.init(mon, config, addresses, utils, localGateAddress) -handlers.init(config, gate, mon, utils, display, events) +handlers.init(config, gate, mon, utils, display, events, transceiver) -- Configure transceiver IDC after utils is initialized (so we can use utils.log) if transceiver and config.enableGDO and config.irisPassword then @@ -591,14 +591,14 @@ local function dialGate(address) if (symbol) ~= 0 then if (gateType == "sgjourney:universe_stargate") or (gateType == "sgjourney:pegasus_stargate") then - os.pullEvent("stargate_chevron_engaged") + events.pullEvent("stargate_chevron_engaged") end else if gateType == "sgjourney:universe_stargate" then - os.pullEvent("stargate_chevron_engaged") + events.pullEvent("stargate_chevron_engaged") redstone.setOutput("top", true) elseif (gateType == "sgjourney:pegasus_stargate") then - os.pullEvent("stargate_chevron_engaged") + events.pullEvent("stargate_chevron_engaged") end end end @@ -798,35 +798,44 @@ local function handleOutgoingDial() if state.remotePasswordRequired and remoteIrisState == 100 then utils.log("Showing password prompt for remote gate") - local password = HandlePasswordEntry() - utils.sendPasswordAttempt(password) - utils.debug("Sent: IRIS_PASSWORD:" .. password) + local result = HandlePasswordEntry() - -- Wait for response - local function WaitForResponse() - sleep(3) -- Wait up to 3 seconds for response - return nil + -- Check if iris opened during password entry (via GDO) + if result == "IRIS_OPENED" then + utils.log("Iris opened during password entry") + connectionSafe = true + elseif result then + -- Password was entered, send it + utils.debug("Sent: IRIS_PASSWORD:" .. result) + + -- Wait for response + local function WaitForResponse() + sleep(3) -- Wait up to 3 seconds for response + return nil + end + + local waitResult = parallel.waitForAny(GetMessage, WaitForResponse) + if waitResult == 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) + connectionSafe = true + elseif response == "IRIS_DENIED" then + display.showPasswordResult(false) + utils.log("Password rejected") + sleep(2) + end + end 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) + -- Re-check iris state + if transceiver then + remoteIrisState = transceiver.checkConnectedShielding() + if not remoteIrisState or remoteIrisState == 0 then + connectionSafe = true end end end