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.lastGDOMatches = 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 and gate.isStargateConnected() and config.irisEnabled then
|
||||
utils.log("Valid GDO code received - opening iris")
|
||||
utils.debug("Valid GDO - opening iris")
|
||||
utils.openIris()
|
||||
end
|
||||
|
||||
|
||||
23
startup.lua
23
startup.lua
@ -144,7 +144,7 @@ else
|
||||
end
|
||||
|
||||
-- Initialize modules
|
||||
utils.init(config, gate)
|
||||
utils.init(config, gate, chatBox)
|
||||
display.init(mon, config, addresses, utils, localGateAddress)
|
||||
handlers.init(config, gate, mon, utils, display, events)
|
||||
|
||||
@ -159,13 +159,6 @@ if transceiver and config.enableGDO and config.irisPassword then
|
||||
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
|
||||
gate.disconnectStargate()
|
||||
|
||||
@ -263,12 +256,12 @@ local function HandleIncomingPasswordRequest(password)
|
||||
utils.log("Correct password received, opening iris")
|
||||
utils.openIris()
|
||||
utils.sendPasswordResponse(true)
|
||||
debugChat("Sent: IRIS_OPEN")
|
||||
utils.debug("Sent: IRIS_OPEN")
|
||||
return true
|
||||
else
|
||||
utils.log("Incorrect password received")
|
||||
utils.sendPasswordResponse(false)
|
||||
debugChat("Sent: IRIS_DENIED")
|
||||
utils.debug("Sent: IRIS_DENIED")
|
||||
return false
|
||||
end
|
||||
end
|
||||
@ -469,7 +462,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)
|
||||
utils.debug("Sent: SGCS_V" .. config.programVersion)
|
||||
|
||||
-- Handle iris
|
||||
if config.autoCloseIrisOnIncoming then
|
||||
@ -483,7 +476,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")
|
||||
utils.debug("Sent: IRIS_PASSWORD_REQUIRED")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -507,7 +500,7 @@ local function handleIncomingWormhole()
|
||||
elseif (result == 3) then
|
||||
-- Received a message
|
||||
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)
|
||||
if message:sub(1, 14) == "IRIS_PASSWORD:" then
|
||||
@ -748,7 +741,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))
|
||||
utils.debug("Received: " .. tostring(message))
|
||||
|
||||
if message and message:sub(1, 6) == "SGCS_V" then
|
||||
state.remoteHasComputer = true
|
||||
@ -807,7 +800,7 @@ local function handleOutgoingDial()
|
||||
|
||||
local password = HandlePasswordEntry()
|
||||
utils.sendPasswordAttempt(password)
|
||||
debugChat("Sent: IRIS_PASSWORD:" .. password)
|
||||
utils.debug("Sent: IRIS_PASSWORD:" .. password)
|
||||
|
||||
-- Wait for response
|
||||
local function WaitForResponse()
|
||||
|
||||
25
utils.lua
25
utils.lua
@ -8,10 +8,12 @@ local utils = {}
|
||||
-- Import config (set by startup.lua)
|
||||
local config
|
||||
local gate
|
||||
local chatBox
|
||||
|
||||
function utils.init(cfg, gateInterface)
|
||||
function utils.init(cfg, gateInterface, chatBoxPeripheral)
|
||||
config = cfg
|
||||
gate = gateInterface
|
||||
chatBox = chatBoxPeripheral
|
||||
end
|
||||
|
||||
---------------------------------------------
|
||||
@ -35,6 +37,27 @@ function utils.log(message)
|
||||
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
|
||||
---------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user