Skip to content

Commit

Permalink
Anonymized GPS (#341)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
osmarks authored and SquidDev committed Jan 8, 2020
1 parent c1c01be commit 35c1b10
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/resources/assets/computercraft/lua/rom/apis/gps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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 }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 35c1b10

Please sign in to comment.