Skip to content

Commit

Permalink
Network EGP data only to owner (#3139)
Browse files Browse the repository at this point in the history
  • Loading branch information
wrefgtzweve authored Oct 2, 2024
1 parent 11a153b commit b2ed354
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
27 changes: 16 additions & 11 deletions lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if (SERVER) then
if not EGP.umsg.Start( "EGP_Transmit_Data", ply ) then return end
net.WriteEntity( Ent )
net.WriteString( "ClearScreen" )
EGP.umsg.End()
EGP.umsg.End( Ent )

EGP:SendQueueItem( ply )
end
Expand All @@ -61,7 +61,7 @@ if (SERVER) then
net.WriteString( "SaveFrame" )
net.WriteEntity( ply )
net.WriteString( FrameName )
EGP.umsg.End()
EGP.umsg.End( Ent )

EGP:SendQueueItem( ply )
end
Expand All @@ -82,7 +82,7 @@ if (SERVER) then
net.WriteString( "LoadFrame" )
net.WriteEntity( ply )
net.WriteString( FrameName )
EGP.umsg.End()
EGP.umsg.End( Ent )

EGP:SendQueueItem( ply )
end
Expand Down Expand Up @@ -112,7 +112,7 @@ if (SERVER) then
net.WriteFloat( vert.v or 0 )
end
end
EGP.umsg.End()
EGP.umsg.End( Ent )
end

EGP:SendQueueItem( ply )
Expand Down Expand Up @@ -144,7 +144,7 @@ if (SERVER) then
net.WriteFloat( vert.v or 0 )
end
end
EGP.umsg.End()
EGP.umsg.End( Ent )
end

EGP:SendQueueItem( ply )
Expand All @@ -165,7 +165,7 @@ if (SERVER) then
net.WriteString( "AddText" )
net.WriteInt( index, 16 )
net.WriteString( text )
EGP.umsg.End()
EGP.umsg.End( Ent )
end

EGP:SendQueueItem( ply )
Expand All @@ -186,7 +186,7 @@ if (SERVER) then
net.WriteString( "SetText" )
net.WriteInt( index, 16 )
net.WriteString( text )
EGP.umsg.End()
EGP.umsg.End( Ent )
end

EGP:SendQueueItem( ply )
Expand All @@ -213,7 +213,7 @@ if (SERVER) then
net.WriteEntity( Ent )
net.WriteString( "EditFiltering" )
net.WriteUInt( filtering, 2 )
EGP.umsg.End()
EGP.umsg.End( Ent )

EGP:SendQueueItem( ply )
end
Expand Down Expand Up @@ -278,7 +278,7 @@ if (SERVER) then
v:Transmit( Ent, ply )
end
end
EGP.umsg.End()
EGP.umsg.End( Ent )

-- Change order now
if order_was_changed then
Expand Down Expand Up @@ -574,7 +574,7 @@ if (SERVER) then
end
end)

function EGP:SendDataStream( ply, entid )
function EGP:SendDataStream( ply, entid, silent )
if not ply or not ply:IsValid() then return false, "ERROR: Invalid ply." end
local targets
if (entid) then
Expand Down Expand Up @@ -620,12 +620,17 @@ if (SERVER) then
end

timer.Simple( k, function() -- send 1 second apart
local isLastScreen = ((k == #targets) and #targets or nil)
if silent then
isLastScreen = nil
end

net.Start("EGP_Request_Transmit")
net.WriteTable({
Ent = v,
Objects = DataToSend,
Filtering = v.GPU_texture_filtering,
IsLastScreen = (k == #targets) and #targets or nil -- Doubles as notifying the client that no more data will arrive, and tells them how many did arrive
IsLastScreen = isLastScreen -- Doubles as notifying the client that no more data will arrive, and tells them how many did arrive
})
net.Send(ply)
end)
Expand Down
15 changes: 13 additions & 2 deletions lua/entities/gmod_wire_egp/lib/egplib/umsgsystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function EGP.umsg.Start( name, sender )
return true
end

function EGP.umsg.End()
function EGP.umsg.End( ent )
if CurSender:IsValid() then
if not EGP.IntervalCheck[CurSender] then EGP.IntervalCheck[CurSender] = { bytes = 0, time = 0 } end
local bytes = net.BytesWritten()
Expand All @@ -48,8 +48,19 @@ function EGP.umsg.End()
else
ErrorNoHalt("Tried to end EGP net message outside of net context?")
end
net.Broadcast()

if ent.Users then
local sendTbl = {}
for ply, _ in pairs(ent.Users) do
if ply:IsValid() then
table.insert(sendTbl, ply)
end
end

net.Send(sendTbl)
else
net.Broadcast()
end
else
net.Send(NULL)
end
Expand Down
1 change: 1 addition & 0 deletions lua/entities/gmod_wire_egp_hud/huddraw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ else -- SERVER

local function EGPHudConnect(ent, state, ply)
if state then
EGP:SendDataStream(ply, ent:EntIndex(), true)
if not ent.Users then ent.Users = {} end

if not ent.Users[ply] then
Expand Down

0 comments on commit b2ed354

Please sign in to comment.