99-- Custom events:
1010addEvent (resName .. " :receiveModList" , true )
1111addEvent (resName .. " :receiveVehicleHandling" , true )
12- -- addEvent(resName..":onMapListReceived", true) -- deprecated
1312addEvent (resName .. " :onModListReceived" , true )
1413addEvent (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
808809end
809810
810811function 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
861870end
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
0 commit comments