From 74d0365733f04c499d81ff98840b3b015f6d7830 Mon Sep 17 00:00:00 2001 From: AlmTech Software Date: Sat, 16 Nov 2019 14:47:32 +0100 Subject: [PATCH] Fixed networking bugs --- gamemode/engine/derma/cl_menu.lua | 4 ++-- gamemode/engine/lib/server/sv_networking.lua | 13 ++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/gamemode/engine/derma/cl_menu.lua b/gamemode/engine/derma/cl_menu.lua index de93481..7f30469 100644 --- a/gamemode/engine/derma/cl_menu.lua +++ b/gamemode/engine/derma/cl_menu.lua @@ -15,9 +15,9 @@ local libs = { Quantum.Client.Menu.GetAPI = function( lib ) return include( libs[lib] ) end net.Receive( "quantum_menu_net", function( len, pl ) - local dt = util.JSONToTable(net.ReadString()) -- TO DO: merge datatable with cached ( if same id/type ) + local dt = net.ReadTable() if( Quantum.Client.Cache[dt.id] ~= nil && #Quantum.Client.Cache[dt.id] >= 1 ) then - table.Merge( Quantum.Client.Cache[dt.id], dt ) + table.Merge( Quantum.Client.Cache[dt.id], dt ) else Quantum.Client.Cache[dt.id] = dt || { id = dt.id } end diff --git a/gamemode/engine/lib/server/sv_networking.lua b/gamemode/engine/lib/server/sv_networking.lua index 99ee48a..bbc4c4f 100644 --- a/gamemode/engine/lib/server/sv_networking.lua +++ b/gamemode/engine/lib/server/sv_networking.lua @@ -59,22 +59,17 @@ local function CacheDatatableMethod( id, datatable, ply ) return { id = id, cont = datatable } end -local function shortenDataTableMethod( datatable ) - Quantum.Debug( "(" .. datatable.id .. ") Converting datatable '" .. tostring( datatable ) .. "' to json..." ) - return util.TableToJSON( datatable, false ) -end - local function initializeDatatable( id, datatable, ply ) Quantum.Debug( "(" .. tostring(ply) .. ") Initializing datatable for client net message.." ) - return shortenDataTableMethod( CacheDatatableMethod( id, datatable, ply ) ) + return CacheDatatableMethod( id, datatable, ply ) end local function SendDatatableToClient( client, dt, type ) local datatable = initializeDatatable( type, dt, client ) -- before we actually send the stuff, cache it and remove unneeded stuff local net_start = net.Start( "quantum_menu_net" ) - if( net_start ) then Quantum.Debug( "Sending net message to " .. tostring(ply) .. "..." ) end - if( #datatable > 0 ) then -- if it's empty just dont send it because we will save 8 bits - net.WriteString( datatable ) -- send the data to the player + if( net_start ) then Quantum.Debug( "Sending net message to " .. tostring(client) .. "..." ) end + if( table.Count(datatable) > 0 ) then -- if it's empty just dont send it because we will save 8 bits + net.WriteTable( datatable ) -- send the data to the player end net.Send( client ) Quantum.Debug("Net message sent.")