From 82ee133d5f015092549d73d2fb442b9fb6910bc3 Mon Sep 17 00:00:00 2001 From: Moonlit Productions Date: Thu, 1 Jan 2026 23:29:19 -0500 Subject: [PATCH] Added GDO support and chatbox debugging --- addresses.lua | 2 +- config.lua | 12 ++++++++++++ handlers.lua | 24 ++++++++++++++++++++++-- startup.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 83 insertions(+), 7 deletions(-) diff --git a/addresses.lua b/addresses.lua index 05e7cc5..0d70313 100644 --- a/addresses.lua +++ b/addresses.lua @@ -30,7 +30,7 @@ addresses.MainGates = { addresses.playerGates = { { "Glaive", { 33, 6, 10, 24, 1, 30, 3, 17, 0 } }, { "Moon", { 32, 33, 8, 7, 25, 21, 14, 35, 0 } }, - { "Caldoric", { 18, 2, 24, 16, 8, 19, 4, 29, 0 } }, + --{ "Caldoric", { 18, 2, 24, 16, 8, 19, 4, 29, 0 } }, { "Trading Hall", { 16, 19, 6, 18, 35, 27, 9, 8, 0 } }, { "Darkmoon", { 29, 10, 3, 35, 11, 14, 16, 17, 0 } } } diff --git a/config.lua b/config.lua index 5944a91..2b1a28d 100644 --- a/config.lua +++ b/config.lua @@ -31,8 +31,20 @@ config.irisCloseDelay = 0.1 -- seconds before closing iris on incoming config.irisClosedByDefault = false -- Iris password (set to nil to disable remote password unlock) +-- Also used as GDO IDC code when GDO support is enabled config.irisPassword = "1234" +-- GDO (Garage Door Opener) support +config.enableGDO = true + +--------------------------------------------- +-- DEBUGGING +--------------------------------------------- + +-- Enable chatbox message debugging (sends messages to specified player) +config.enableChatboxDebug = false +config.chatboxDebugPlayer = "MoonlitJolty" + --------------------------------------------- -- MESSAGING --------------------------------------------- diff --git a/handlers.lua b/handlers.lua index 4977d6d..02399bd 100644 --- a/handlers.lua +++ b/handlers.lua @@ -18,7 +18,9 @@ local state = { remoteHasComputer = false, remotePasswordRequired = false, destAddress = {}, - destAddressname = "" + destAddressname = "", + lastGDOCode = nil, + lastGDOMatches = false } function handlers.init(cfg, gateInterface, monitor, utilsModule, displayModule, eventsModule) @@ -167,7 +169,25 @@ end function handlers.handleMessage(eventType, side, message) state.lastReceivedMessage = message - return "message" + return "message_received" +end + +--------------------------------------------- +-- GDO TRANSMISSION HANDLER +--------------------------------------------- + +function handlers.handleGDOTransmission(eventType, side, frequency, idc, matches) + state.lastGDOCode = idc + state.lastGDOMatches = matches + utils.log("GDO transmission received: IDC=" .. tostring(idc) .. ", matches=" .. tostring(matches)) + + -- If matches configured IDC and gate is connected, open iris + if matches and gate.isStargateConnected() and config.irisEnabled then + utils.log("Valid GDO code received - opening iris") + utils.openIris() + end + + return "gdo_received" end --------------------------------------------- diff --git a/startup.lua b/startup.lua index 5b95c7b..0fb027b 100644 --- a/startup.lua +++ b/startup.lua @@ -110,6 +110,7 @@ local gate = peripheral.find("advanced_crystal_interface") or peripheral.find("crystal_interface") or peripheral.find("basic_interface") local transceiver = peripheral.find("transceiver") +local chatBox = peripheral.find("chatBox") if gate == nil then error("Stargate interface not found! Please connect an interface.") @@ -120,7 +121,23 @@ if mon == nil then end if transceiver == nil then - print("WARNING: No transceiver found. Remote iris detection disabled.") + print("WARNING: No transceiver found. Remote iris detection and GDO support disabled.") +else + -- Configure transceiver IDC to match iris password (if GDO enabled) + if config.enableGDO and config.irisPassword then + local idcCode = tonumber(config.irisPassword) + if idcCode then + transceiver.setIDC(idcCode) + utils.log("Transceiver IDC configured to: " .. idcCode) + else + print("WARNING: irisPassword must be a number for GDO support") + end + end +end + +if chatBox == nil and config.enableChatboxDebug then + print("WARNING: No chatbox found. Debug messages disabled.") + config.enableChatboxDebug = false end -- Check iris availability @@ -142,6 +159,13 @@ utils.init(config, gate) display.init(mon, config, addresses, utils, localGateAddress) handlers.init(config, gate, mon, utils, display, events) +-- Helper function for chatbox debugging +local function debugChat(message) + if config.enableChatboxDebug and chatBox then + chatBox.sendMessageToPlayer("[SGC] " .. message, config.chatboxDebugPlayer) + end +end + -- Ensure gate starts disconnected gate.disconnectStargate() @@ -224,6 +248,11 @@ local function GetMessage() return 1 end +local function GetGDOTransmission() + local result = events.pullEvent("transceiver_transmission_received") + return 2 +end + local function HandlePasswordEntry() return handlers.handlePasswordInput() end @@ -234,10 +263,12 @@ local function HandleIncomingPasswordRequest(password) utils.log("Correct password received, opening iris") utils.openIris() utils.sendPasswordResponse(true) + debugChat("Sent: IRIS_OPEN") return true else utils.log("Incorrect password received") utils.sendPasswordResponse(false) + debugChat("Sent: IRIS_DENIED") return false end end @@ -438,6 +469,7 @@ local function handleIncomingWormhole() -- Send version message to remote gate sleep(0.5) -- Brief delay to ensure connection is stable utils.sendVersionMessage() + debugChat("Sent: SGCS_V" .. config.programVersion) -- Handle iris if config.autoCloseIrisOnIncoming then @@ -451,6 +483,7 @@ local function handleIncomingWormhole() -- Send password request if iris is closed and password system is enabled if config.irisPassword and config.enableMessaging then utils.sendPasswordRequest() + debugChat("Sent: IRIS_PASSWORD_REQUIRED") end end end @@ -459,13 +492,14 @@ local function handleIncomingWormhole() disconnect = false while (disconnect == false) do -- parallel.waitForAny runs multiple functions at the same time and returns which one finished first - -- Here we're watching for 4 things simultaneously: + -- Here we're watching for things simultaneously: -- 1 = EntityRead (someone/something came through the gate) -- 2 = DisconnectCheck (gate disconnected on its own) -- 3 = GetMessage (received a message from remote gate) + -- 4 = GetGDOTransmission (received GDO code) -- ParaDisconnect (user clicked screen to manually disconnect) -- Whichever happens first, that function returns and we handle it - local result = parallel.waitForAny(EntityRead, DisconnectCheck, GetMessage, ParaDisconnect) + local result = parallel.waitForAny(EntityRead, DisconnectCheck, GetMessage, GetGDOTransmission, ParaDisconnect) if (result == 1) then display.showEntity(state.incomingEntityType, state.incomingEntityName, allowed) state.incomingEntityType = "" @@ -473,6 +507,7 @@ local function handleIncomingWormhole() elseif (result == 3) then -- Received a message local message = state.lastReceivedMessage + debugChat("Received: " .. tostring(message)) -- Check if it's a password attempt (don't log passwords in plaintext) if message:sub(1, 14) == "IRIS_PASSWORD:" then @@ -487,6 +522,9 @@ local function handleIncomingWormhole() utils.log("Received message: " .. message) end state.lastReceivedMessage = nil + elseif (result == 4) then + -- GDO transmission received (already handled by event system) + utils.log("GDO transmission processed") else disconnect = true end @@ -700,7 +738,7 @@ local function handleOutgoingDial() local startTime = os.clock() local lastMessageTime = startTime while (os.clock() - startTime) < 2 and gate.isStargateConnected() do - local result = parallel.waitForAny(GetMessage, function() + local result = parallel.waitForAny(GetMessage, GetGDOTransmission, function() sleep(0.3); return -1 end) if result == 1 then @@ -710,6 +748,7 @@ local function handleOutgoingDial() -- DEBUG: Print all messages received print("DEBUG: Message received: " .. tostring(message)) utils.log("DEBUG: Message received: " .. tostring(message)) + debugChat("Received: " .. tostring(message)) if message and message:sub(1, 6) == "SGCS_V" then state.remoteHasComputer = true @@ -722,6 +761,10 @@ local function handleOutgoingDial() lastMessageTime = os.clock() break -- Got password request, that's all we need end + elseif result == 2 then + -- GDO transmission received (handled by event system) + utils.log("GDO transmission detected") + lastMessageTime = os.clock() else -- Timeout - if we got a version message, assume no password required if state.remoteHasComputer and (os.clock() - lastMessageTime) > 0.5 then @@ -764,6 +807,7 @@ local function handleOutgoingDial() local password = HandlePasswordEntry() utils.sendPasswordAttempt(password) + debugChat("Sent: IRIS_PASSWORD:" .. password) -- Wait for response local function WaitForResponse()