API ReferenceSandbox.Network

GameNetworkSystemclass

An instance of this is created by the NetworkSystem when a server is joined, or created. You should not try to create this manually.

object→GameNetworkSystem
Namespace
Sandbox.Network
Assembly
Sandbox.Engine
Declaration
public abstract class Sandbox.Network.GameNetworkSystem

Constructors1

Showing 1 constructors

Methods28

Showing 28 methods

public virtual bool AcceptConnection(Sandbox.Connection channel, string reason)PUBLICVIRTUAL

Called on the host to decide whether to accept a `Sandbox.Connection`.

ParameterTypeDescription
channelConnection—
reasonstringThe reason to display to the client.
Returns:bool—

public virtual System.Threading.Tasks.Task BecomeHostAsync(Sandbox.Connection previousHost, Sandbox.Network.SnapshotMsg snapshot)PUBLICVIRTUAL

We're already the host; load the previous host's snapshot.

ParameterTypeDescription
previousHostConnection—
snapshotSnapshotMsg—
Returns:Task—

public void Broadcast(T obj, System.Nullable`1<Sandbox.Connection.Filter> filter = null)PUBLIC

ParameterTypeDescription
objT—
filter = nullNullable<Filter>—
Returns:void—

public void BroadcastRaw(Sandbox.ByteStream msg, System.Nullable`1<Sandbox.Connection.Filter> filter = null)PUBLIC

ParameterTypeDescription
msgByteStream—
filter = nullNullable<Filter>—
Returns:void—

public static void CreateLobby()PUBLICSTATICOBSOLETE

Obsolete: Moved to Networking.CreateLobby

Returns:void—

public static void Disconnect()PUBLICSTATICOBSOLETE

Obsolete: Moved to Networking.Disconnect

Returns:void—

public virtual void Dispose()PUBLICVIRTUAL

Returns:void—

public virtual void OnBecameHost(Sandbox.Connection previousHost)PUBLICVIRTUAL

Legacy host-change callback. Override BecomeHostAsync to apply the handoff snapshot. The default BecomeHostAsync implementation calls this for existing subclasses.

ParameterTypeDescription
previousHostConnection—
Returns:void—

public virtual void OnConnected(Sandbox.Connection client)PUBLICVIRTUAL

A client has connected to the server but hasn't fully finished joining yet.

ParameterTypeDescription
clientConnection—
Returns:void—

public virtual void OnHostChanged(Sandbox.Connection previousHost, Sandbox.Connection newHost)PUBLICVIRTUAL

Legacy host-change callback. Override ResyncFromHostAsync to apply the new host's snapshot. The default ResyncFromHostAsync implementation calls this for existing subclasses.

ParameterTypeDescription
previousHostConnection—
newHostConnection—
Returns:void—

public virtual void OnInitialize()PUBLICVIRTUAL

Called when the network system should handle initialization.

Returns:void—

public virtual void OnJoined(Sandbox.Connection client)PUBLICVIRTUAL

Fully joined the server. Can be called when changing the map too. The game should usually create some object for the player to control here.

ParameterTypeDescription
clientConnection—
Returns:void—

public virtual void OnLeave(Sandbox.Connection client)PUBLICVIRTUAL

A client has disconnected from the server.

ParameterTypeDescription
clientConnection—
Returns:void—

public virtual System.IDisposable Push()PUBLICVIRTUAL

Allows to push some kind of scope when reading network messages. This is useful if you need to adjust Time.Now etc.

Returns:IDisposable—

public static System.Threading.Tasks.Task`1<System.Collections.Generic.List`1<Sandbox.Network.LobbyInformation>> QueryLobbies()PUBLICSTATICOBSOLETE

Obsolete: Moved to Networking.QueryLobbies

Returns:Task<List<LobbyInformation>>—

public void Send(System.Guid connectionId, T obj)PUBLIC

ParameterTypeDescription
connectionIdGuid—
objT—
Returns:void—

public virtual System.Threading.Tasks.Task SetSnapshotAsync(Sandbox.Network.SnapshotMsg data)PUBLICVIRTUAL

ParameterTypeDescription
dataSnapshotMsg—
Returns:Task—

protected virtual void Tick()PROTECTEDVIRTUAL

Called every frame

Returns:void—

public static System.Threading.Tasks.Task`1<bool> TryConnectSteamId(ulong steamId)PUBLICSTATICOBSOLETE

Obsolete: Moved to Networking.Connect

ParameterTypeDescription
steamIdulong—
Returns:Task<bool>—

Properties4

Showing 4 properties

public static bool Sandbox.Network.GameNetworkSystem.IsActive { get; set; }PUBLICSTATICGETSETOBSOLETE

True if we're currently connected etc

Obsolete: Moved to Networking.IsActive

Returns:bool—

public static bool Sandbox.Network.GameNetworkSystem.IsClient { get; set; }PUBLICSTATICGETSETOBSOLETE

True if we're connected to a server and not the host.

Obsolete: Moved to Networking.IsClient

Returns:bool—

public static bool Sandbox.Network.GameNetworkSystem.IsConnecting { get; set; }PUBLICSTATICGETSETOBSOLETE

True if we're currently connecting to the server

Obsolete: Moved to Networking.IsConnecting

Returns:bool—

public static bool Sandbox.Network.GameNetworkSystem.IsHost { get; set; }PUBLICSTATICGETSETOBSOLETE

True if we can be considered the host of this session. Either we're not connected to a server, or we are and we are the host.

Obsolete: Moved to Networking.IsHost

Returns:bool—

On this page

Constructorspublic GameNetworkSystem()Methodspublic virtual System.Boolean AcceptConnection(Sandbox.Connection channel, System.String reason)public System.Void AddHandler(System.Action`2<T,Sandbox.Connection> handler)public System.Void AddHandler(System.Action`3<T,Sandbox.Connection,System.Guid> handler)public System.Void AddHandler(System.Func`4<T,Sandbox.Connection,System.Guid,System.Threading.Tasks.Task> handler)public virtual System.Threading.Tasks.Task BecomeHostAsync(Sandbox.Connection previousHost, Sandbox.Network.SnapshotMsg snapshot)public System.Void Broadcast(T obj, System.Nullable`1<Sandbox.Connection.Filter> filter = null)public System.Void BroadcastRaw(Sandbox.ByteStream msg, System.Nullable`1<Sandbox.Connection.Filter> filter = null)public static System.Void Connect(System.String target)public static System.Void Connect(System.UInt64 steamid)public static System.Void CreateLobby()public static System.Void Disconnect()public virtual System.Void Dispose()public virtual System.Void GetMountedVPKs(Sandbox.Connection source, Sandbox.Network.MountedVPKsResponse msg)public virtual System.Void GetSnapshot(Sandbox.Connection source, Sandbox.Network.SnapshotMsg msg)public virtual System.Threading.Tasks.Task MountVPKs(Sandbox.Connection source, Sandbox.Network.MountedVPKsResponse msg)public virtual System.Void OnBecameHost(Sandbox.Connection previousHost)public virtual System.Void OnConnected(Sandbox.Connection client)public virtual System.Void OnHostChanged(Sandbox.Connection previousHost, Sandbox.Connection newHost)public virtual System.Void OnInitialize()public virtual System.Void OnJoined(Sandbox.Connection client)public virtual System.Void OnLeave(Sandbox.Connection client)public virtual System.IDisposable Push()public static System.Threading.Tasks.Task`1<System.Collections.Generic.List`1<Sandbox.Network.LobbyInformation>> QueryLobbies()public virtual System.Threading.Tasks.Task ResyncFromHostAsync(Sandbox.Connection previousHost, Sandbox.Connection newHost, Sandbox.Network.SnapshotMsg snapshot)public System.Void Send(System.Guid connectionId, T obj)public virtual System.Threading.Tasks.Task SetSnapshotAsync(Sandbox.Network.SnapshotMsg data)protected virtual System.Void Tick()public static System.Threading.Tasks.Task`1<System.Boolean> TryConnectSteamId(System.UInt64 steamId)Propertiespublic static System.Boolean Sandbox.Network.GameNetworkSystem.IsActive { get; set; }public static System.Boolean Sandbox.Network.GameNetworkSystem.IsClient { get; set; }public static System.Boolean Sandbox.Network.GameNetworkSystem.IsConnecting { get; set; }public static System.Boolean Sandbox.Network.GameNetworkSystem.IsHost { get; set; }Metadata