Network Library
Network communication and data streaming system for the Lilia framework.
Overview
The network library provides comprehensive functionality for managing network communication in the Lilia framework. It handles both simple message passing and complex data streaming between server and client. The library includes support for registering network message handlers, sending messages to specific targets or broadcasting to all clients, and managing large data transfers through chunked streaming. It also provides global variable synchronization across the network, allowing server-side variables to be automatically synchronized with clients. The library operates on both server and client sides, with server handling message broadcasting and client handling message reception and acknowledgment.
lia.net.isCacheHit(name, args)
Determine if a net payload with given args is still fresh in cache.
Before sending large net payloads to avoid duplicate work.
Parameters:
string name Cache identifier.table args Arguments that define cache identity.
Returns:
boolean true if cached entry exists within TTL.Example Usage:
if not lia.net.isCacheHit("bigSync", {ply:SteamID64()}) then
lia.net.writeBigTable(ply, "liaBigSync", payload)
lia.net.addToCache("bigSync", {ply:SteamID64()})
end
lia.net.addToCache(name, args)
Insert a cache marker for a named payload/args combination.
Right after sending a large or expensive net payload.
Parameters:
string name Cache identifier.table args Arguments that define cache identity.
Example Usage:
lia.net.writeBigTable(targets, "liaDialogSync", data)
lia.net.addToCache("dialogSync", {table.Count(data)})
lia.net.readBigTable(netStr, callback)
Receive chunked JSON-compressed tables and reconstruct them.
To register a receiver for big table streams (both realms).
Parameters:
string netStr Net message name carrying the chunks.function callback Function called when table is fully received. Client: function(tbl), Server: function(ply, tbl).
Example Usage:
lia.net.readBigTable("liaDoorDataBulk", function(tbl)
if not tbl then return end
for doorID, data in pairs(tbl) do
lia.doors.updateCachedData(doorID, data)
end
end)
lia.net.writeBigTable(targets, netStr, tbl, chunkSize)
Send a large table by compressing and chunking it across the net.
For big payloads (dialog sync, door data, keybinds) that exceed net limits.
Parameters:
Player|table targets optional Single player, list of players, or nil to broadcast to humans.string netStr Net message name to use.
table tbl Data to serialize.
number chunkSize optional Optional override for chunk size.
Example Usage:
local payload = {doors = lia.doors.stored, ts = os.time()}
lia.net.writeBigTable(player.GetHumans(), "liaDoorDataBulk", payload, 2048)
lia.net.addToCache("doorBulk", {payload.ts})
lia.net.checkBadType(name, object)
Validate netvar payloads to prevent functions being networked.
Internally before setting globals/locals.
Parameters:
string name Identifier for error reporting.any object Value to validate for networking safety.
Returns:
boolean|nil true if bad type detected.Example Usage:
if lia.net.checkBadType("example", someTable) then return end
lia.net.setNetVar(key, value, receiver)
Set a global netvar and broadcast it (or send to specific receiver).
Whenever shared state changes (config sync, feature flags, etc.).
Parameters:
string key Netvar identifier.any value Value to set.
Player|table receiver optional Optional target(s); broadcasts when nil.
Example Usage:
lia.net.setNetVar("eventActive", true)
lia.net.setNetVar("roundNumber", round, targetPlayers)
lia.net.getNetVar(key, default)
Retrieve a global netvar with a fallback default.
Client/server code reading synchronized state.
Parameters:
string key Netvar identifier.any default Fallback value if netvar is not set.
Returns:
anyExample Usage:
if lia.net.getNetVar("eventActive", false) then
DrawEventHUD()
end