Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions lua/autorun/netstream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,54 @@
net.Stream.MaxSize = net.Stream.SendSize*net.Stream.MaxChunks
net.Stream.MaxTries = 3 --Maximum times the client may retry downloading the whole data

local pendingStreams = {}
if SERVER then
-- Bind streams to the recipients of the message containing their headers.
for _, name in ipairs({"Start", "Abort"}) do
local original = net[name]
net[name] = function(...)
pendingStreams = {}
return original(...)
end
end

for _, name in ipairs({"Send", "Broadcast", "SendOmit", "SendPVS", "SendPAS"}) do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detouring every single net function is not a fix for this??

local original = net[name]
net[name] = function(...)
if #pendingStreams > 0 then
local target = ...
local recipients
if name == "Send" then
if type(target) == "CRecipientFilter" then
recipients = target:GetPlayers()
else
recipients = istable(target) and target or {target}
end
elseif name == "Broadcast" then
recipients = player.GetAll()
else
local filter = RecipientFilter()
if name == "SendOmit" then
filter:AddAllPlayers()
filter:RemovePlayers(istable(target) and target or {target})
elseif name == "SendPVS" then
filter:AddPVS(target)
else
filter:AddPAS(target)
end
recipients = filter:GetPlayers()
end

local allowed = {}
for _, ply in ipairs(recipients) do allowed[ply] = true end
for _, stream in ipairs(pendingStreams) do stream.recipients = allowed end
pendingStreams = {}
end
return original(...)
end
end
end

local WriteStreamQueue = {
__index = {
Add = function(self, stream)
Expand Down Expand Up @@ -87,7 +135,7 @@
ErrorNoHalt("Receiving too many ReadStream requests!")
return
end

Check warning on line 138 in lua/autorun/netstream.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace
for _, v in ipairs(queue) do
if v.identifier == stream.identifier then
ErrorNoHalt("Tried to start a new ReadStream for an already existing stream!")
Expand Down Expand Up @@ -145,6 +193,7 @@
local WritingDataItem = {
__index = {
Write = function(self, ply, chunkidx)
if SERVER and (not self.recipients or not self.recipients[ply]) then return false end
local client = self.clients[ply]
if client.finished then return false end
if chunkidx == #self.chunks+1 then self:Finished(ply) return true end
Expand Down Expand Up @@ -323,7 +372,8 @@

local stream = net.Stream.WriteStreams:Add(WritingDataItem(data, callback, compressed))
if not stream then return end
if SERVER then pendingStreams[#pendingStreams+1] = stream end

Check warning on line 376 in lua/autorun/netstream.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace
--print("WriteStream", #stream.chunks, stream.identifier, compressed)
net.WriteUInt(#stream.chunks, 32)
net.WriteUInt(stream.identifier, 32)
Expand All @@ -347,7 +397,7 @@
if not isfunction(callback) then
error("bad argument #2 to 'ReadStream' (function expected, got " .. type(callback) .. ")", 2)
end

Check warning on line 400 in lua/autorun/netstream.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace
local numchunks = net.ReadUInt(32)
if numchunks == nil then
return
Expand Down
Loading