-
Notifications
You must be signed in to change notification settings - Fork 5
Networking
All networking API is handled through Mod.Networking.
It is instantiated as soon as the internal NetworkingManager is instantiated.
This class is instanced to your mod specifically and ensures isolation from other mods to protect compatibility.
DO NOT pass or consume references to or from other mods.
The API itself only exposes the ability to open and close virtual channels. Virtual channels act as services in other APIs and combine both listen and connect sockets. The virtual ports used for channel creation is unique to your mod and will not conflict. If you try to reopen an existing port, the original channel will be returned.
NetworkChannel exposes the features needed to communicate data between users.
Before any connection can be accepted, you must implement the ConnectionFilter delegate and add it to the OnConnection event.
To handle any data, you must add a delegate to the OnMessage event.
The other events (OnConnected, OnDisconnect, OnConnectionFailed) are optional.
To connect to a player, call NetworkChannel.Connect with the player's SteamID.
Similarly, use NetworkChannel.Disconnect to disconnect.
Use NetworkChannel.Send to send.
The SteamID and data are mandatory, but an optional fast parameter allows the use of faster, unreliable data paths such as UDP.
As of the writing of this guide, broadcasting is not implemented.
NetworkChannel.GetStatistics gets the NetworkStatistics from a given player.
This allows you to retrieve the calculated ping, packet loss, bandwidth, and pending packets (unsent for fast, unsent and unacknowledged otherwise.)
LoadingManager also has networking specific events on the host:
PlayerJoinedPlayerLeft-
PrePlayerAuthenticatingAllows mods to block players from joining before the framework performs its handshake. Does not trigger the kick system. -
PlayerAuthenticatingAllows mods to block players from joining after the framework handshake. Does not trigger the kick system.
Discovery is primarily used internally, but does expose some features.
Discovery.Players is the list of player is both connected and using the framework (the handshake succeeded.)
Discovery.Ready event is triggered when all handshakes have completed (regardless of outcome.)
Discovery.ModsAvailable event is triggered when a handshake of a given player has completed (regardless of outcome.)
Discovery.GetMods gets the mod list of a given player. It will contain at minimum AtomicFramwork if the handshake succeeded.