VERGELua API

NetChannel

The net channel: latency, loss, and connection details.

nc:IsNull():boolean

Whether the channel is null.

nc:GetName():string

Channel name.

nc:GetAddress():string

Remote address string.

nc:GetConnectTime():number

Time the connection was established.

nc:GetTimeSinceLastReceived():number

Seconds since the last received packet.

nc:GetLatency(flow:number):number

Latency in seconds; flow 0 = incoming, 1 = outgoing.

nc:GetAvgLatency(flow:number):number

Average latency; flow 0 = incoming, 1 = outgoing.

nc:GetAvgChoke(flow:number):number

Average choke; flow 0 = incoming, 1 = outgoing.

nc:GetAvgLoss(flow:number):number

Average loss; flow 0 = incoming, 1 = outgoing.

nc:GetAvgData(flow:number):number

Average data rate; flow 0 = incoming, 1 = outgoing.

nc:GetTime():number

Current time on the channel.

nc:GetTimeConnected():number

Seconds since the connection started.

nc:GetBufferSize():number

Current buffer size in bytes.

nc:GetDataRate():number

Maximum data rate in bytes per second.

nc:IsLoopback():boolean

Whether the channel is a loopback connection.

nc:IsTimingOut():boolean

Whether the channel is timing out.

nc:IsPlayback():boolean

Whether the channel is in playback mode.

nc:SetDataRate(rate:number)

Set the maximum data rate.

nc:SetTimeout(t:number)

Set the connection timeout in seconds.

nc:SetChallengeNr(nr:number)

Set the challenge number.

nc:GetChallengeNr():number

Current challenge number.

nc:GetSequenceData():number, number, number

Incoming sequence state (inRelState, inNr, inStreamSeqNr).

nc:SetSequenceData(a:number, b:number, c:number)

Set the incoming sequence state.

nc:SetInterpolationAmount(amt:number)

Set the interpolation amount.

nc:SendData(buffer:BitBuffer, reliable:boolean):boolean

Send a bit buffer over the channel.

Examples

Ping / choke / loss HUD

Reads the live net channel to draw ping, choke and loss in a corner.

callbacks.Register("Draw", function()
    local nc = clientstate.GetNetChannel()
    if not nc or nc:IsNull() then return end

    -- flow 0 = incoming, 1 = outgoing; latency is in seconds
    local ping = (nc:GetLatency(0) + nc:GetLatency(1)) * 1000
    draw.Color(255, 255, 255, 255)
    draw.Text(10, 46, string.format("ping %.0fms  choke %.1f%%  loss %.1f%%",
        ping, nc:GetAvgChoke(1) * 100, nc:GetAvgLoss(1) * 100))
end)

Connection details

Prints the server address and connection time once, right after joining.

local printed = false

callbacks.Register("Draw", function()
    if printed then return end
    local nc = clientstate.GetNetChannel()
    if not nc or nc:IsNull() then return end

    printed = true
    print("server:", nc:GetAddress())
    print("loopback:", tostring(nc:IsLoopback()))
    print("connected for:", string.format("%.1fs", nc:GetTimeConnected()))
end)