Added GDO support and chatbox debugging

This commit is contained in:
2026-01-01 23:29:19 -05:00
parent 6841cdb559
commit 82ee133d5f
4 changed files with 83 additions and 7 deletions

View File

@ -30,7 +30,7 @@ addresses.MainGates = {
addresses.playerGates = { addresses.playerGates = {
{ "Glaive", { 33, 6, 10, 24, 1, 30, 3, 17, 0 } }, { "Glaive", { 33, 6, 10, 24, 1, 30, 3, 17, 0 } },
{ "Moon", { 32, 33, 8, 7, 25, 21, 14, 35, 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 } }, { "Trading Hall", { 16, 19, 6, 18, 35, 27, 9, 8, 0 } },
{ "Darkmoon", { 29, 10, 3, 35, 11, 14, 16, 17, 0 } } { "Darkmoon", { 29, 10, 3, 35, 11, 14, 16, 17, 0 } }
} }

View File

@ -31,8 +31,20 @@ config.irisCloseDelay = 0.1 -- seconds before closing iris on incoming
config.irisClosedByDefault = false config.irisClosedByDefault = false
-- Iris password (set to nil to disable remote password unlock) -- Iris password (set to nil to disable remote password unlock)
-- Also used as GDO IDC code when GDO support is enabled
config.irisPassword = "1234" 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 -- MESSAGING
--------------------------------------------- ---------------------------------------------

View File

@ -18,7 +18,9 @@ local state = {
remoteHasComputer = false, remoteHasComputer = false,
remotePasswordRequired = false, remotePasswordRequired = false,
destAddress = {}, destAddress = {},
destAddressname = "" destAddressname = "",
lastGDOCode = nil,
lastGDOMatches = false
} }
function handlers.init(cfg, gateInterface, monitor, utilsModule, displayModule, eventsModule) function handlers.init(cfg, gateInterface, monitor, utilsModule, displayModule, eventsModule)
@ -167,7 +169,25 @@ end
function handlers.handleMessage(eventType, side, message) function handlers.handleMessage(eventType, side, message)
state.lastReceivedMessage = 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 end
--------------------------------------------- ---------------------------------------------

View File

@ -110,6 +110,7 @@ local gate = peripheral.find("advanced_crystal_interface")
or peripheral.find("crystal_interface") or peripheral.find("crystal_interface")
or peripheral.find("basic_interface") or peripheral.find("basic_interface")
local transceiver = peripheral.find("transceiver") local transceiver = peripheral.find("transceiver")
local chatBox = peripheral.find("chatBox")
if gate == nil then if gate == nil then
error("Stargate interface not found! Please connect an interface.") error("Stargate interface not found! Please connect an interface.")
@ -120,7 +121,23 @@ if mon == nil then
end end
if transceiver == nil then 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 end
-- Check iris availability -- Check iris availability
@ -142,6 +159,13 @@ utils.init(config, gate)
display.init(mon, config, addresses, utils, localGateAddress) display.init(mon, config, addresses, utils, localGateAddress)
handlers.init(config, gate, mon, utils, display, events) 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 -- Ensure gate starts disconnected
gate.disconnectStargate() gate.disconnectStargate()
@ -224,6 +248,11 @@ local function GetMessage()
return 1 return 1
end end
local function GetGDOTransmission()
local result = events.pullEvent("transceiver_transmission_received")
return 2
end
local function HandlePasswordEntry() local function HandlePasswordEntry()
return handlers.handlePasswordInput() return handlers.handlePasswordInput()
end end
@ -234,10 +263,12 @@ local function HandleIncomingPasswordRequest(password)
utils.log("Correct password received, opening iris") utils.log("Correct password received, opening iris")
utils.openIris() utils.openIris()
utils.sendPasswordResponse(true) utils.sendPasswordResponse(true)
debugChat("Sent: IRIS_OPEN")
return true return true
else else
utils.log("Incorrect password received") utils.log("Incorrect password received")
utils.sendPasswordResponse(false) utils.sendPasswordResponse(false)
debugChat("Sent: IRIS_DENIED")
return false return false
end end
end end
@ -438,6 +469,7 @@ local function handleIncomingWormhole()
-- Send version message to remote gate -- Send version message to remote gate
sleep(0.5) -- Brief delay to ensure connection is stable sleep(0.5) -- Brief delay to ensure connection is stable
utils.sendVersionMessage() utils.sendVersionMessage()
debugChat("Sent: SGCS_V" .. config.programVersion)
-- Handle iris -- Handle iris
if config.autoCloseIrisOnIncoming then if config.autoCloseIrisOnIncoming then
@ -451,6 +483,7 @@ local function handleIncomingWormhole()
-- Send password request if iris is closed and password system is enabled -- Send password request if iris is closed and password system is enabled
if config.irisPassword and config.enableMessaging then if config.irisPassword and config.enableMessaging then
utils.sendPasswordRequest() utils.sendPasswordRequest()
debugChat("Sent: IRIS_PASSWORD_REQUIRED")
end end
end end
end end
@ -459,13 +492,14 @@ local function handleIncomingWormhole()
disconnect = false disconnect = false
while (disconnect == false) do while (disconnect == false) do
-- parallel.waitForAny runs multiple functions at the same time and returns which one finished first -- 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) -- 1 = EntityRead (someone/something came through the gate)
-- 2 = DisconnectCheck (gate disconnected on its own) -- 2 = DisconnectCheck (gate disconnected on its own)
-- 3 = GetMessage (received a message from remote gate) -- 3 = GetMessage (received a message from remote gate)
-- 4 = GetGDOTransmission (received GDO code)
-- ParaDisconnect (user clicked screen to manually disconnect) -- ParaDisconnect (user clicked screen to manually disconnect)
-- Whichever happens first, that function returns and we handle it -- 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 if (result == 1) then
display.showEntity(state.incomingEntityType, state.incomingEntityName, allowed) display.showEntity(state.incomingEntityType, state.incomingEntityName, allowed)
state.incomingEntityType = "" state.incomingEntityType = ""
@ -473,6 +507,7 @@ local function handleIncomingWormhole()
elseif (result == 3) then elseif (result == 3) then
-- Received a message -- Received a message
local message = state.lastReceivedMessage local message = state.lastReceivedMessage
debugChat("Received: " .. tostring(message))
-- Check if it's a password attempt (don't log passwords in plaintext) -- Check if it's a password attempt (don't log passwords in plaintext)
if message:sub(1, 14) == "IRIS_PASSWORD:" then if message:sub(1, 14) == "IRIS_PASSWORD:" then
@ -487,6 +522,9 @@ local function handleIncomingWormhole()
utils.log("Received message: " .. message) utils.log("Received message: " .. message)
end end
state.lastReceivedMessage = nil state.lastReceivedMessage = nil
elseif (result == 4) then
-- GDO transmission received (already handled by event system)
utils.log("GDO transmission processed")
else else
disconnect = true disconnect = true
end end
@ -700,7 +738,7 @@ local function handleOutgoingDial()
local startTime = os.clock() local startTime = os.clock()
local lastMessageTime = startTime local lastMessageTime = startTime
while (os.clock() - startTime) < 2 and gate.isStargateConnected() do 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 sleep(0.3); return -1
end) end)
if result == 1 then if result == 1 then
@ -710,6 +748,7 @@ local function handleOutgoingDial()
-- DEBUG: Print all messages received -- DEBUG: Print all messages received
print("DEBUG: Message received: " .. tostring(message)) print("DEBUG: Message received: " .. tostring(message))
utils.log("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 if message and message:sub(1, 6) == "SGCS_V" then
state.remoteHasComputer = true state.remoteHasComputer = true
@ -722,6 +761,10 @@ local function handleOutgoingDial()
lastMessageTime = os.clock() lastMessageTime = os.clock()
break -- Got password request, that's all we need break -- Got password request, that's all we need
end end
elseif result == 2 then
-- GDO transmission received (handled by event system)
utils.log("GDO transmission detected")
lastMessageTime = os.clock()
else else
-- Timeout - if we got a version message, assume no password required -- Timeout - if we got a version message, assume no password required
if state.remoteHasComputer and (os.clock() - lastMessageTime) > 0.5 then if state.remoteHasComputer and (os.clock() - lastMessageTime) > 0.5 then
@ -764,6 +807,7 @@ local function handleOutgoingDial()
local password = HandlePasswordEntry() local password = HandlePasswordEntry()
utils.sendPasswordAttempt(password) utils.sendPasswordAttempt(password)
debugChat("Sent: IRIS_PASSWORD:" .. password)
-- Wait for response -- Wait for response
local function WaitForResponse() local function WaitForResponse()