1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-13 11:40:29 +00:00

Anonymized GPS (#341)

GPS requests are now sent and received on CHANNEL_GPS by default
instead. This means it should not be possible to distinguish
computers (and thus locate them) via their GPS requests.
This commit is contained in:
Oliver Marks 2020-01-08 17:07:01 +00:00 committed by Jonathan Coates
parent c1c01bef7c
commit 35c1b10224

View File

@ -84,16 +84,16 @@ function locate( _nTimeout, _bDebug )
print( "Finding position..." )
end
-- Open a channel
-- Open GPS channel to listen for ping responses
local modem = peripheral.wrap( sModemSide )
local bCloseChannel = false
if not modem.isOpen( os.getComputerID() ) then
modem.open( os.getComputerID() )
if not modem.isOpen( CHANNEL_GPS ) then
modem.open( CHANNEL_GPS )
bCloseChannel = true
end
-- Send a ping to listening GPS hosts
modem.transmit( CHANNEL_GPS, os.getComputerID(), "PING" )
modem.transmit( CHANNEL_GPS, CHANNEL_GPS, "PING" )
-- Wait for the responses
local tFixes = {}
@ -104,7 +104,7 @@ function locate( _nTimeout, _bDebug )
if e == "modem_message" then
-- We received a reply from a modem
local sSide, sChannel, sReplyChannel, tMessage, nDistance = p1, p2, p3, p4, p5
if sSide == sModemSide and sChannel == os.getComputerID() and sReplyChannel == CHANNEL_GPS and nDistance then
if sSide == sModemSide and sChannel == CHANNEL_GPS and sReplyChannel == CHANNEL_GPS and nDistance then
-- Received the correct message from the correct modem: use it to determine position
if type(tMessage) == "table" and #tMessage == 3 and tonumber(tMessage[1]) and tonumber(tMessage[2]) and tonumber(tMessage[3]) then
local tFix = { vPosition = vector.new( tMessage[1], tMessage[2], tMessage[3] ), nDistance = nDistance }
@ -141,7 +141,7 @@ function locate( _nTimeout, _bDebug )
-- Close the channel, if we opened one
if bCloseChannel then
modem.close( os.getComputerID() )
modem.close( CHANNEL_GPS )
end
-- Return the response