From dfa63f646d17fe54186908858c73962d08d79177 Mon Sep 17 00:00:00 2001 From: Redox Date: Wed, 9 Oct 2024 14:23:02 +0200 Subject: [PATCH 1/7] Dont use net.WriteTable for EGP --- .../lib/egplib/transmitreceive.lua | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua index df4ab6efa..656884205 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua @@ -625,13 +625,18 @@ if (SERVER) then isLastScreen = nil end + local data = { + Ent = v, + Objects = DataToSend, + Filtering = v.GPU_texture_filtering, + IsLastScreen = isLastScreen -- Doubles as notifying the client that no more data will arrive, and tells them how many did arrive + } + + local json = util.TableToJSON(data) + local compressed = util.Compress(json) net.Start("EGP_Request_Transmit") - net.WriteTable({ - Ent = v, - Objects = DataToSend, - Filtering = v.GPU_texture_filtering, - IsLastScreen = isLastScreen -- Doubles as notifying the client that no more data will arrive, and tells them how many did arrive - }) + net.WriteUInt( #compressed, 16 ) + net.WriteData( compressed, #compressed ) net.Send(ply) end) sent = true @@ -643,21 +648,7 @@ if (SERVER) then return true, #targets end end - - local function initspawn(ply) - timer.Simple(10,function() - if (ply and ply:IsValid()) then - local bool, msg = EGP:SendDataStream( ply ) - if (bool == true) then - ply:ChatPrint("[EGP] " .. tostring(msg) .. " EGP Screens found on the server. Sending objects now...") - end - end - end) - end - - hook.Add("PlayerInitialSpawn","EGP_SpawnFunc",initspawn) else - function EGP:ReceiveDataStream( decoded ) local Ent = decoded.Ent local Objects = decoded.Objects @@ -684,7 +675,11 @@ else LocalPlayer():ChatPrint("[EGP] Received EGP object reload. " .. decoded.IsLastScreen .. " screens' objects were reloaded.") end end + net.Receive("EGP_Request_Transmit", function(len,ply) - EGP:ReceiveDataStream(net.ReadTable()) + local amount = net.ReadUInt(16) + local data = net.ReadData(amount) + local tbl = util.JSONToTable(util.Decompress(data)) + EGP:ReceiveDataStream(tbl) end) -end \ No newline at end of file +end From 11976df0d57d619657639e1c768318998642abb8 Mon Sep 17 00:00:00 2001 From: Redox Date: Fri, 11 Oct 2024 17:40:48 +0200 Subject: [PATCH 2/7] Use von instead of JSON --- lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua index 656884205..7fa9cd784 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua @@ -632,7 +632,7 @@ if (SERVER) then IsLastScreen = isLastScreen -- Doubles as notifying the client that no more data will arrive, and tells them how many did arrive } - local json = util.TableToJSON(data) + local json = WireLib.von.serialize(data) local compressed = util.Compress(json) net.Start("EGP_Request_Transmit") net.WriteUInt( #compressed, 16 ) @@ -679,7 +679,7 @@ else net.Receive("EGP_Request_Transmit", function(len,ply) local amount = net.ReadUInt(16) local data = net.ReadData(amount) - local tbl = util.JSONToTable(util.Decompress(data)) + local tbl = WireLib.von.deserialize(util.Decompress(data)) EGP:ReceiveDataStream(tbl) end) end From 049cdb161113f85a6fc5dbbba3401ca22a92a0ef Mon Sep 17 00:00:00 2001 From: Redox Date: Mon, 14 Oct 2024 16:58:09 +0200 Subject: [PATCH 3/7] Fix var name --- lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua index 7fa9cd784..71483bd07 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua @@ -632,8 +632,8 @@ if (SERVER) then IsLastScreen = isLastScreen -- Doubles as notifying the client that no more data will arrive, and tells them how many did arrive } - local json = WireLib.von.serialize(data) - local compressed = util.Compress(json) + local von = WireLib.von.serialize(data) + local compressed = util.Compress(von) net.Start("EGP_Request_Transmit") net.WriteUInt( #compressed, 16 ) net.WriteData( compressed, #compressed ) From 3341bed9e2015121f3be56a4172c95aec4dacb0f Mon Sep 17 00:00:00 2001 From: Redox Date: Tue, 15 Oct 2024 13:34:18 +0200 Subject: [PATCH 4/7] Send first message instantly --- lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua index 71483bd07..118533c43 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua @@ -619,7 +619,7 @@ if (SERVER) then DataToSend[#DataToSend+1] = { ID = obj.ID, index = obj.index, Settings = obj:DataStreamInfo() } end - timer.Simple( k, function() -- send 1 second apart + timer.Simple( k - 1, function() -- send 1 second apart, send the first one instantly local isLastScreen = ((k == #targets) and #targets or nil) if silent then isLastScreen = nil From 9364e7b99d7e2483d7d01700094d943f210d6ab2 Mon Sep 17 00:00:00 2001 From: Redox Date: Tue, 15 Oct 2024 13:47:56 +0200 Subject: [PATCH 5/7] Cancel early if the compressed lenght is too large --- .../gmod_wire_egp/lib/egplib/transmitreceive.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua index 118533c43..570ed1b60 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua @@ -634,9 +634,16 @@ if (SERVER) then local von = WireLib.von.serialize(data) local compressed = util.Compress(von) + local compressedLength = #compressed + + if compressedLength > 60000 then + ply:ChatPrint("[EGP] Error: Data too large to send to client. (" .. math.Round( compressedLength / 1024, 2 ) .. " kb)") + return + end + net.Start("EGP_Request_Transmit") - net.WriteUInt( #compressed, 16 ) - net.WriteData( compressed, #compressed ) + net.WriteUInt( compressedLength, 16 ) + net.WriteData( compressed, compressedLength ) net.Send(ply) end) sent = true From 69b87fda756874b285f0934928df7a7152f9ac12 Mon Sep 17 00:00:00 2001 From: Redox Date: Sat, 26 Oct 2024 18:05:15 +0200 Subject: [PATCH 6/7] Add uncompressed and decompress limit --- .../gmod_wire_egp/lib/egplib/transmitreceive.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua index 570ed1b60..8480afd8b 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua @@ -633,15 +633,22 @@ if (SERVER) then } local von = WireLib.von.serialize(data) + local vonLen = #von + if vonLen > 60000 then + ply:ChatPrint("[EGP] Error: Data too large to send to client. (" .. math.Round( vonLen / 1024, 2 ) .. " kb)") + return + end + local compressed = util.Compress(von) local compressedLength = #compressed if compressedLength > 60000 then - ply:ChatPrint("[EGP] Error: Data too large to send to client. (" .. math.Round( compressedLength / 1024, 2 ) .. " kb)") + ply:ChatPrint("[EGP] Error: Compressed data too large to send to client. (" .. math.Round( compressedLength / 1024, 2 ) .. " kb)") return end net.Start("EGP_Request_Transmit") + net.WriteUInt( vonLen, 16 ) net.WriteUInt( compressedLength, 16 ) net.WriteData( compressed, compressedLength ) net.Send(ply) @@ -684,9 +691,10 @@ else end net.Receive("EGP_Request_Transmit", function(len,ply) + local vonLen = net.ReadUInt(16) local amount = net.ReadUInt(16) local data = net.ReadData(amount) - local tbl = WireLib.von.deserialize(util.Decompress(data)) + local tbl = WireLib.von.deserialize(util.Decompress(data, vonLen)) EGP:ReceiveDataStream(tbl) end) end From 4f5531e6ecc5ddf10054355a26f47526e1e96d21 Mon Sep 17 00:00:00 2001 From: Redox Date: Sun, 27 Oct 2024 13:47:37 +0100 Subject: [PATCH 7/7] Dont network vonlen --- .../gmod_wire_egp/lib/egplib/transmitreceive.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua index 8480afd8b..b40b169a5 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/transmitreceive.lua @@ -633,9 +633,8 @@ if (SERVER) then } local von = WireLib.von.serialize(data) - local vonLen = #von - if vonLen > 60000 then - ply:ChatPrint("[EGP] Error: Data too large to send to client. (" .. math.Round( vonLen / 1024, 2 ) .. " kb)") + if #von > 60000 then + ply:ChatPrint("[EGP] Error: Data too large to send to client. (" .. math.Round( #von / 1024, 2 ) .. " kb)") return end @@ -648,7 +647,6 @@ if (SERVER) then end net.Start("EGP_Request_Transmit") - net.WriteUInt( vonLen, 16 ) net.WriteUInt( compressedLength, 16 ) net.WriteData( compressed, compressedLength ) net.Send(ply) @@ -691,10 +689,9 @@ else end net.Receive("EGP_Request_Transmit", function(len,ply) - local vonLen = net.ReadUInt(16) local amount = net.ReadUInt(16) local data = net.ReadData(amount) - local tbl = WireLib.von.deserialize(util.Decompress(data, vonLen)) + local tbl = WireLib.von.deserialize(util.Decompress(data, 60000)) EGP:ReceiveDataStream(tbl) end) end