Interface INetworkPlayer
This interface 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 might change his 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 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 only valid in that context. It will change even on leave and re-join. Ids are never re-used per 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 "authoritative" client/player to make decisions, run AI or other. If the current Master Client leaves the room (leave/disconnect), 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 his own nickname in a room. Setting this value updates the server and other players.
Room
Gets the room where is the player. 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 that's useful to know "by player". This property is not sync 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 custom properties.
Declaration
event EventHandler OnCustomPropertiesChanged
Event Type
Type | Description |
---|---|
EventHandler |
OnNicknameChanged
Event raised when the server updates the player nickname.
Declaration
event EventHandler OnNicknameChanged
Event Type
Type | Description |
---|---|
EventHandler |