Gate debugging functions added
This commit is contained in:
@ -180,10 +180,12 @@ function handlers.handleGDOTransmission(eventType, side, frequency, idc, matches
|
|||||||
state.lastGDOCode = idc
|
state.lastGDOCode = idc
|
||||||
state.lastGDOMatches = matches
|
state.lastGDOMatches = matches
|
||||||
utils.log("GDO transmission received: IDC=" .. tostring(idc) .. ", matches=" .. tostring(matches))
|
utils.log("GDO transmission received: IDC=" .. tostring(idc) .. ", matches=" .. tostring(matches))
|
||||||
|
utils.debug("GDO received: IDC=" .. tostring(idc) .. ", matches=" .. tostring(matches))
|
||||||
|
|
||||||
-- If matches configured IDC and gate is connected, open iris
|
-- If matches configured IDC and gate is connected, open iris
|
||||||
if matches and gate.isStargateConnected() and config.irisEnabled then
|
if matches and gate.isStargateConnected() and config.irisEnabled then
|
||||||
utils.log("Valid GDO code received - opening iris")
|
utils.log("Valid GDO code received - opening iris")
|
||||||
|
utils.debug("Valid GDO - opening iris")
|
||||||
utils.openIris()
|
utils.openIris()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
23
startup.lua
23
startup.lua
@ -144,7 +144,7 @@ else
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Initialize modules
|
-- Initialize modules
|
||||||
utils.init(config, gate)
|
utils.init(config, gate, chatBox)
|
||||||
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)
|
||||||
|
|
||||||
@ -159,13 +159,6 @@ if transceiver and config.enableGDO and config.irisPassword then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 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()
|
||||||
|
|
||||||
@ -263,12 +256,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")
|
utils.debug("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")
|
utils.debug("Sent: IRIS_DENIED")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -469,7 +462,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)
|
utils.debug("Sent: SGCS_V" .. config.programVersion)
|
||||||
|
|
||||||
-- Handle iris
|
-- Handle iris
|
||||||
if config.autoCloseIrisOnIncoming then
|
if config.autoCloseIrisOnIncoming then
|
||||||
@ -483,7 +476,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")
|
utils.debug("Sent: IRIS_PASSWORD_REQUIRED")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -507,7 +500,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))
|
utils.debug("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
|
||||||
@ -748,7 +741,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))
|
utils.debug("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
|
||||||
@ -807,7 +800,7 @@ local function handleOutgoingDial()
|
|||||||
|
|
||||||
local password = HandlePasswordEntry()
|
local password = HandlePasswordEntry()
|
||||||
utils.sendPasswordAttempt(password)
|
utils.sendPasswordAttempt(password)
|
||||||
debugChat("Sent: IRIS_PASSWORD:" .. password)
|
utils.debug("Sent: IRIS_PASSWORD:" .. password)
|
||||||
|
|
||||||
-- Wait for response
|
-- Wait for response
|
||||||
local function WaitForResponse()
|
local function WaitForResponse()
|
||||||
|
|||||||
25
utils.lua
25
utils.lua
@ -8,10 +8,12 @@ local utils = {}
|
|||||||
-- Import config (set by startup.lua)
|
-- Import config (set by startup.lua)
|
||||||
local config
|
local config
|
||||||
local gate
|
local gate
|
||||||
|
local chatBox
|
||||||
|
|
||||||
function utils.init(cfg, gateInterface)
|
function utils.init(cfg, gateInterface, chatBoxPeripheral)
|
||||||
config = cfg
|
config = cfg
|
||||||
gate = gateInterface
|
gate = gateInterface
|
||||||
|
chatBox = chatBoxPeripheral
|
||||||
end
|
end
|
||||||
|
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
@ -35,6 +37,27 @@ function utils.log(message)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function utils.debug(message)
|
||||||
|
-- Log to debug log file
|
||||||
|
local timestamp = os.date("%Y-%m-%d %H:%M:%S")
|
||||||
|
local logEntry = "[" .. timestamp .. "] " .. message
|
||||||
|
|
||||||
|
-- Write to console
|
||||||
|
print("DEBUG: " .. message)
|
||||||
|
|
||||||
|
-- Write to debug log file
|
||||||
|
local file = fs.open("gate_debug.log", "a")
|
||||||
|
if file then
|
||||||
|
file.writeLine(logEntry)
|
||||||
|
file.close()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Send to chatbox if enabled
|
||||||
|
if config.enableChatboxDebug and chatBox then
|
||||||
|
chatBox.sendMessageToPlayer("[SGC] " .. message, config.chatboxDebugPlayer)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
-- ADDRESS UTILITIES
|
-- ADDRESS UTILITIES
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user