Skip to content

Commit 1047d34

Browse files
authored
Use netstream for e2_functiondata (#3398)
* Use netstream for e2_functiondata * Use actual error
1 parent b9fef53 commit 1047d34

File tree

1 file changed

+26
-33
lines changed
  • lua/entities/gmod_wire_expression2/core

1 file changed

+26
-33
lines changed

lua/entities/gmod_wire_expression2/core/init.lua

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,8 @@ do
294294
loadFiles("",file.Find("entities/gmod_wire_expression2/core/cl_*.lua", "LUA"))
295295
end
296296

297-
local E2FunctionQueue = WireLib.NetQueue("e2_functiondata")
298-
local E2FUNC_SENDMISC, E2FUNC_SENDFUNC, E2FUNC_DONE = 0, 1, 2
299297
if SERVER then
298+
util.AddNetworkString("e2_functiondata")
300299
-- Serverside files are loaded in extloader
301300
include("extloader.lua")
302301

@@ -335,28 +334,14 @@ if SERVER then
335334
local function sendData(ply)
336335
if not (IsValid(ply) and ply:IsPlayer()) then return end
337336

338-
local queue = E2FunctionQueue.plyqueues[ply]
339-
queue:add(function()
340-
net.WriteUInt(E2FUNC_SENDMISC, 8)
341-
net.WriteTable(miscdata[1])
342-
net.WriteTable(miscdata[2])
343-
net.WriteTable(miscdata[3])
344-
end)
345-
for signature, tab in pairs(functiondata) do
346-
queue:add(function()
347-
net.WriteUInt(E2FUNC_SENDFUNC, 8)
348-
net.WriteString(signature) -- The function signature ["holoAlpha(nn)"]
349-
net.WriteString(tab[1]) -- The function's return type ["s"]
350-
net.WriteUInt(tab[2] or 0, 16) -- The function's cost [5]
351-
net.WriteTable(tab[3] or {}) -- The function's argnames table (if a table isn't set, it'll just send a 1 byte blank table)
352-
net.WriteString(tab[4] or "unknown")
353-
net.WriteTable(tab[5] or {}) -- Attributes
354-
end)
355-
end
356-
queue:add(function()
357-
net.WriteUInt(E2FUNC_DONE, 8)
358-
end)
359-
E2FunctionQueue:flushQueue(ply, queue)
337+
local data = WireLib.von.serialize( {
338+
miscdata = miscdata,
339+
functiondata = functiondata
340+
} )
341+
342+
net.Start("e2_functiondata")
343+
net.WriteStream(data)
344+
net.Send(ply)
360345
end
361346

362347
local antispam = WireLib.RegisterPlayerTable()
@@ -425,16 +410,24 @@ elseif CLIENT then
425410
E2Lib.Env.Events = events
426411
end
427412

428-
function E2FunctionQueue.receivecb()
429-
local state = net.ReadUInt(8)
430-
if state == E2FUNC_SENDFUNC then
431-
insertData(net.ReadString(), net.ReadString(), net.ReadUInt(16), net.ReadTable(), net.ReadString(), net.ReadTable())
432-
elseif state == E2FUNC_SENDMISC then
433-
insertMiscData(net.ReadTable(), net.ReadTable(), net.ReadTable())
434-
elseif state == E2FUNC_DONE then
413+
net.Receive("e2_functiondata", function()
414+
net.ReadStream( nil, function( data )
415+
local deserialized = WireLib.von.deserialize(data)
416+
if not deserialized then
417+
error("Failed to deserialize E2 function data from server!\n")
418+
end
419+
420+
wire_expression2_reset_extensions()
421+
422+
insertMiscData(deserialized.miscdata[1], deserialized.miscdata[2], deserialized.miscdata[3])
423+
424+
for signature, tab in pairs(deserialized.functiondata) do
425+
insertData(signature, tab[1], tab[2] or 0, tab[3] or {}, tab[4] or "unknown", tab[5] or {})
426+
end
427+
435428
doneInsertingData()
436-
end
437-
end
429+
end )
430+
end)
438431
end
439432

440433
-- this file just generates the docs so it doesn't need to run every time.

0 commit comments

Comments
 (0)