Interface INetworkPlayer
Defines a network player.
Namespace: Evergine.Networking.Players
Assembly: Evergine.Networking.dll
Syntax
public interface INetworkPlayer
Properties
CustomProperties
Gets the custom properties of the player. Those properties are synchronized by the server automatically.
Declaration
NetworkPropertiesTable CustomProperties { get; }
Property Value
Type | Description |
---|---|
NetworkPropertiesTable |
Remarks
Only the local player may change their own custom properties in a room. Setting properties in this table updates the server and other players.
Keys in the table are bytes to reduce network traffic. It is recommended to use a custom enumerator for better clarity.
Examples
var matchmakingClient = Evergine.GetService<MatchmakingClientService>();
var playerProperties = matchmakingClient.LocalPlayer.CustomProperties;
playerProperties.Set((byte)CustomEnum.PlayerPosition, Vector3.Zero);
var position = playerProperties.GetVector3((byte)CustomEnum.PlayerPosition);
Id
Gets an identifier of this player in the current room. It's -1 outside of rooms.
Declaration
int Id { get; }
Property Value
Type | Description |
---|---|
int |
Remarks
The Id is assigned per room and is only valid in that context. It will change upon leaving and re-joining. Ids are never re-used within a room.
IsInLobby
Gets a value indicating whether this player is in the lobby (not in a room).
Declaration
bool IsInLobby { get; }
Property Value
Type | Description |
---|---|
bool |
IsLocalPlayer
Gets a value indicating whether this player is the local player.
Declaration
bool IsLocalPlayer { get; }
Property Value
Type | Description |
---|---|
bool |
IsMasterClient
Gets a value indicating whether this player is the Master Client of the current room or not.
Declaration
bool IsMasterClient { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Can be used as an "authoritative" client/player to make decisions, run AI, or other tasks. If the current Master Client leaves the room (leaves/disconnects), the server will quickly assign someone else. If the current Master Client times out (closed app, lost connection, etc.), messages sent to this client are effectively lost for the others.
Nickname
Gets a non-unique nickname of this player. Synced automatically in a room.
Declaration
string Nickname { get; }
Property Value
Type | Description |
---|---|
string |
Remarks
A player might change their own nickname in a room. Setting this value updates the server and other players.
Room
Gets the room where the player is. It is null if the player is in the lobby.
Declaration
INetworkRoom Room { get; }
Property Value
Type | Description |
---|---|
INetworkRoom |
TagObject
Gets or sets an object that can be used to store a reference useful for knowing "by player". This property is not synchronized by the server.
Declaration
object TagObject { get; set; }
Property Value
Type | Description |
---|---|
object |
Remarks
Example: Set a player's character as Tag by assigning its Entity or EntityPath.
Events
OnCustomPropertiesChanged
Event raised when the server updates the custom properties.
Declaration
event EventHandler OnCustomPropertiesChanged
Event Type
Type | Description |
---|---|
EventHandler |
OnNicknameChanged
Event raised when the server updates a player's nickname.
Declaration
event EventHandler OnNicknameChanged
Event Type
Type | Description |
---|---|
EventHandler |