Fixed networking bugs

master
AlmTech Software 5 years ago
parent 62f0c0d1ca
commit 74d0365733
  1. 2
      gamemode/engine/derma/cl_menu.lua
  2. 13
      gamemode/engine/lib/server/sv_networking.lua

@ -15,7 +15,7 @@ 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 )
else

@ -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.")

Loading…
Cancel
Save