Search Results for

    Show / Hide Table of Contents

    Class BaseNetworkPlayer

    Base class for network players.

    Inheritance
    object
    BaseNetworkPlayer
    RemoteNetworkPlayer
    BaseSyncNetworkPlayer
    Implements
    INetworkPlayer
    Namespace: Evergine.Networking.Players
    Assembly: Evergine.Networking.dll
    Syntax
    public abstract class BaseNetworkPlayer : INetworkPlayer

    Constructors

    BaseNetworkPlayer(bool)

    Initializes a new instance of the BaseNetworkPlayer class.

    Declaration
    public BaseNetworkPlayer(bool hasReadOnlyProperties)
    Parameters
    Type Name Description
    bool hasReadOnlyProperties

    Indicates whether the custom properties of the player are read-only.

    Properties

    CustomProperties

    Gets the custom properties of the player. Those properties are synchronized by the server automatically.

    Declaration
    public 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
    public 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
    public bool IsInLobby { get; }
    Property Value
    Type Description
    bool

    IsLocalPlayer

    Gets a value indicating whether this player is the local player.

    Declaration
    public 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
    public 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
    public string Nickname { get; protected set; }
    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
    public 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
    public object TagObject { get; set; }
    Property Value
    Type Description
    object
    Remarks

    Example: Set a player's character as Tag by assigning its Entity or EntityPath.

    Methods

    WriteToMessage(OutgoingMessage, PlayerFliedsFlags)

    Writes the specified fields to an outgoing message.

    Declaration
    protected void WriteToMessage(OutgoingMessage message, BaseNetworkPlayer.PlayerFliedsFlags includedFields)
    Parameters
    Type Name Description
    OutgoingMessage message

    The outgoing message.

    BaseNetworkPlayer.PlayerFliedsFlags includedFields

    Indicates the fields that must be synchronized.

    Events

    OnCustomPropertiesChanged

    Event raised when the server updates the custom properties.

    Declaration
    public event EventHandler OnCustomPropertiesChanged
    Event Type
    Type Description
    EventHandler

    OnNicknameChanged

    Event raised when the server updates a player's nickname.

    Declaration
    public event EventHandler OnNicknameChanged
    Event Type
    Type Description
    EventHandler

    Implements

    INetworkPlayer

    Extension Methods

    ReflectionHelper.GetMemberAssembly(object)
    ReflectionHelper.GetTypeName(object)
    In this article
    Back to top
    Generated by DocFX