Added GDO support and chatbox debugging
This commit is contained in:
52
startup.lua
52
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()
|
||||
|
||||
Reference in New Issue
Block a user