menu_bookDocumentation

Connection Class: Local, Host, All, Find, Permissions, Kicking, and Visibility Origins

calendar_today May 4, 2026 schedule ~1 min read person patrickjr verified 50

Connection Class: Local, Host, All, Find, and Permissions

Connection represents a network connection to a player. It's the primary way to identify and interact with players in s&box.

Key Static Properties

CSHARP
Connection.Local   // the local player's connection (always valid, even offline)
Connection.Host    // the host's connection (= Local if you are the host)
Connection.All     // all connected players (includes Local if offline)

Finding Connections

CSHARP
// Find by Guid
var conn = Connection.Find( someGuid );

// Find by SteamId (manual search)
var conn = Connection.All.FirstOrDefault( c => c.SteamId == steamId );

Connection Properties

CSHARP
conn.Id            // Guid — unique connection identifier
conn.DisplayName   // player's display name
conn.SteamId       // player's SteamId
conn.PartyId       // SteamId of the party this player is in
conn.IsHost        // true if this is the host connection
conn.IsActive      // true if fully connected
conn.IsConnecting  // true if still connecting
conn.Ping          // round-trip latency in milliseconds
conn.Latency       // one-way latency
conn.Stats         // ConnectionStats (bandwidth, ping)
conn.ConnectionTime // when this player connected

Permissions (Host Only)

CSHARP
// Control what a connection can do (host only)
conn.CanSpawnObjects = true;   // can call NetworkSpawn
conn.CanRefreshObjects = true; // can call Network.Refresh
conn.CanDestroyObjects = true; // can destroy their own networked objects

Kicking

CSHARP
// Kick a player (host only)
conn.Kick( "Cheating" );

Sending Messages

CSHARP
// Send a typed message to a specific connection
conn.SendMessage( new MyMessage { Data = "hello" } );

// Send a log message to a connection's console
conn.SendLog( LogLevel.Info, "You have been warned" );

User Data

CSHARP
// Get user data (set via [ConVar( ConVarFlags.UserInfo )])
string value = conn.GetUserData( "my_convar" );

Visibility Origins

Connection.VisibilityOrigins is an array of world positions representing where this player can "see" from. Used for network culling. Updated each tick from the client's camera position.
CSHARP
// Distance from a connection's visibility origins to a position
float distSq = conn.DistanceSquared( worldPosition );

MockConnection

When a player is known (via connection info) but not directly connected (e.g., on a different client), Connection.Find returns a MockConnection. This is a lightweight proxy that holds the connection info but cannot send messages directly.

Was this helpful?