diff --git a/lua/mapvote/server/modules/net.lua b/lua/mapvote/server/modules/net.lua index f82e723..1995eb9 100644 --- a/lua/mapvote/server/modules/net.lua +++ b/lua/mapvote/server/modules/net.lua @@ -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 ) diff --git a/lua/mapvote/server/modules/thumb.lua b/lua/mapvote/server/modules/thumb.lua index 1431e1c..2197540 100644 --- a/lua/mapvote/server/modules/thumb.lua +++ b/lua/mapvote/server/modules/thumb.lua @@ -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 )