Skip to content

Commit 24d0663

Browse files
fix download failure checks
1 parent d946430 commit 24d0663

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

newmodels/client.lua

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
-- Custom events:
1010
addEvent(resName..":receiveModList", true)
1111
addEvent(resName..":receiveVehicleHandling", true)
12-
-- addEvent(resName..":onMapListReceived", true) -- deprecated
1312
addEvent(resName..":onModListReceived", true)
1413
addEvent(resName..":onModFileDownloaded", true)
1514

@@ -804,7 +803,9 @@ function onDownloadFailed(modId, path)
804803

805804
if fileDLTries[path] == DOWNLOAD_MAX_TRIES then
806805
triggerServerEvent(resName..":kickOnDownloadsFail", resourceRoot, modId, path)
806+
return true
807807
end
808+
return false
808809
end
809810

810811
function handleDownloadFinish(fileName, success, requestRes)
@@ -814,16 +815,24 @@ function handleDownloadFinish(fileName, success, requestRes)
814815

815816
currDownloading = nil
816817

818+
local waitDelay = 50
819+
817820
if not success then
818-
onDownloadFailed(modId, path)
821+
819822
outputDebugString("Failed to download mod file: "..tostring(fileName), 1)
820-
return
821-
end
823+
if onDownloadFailed(modId, path) then
824+
return -- Kicked
825+
end
822826

823-
setModFileReady(modId, path)
827+
-- place back in queue
828+
table.insert(fileDLQueue, 1, {modId, path})
829+
waitDelay = 1000
830+
else
831+
setModFileReady(modId, path)
832+
end
824833

825834
if #fileDLQueue >= 1 then
826-
setTimer(downloadFirstInQueue, 50, 1)
835+
setTimer(downloadFirstInQueue, waitDelay, 1)
827836
elseif busyDownloading then
828837
if (SHOW_DOWNLOADING) then removeEventHandler("onClientRender", root, showDownloadingDialog) end
829838
busyDownloading = false
@@ -850,13 +859,13 @@ function downloadFirstInQueue()
850859
currDownloading = {modId, path}
851860

852861
if not downloadFile(path) then
853-
currDownloading = nil
854-
if busyDownloading then
855-
if (SHOW_DOWNLOADING) then removeEventHandler("onClientRender", root, showDownloadingDialog) end
856-
busyDownloading = false
857-
end
858-
onDownloadFailed(modId, path)
859862
outputDebugString("Error trying to download file: "..tostring(path), 1)
863+
if onDownloadFailed(modId, path) then
864+
return -- Kicked
865+
end
866+
867+
-- retry after a bit:
868+
setTimer(downloadFile, 1000, 1, path)
860869
end
861870
end
862871

@@ -948,7 +957,6 @@ function receiveModList(modList)
948957
outputDebugString("Received mod list on client", 0, 115, 236, 255)
949958

950959
-- for other resources to handle
951-
-- triggerEvent(resName..":onMapListReceived", localPlayer) -- deprecated
952960
triggerEvent(resName..":onModListReceived", localPlayer)
953961

954962
if updateElementsInQueue() then

newmodels/server.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
addEvent(resName..":requestModList", true)
1111
addEvent(resName..":resetElementModel", true)
1212
addEvent(resName..":updateVehicleProperties", true)
13+
addEvent(resName..":kickOnDownloadsFail", true)
1314

1415
local SERVER_READY = false
1516
local startTickCount

0 commit comments

Comments
 (0)