Skip to content

Commit

Permalink
Added a fallback for the map updater if the primary server fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Balthazar committed Dec 23, 2024
1 parent 314eea9 commit ef235a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/utils/network.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function network.ftpGetWrite(path)
end
end

function network.getMapLibData()
local code, body, headers = require'https'.request'https://theloudproject.org:8081/maps/'
function network.getMapLibData(address)
local code, body, headers = require'https'.request(address or 'https://theloudproject.org:8081/maps/')
if code~=200 then return ('Communication error: %s: %s'):format(tostring(code), body) end
local mapsData = {}
for mapJsonRaw in body:gmatch'%b{}' do
Expand All @@ -65,16 +65,16 @@ function network.getMapLibData()
return mapsData
end

function network.getMapLibFile(file)
local code, body, headers = require'https'.request('https://theloudproject.org:8081/'..file)
function network.getMapLibFile(file, address)
local code, body, headers = require'https'.request((address or 'https://theloudproject.org:8081/')..file)
if code~=200 then return file, 'Communication error' end
return file, body
end

function network.getMap(data)
function network.getMap(data, address)
feedback:push(1)
feedback:push{data.name, 'downloading'}
local code, body, headers = require'https'.request('https://theloudproject.org:8081/'..data.file)
local code, body, headers = require'https'.request((address or 'https://theloudproject.org:8081/')..data.file)
if code~=200 then
feedback:push{data.name, 'done'}
feedback:push{{0.7, 0, 0.3}, ('%s map download failed: code %s: %s'):format(data.name, tostring(code), body)}
Expand Down
9 changes: 8 additions & 1 deletion src/utils/threads/updateMaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ local feedback = love.thread.getChannel'log'
local updatingMarker = love.thread.getChannel'updatingMarker'
feedback:push'Fetching map library data'
local libdata = network.getMapLibData()
local address

if type(libdata) == 'string' then
feedback:push{{0.7, 0, 0.3}, libdata, '\n'}
feedback:push{{1, 0.6, 0.3}, 'Trying EU read-only mirror\n'}
address = 'https://eu.theloudproject.org:8081/'
libdata = network.getMapLibData(address)
end
if type(libdata) == 'string' then
love.thread.getChannel'wastefulSingleUseChannelToMarkMapUpdateComplete':push'no'
return feedback:push{{0.7, 0, 0.3}, libdata, '\n'}
Expand All @@ -19,7 +26,7 @@ end
for i, data in ipairs(libdata) do
if data.outOfDate then
feedback:push(-1)
network.getMap(data)
network.getMap(data, address)
end
end
feedback:push'All maps up to date'
Expand Down

0 comments on commit ef235a7

Please sign in to comment.