Skip to content

Commit

Permalink
rate limit thumb downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
plally committed Feb 3, 2024
1 parent 3ad44d2 commit 3156605
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 7 additions & 0 deletions lua/mapvote/server/modules/net.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ MapVote.Net.receiveWithMiddleware( "MapVote_RequestVoteState", function( _, ply
end )
end, MapVote.Net.rateLimit( "MapVote_RequestVoteState", 2, 0.1 ) )

MapVote.Net.receiveWithMiddleware( "MapVote_RequestWorkshopIDTable", function( _, ply )
local addonWorkshopIDs = MapVote.getWorkshopIDs( MapVote.maps )
net.Start( "MapVote_WorkshopIDTable" )
net.WriteTable( addonWorkshopIDs )
net.Send( ply )
end, MapVote.Net.rateLimit( "MapVote_RequestWorkshopIDTable", 5, 0.5 ) )

-- to client

function MapVote.Net.sendVoteStart( endTime, mapsInVote, ply )
Expand Down
14 changes: 6 additions & 8 deletions lua/mapvote/server/modules/thumb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@ function MapVote.getAllWorkshopIDs()
local addonWorkshopIDs = {}
for _, addon in ipairs( engine.GetAddons() ) do
local files = file.Find( "maps/*.bsp", addon.title )
for _, f in ipairs(files) do
for _, f in ipairs( files ) do
addonWorkshopIDs[string.Replace( f, ".bsp", "" )] = addon.wsid
end
end
MapVote.addonWorkshopIDs = addonWorkshopIDs
end

net.Receive( "MapVote_RequestWorkshopIDTable", function( _, ply )
local requestedMaps = net.ReadTable()
function MapVote.getWorkshopIDs( maps )
local addonWorkshopIDs = {}
for _, map in ipairs( requestedMaps ) do
for _, map in ipairs( maps ) do
if MapVote.addonWorkshopIDs[map] then
addonWorkshopIDs[map] = MapVote.addonWorkshopIDs[map]
else
print( "MapVote: No workshop ID found for map", map )
end
end
net.Start( "MapVote_WorkshopIDTable" )
net.WriteTable( addonWorkshopIDs )
net.Send( ply )
end )
return addonWorkshopIDs
end

hook.Add( "Initialize", "MapVote_GetWorkshopIDs", MapVote.getAllWorkshopIDs )

0 comments on commit 3156605

Please sign in to comment.