Class BaseNetworkRoom
This class represents the network room.
Namespace: Evergine.Networking.Rooms
Assembly: Evergine.Networking.dll
Syntax
public abstract class BaseNetworkRoom : INetworkRoom, IRoomInfo
Constructors
BaseNetworkRoom()
Initializes a new instance of the BaseNetworkRoom class.
Declaration
protected BaseNetworkRoom()
BaseNetworkRoom(RoomOptions)
Initializes a new instance of the BaseNetworkRoom class.
Declaration
protected BaseNetworkRoom(RoomOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| RoomOptions | options | The room options for the new room. |
Fields
FirstPlayerId
Constant that defines the player ID assigned to the first player who enters the room.
Declaration
protected const int FirstPlayerId = 0
Field Value
| Type | Description |
|---|---|
| int |
internalRoomInfo
Internal room information.
Declaration
protected RoomInfo internalRoomInfo
Field Value
| Type | Description |
|---|---|
| RoomInfo |
Properties
AllPlayers
Gets the list of all the players who are in that room (including the local player). Only updated while inside a room.
Declaration
public IEnumerable<INetworkPlayer> AllPlayers { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<INetworkPlayer> |
CustomProperties
Gets the custom properties of the room. These properties are synchronized by the server automatically.
Declaration
public NetworkPropertiesTable CustomProperties { get; }
Property Value
| Type | Description |
|---|---|
| NetworkPropertiesTable |
Remarks
All players inside the room can change these properties. 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 roomProperties = matchmakingClient.CurrentRoom.CustomProperties;
roomProperties.Set((byte)CustomEnum.MapLevel, "cs_italy");
var mapLevel = roomProperties.GetString((byte)CustomEnum.MapLevel);
IsFull
Gets a value indicating whether the room is full and, therefore, no more players can join it.
Declaration
public bool IsFull { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsVisible
Gets a value indicating whether the room is listed in its lobby.
Declaration
public virtual bool IsVisible { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Rooms can be created as invisible or changed to invisible.
MasterClientId
Gets the Id of the player who is the master of this room. Note: This changes when the current master leaves the room.
Declaration
public int MasterClientId { get; protected set; }
Property Value
| Type | Description |
|---|---|
| int |
MaxPlayers
Gets the limit of players for this room. This property is shown in the lobby, too. If the room is full (player count == maxplayers), joining this room will fail.
Declaration
public virtual byte MaxPlayers { get; set; }
Property Value
| Type | Description |
|---|---|
| byte |
Remarks
If the player has joined the room, the setter will update the server and all clients.
Name
Gets the name of a room. It serves as a unique identifier for a room or match (per AppId + game version).
Declaration
public string Name { get; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
The name can't be changed once it's set by the matchmaking server.
PlayerCount
Gets the number of players currently in the room.
Declaration
public byte PlayerCount { get; }
Property Value
| Type | Description |
|---|---|
| byte |
PropertiesListedInLobby
Gets a set of string properties that are in the RoomInfo of the Lobby. This list is defined when creating the room and can't be changed afterward.
Declaration
public HashSet<string> PropertiesListedInLobby { get; }
Property Value
| Type | Description |
|---|---|
| HashSet<string> |
Remarks
You can name properties that are not set from the beginning. Those will be synchronized with the lobby when added later.
Methods
GetPlayer(int)
Tries to find the player with the given player ID. Only useful when in a room, as IDs are only valid per room.
Declaration
public INetworkPlayer GetPlayer(int playerId)
Parameters
| Type | Name | Description |
|---|---|---|
| int | playerId | Player ID of a player in this room. |
Returns
| Type | Description |
|---|---|
| INetworkPlayer | Player or null. |
InternalAddPlayer(BaseNetworkPlayer)
Internal method to add a player to the players list.
Declaration
protected void InternalAddPlayer(BaseNetworkPlayer player)
Parameters
| Type | Name | Description |
|---|---|---|
| BaseNetworkPlayer | player | The player to add. |
InternalAddPlayer(BaseNetworkPlayer, int)
Internal method to add a player to the players list.
Declaration
protected void InternalAddPlayer(BaseNetworkPlayer player, int playerId)
Parameters
| Type | Name | Description |
|---|---|---|
| BaseNetworkPlayer | player | The player to add. |
| int | playerId | The assigned player ID. |
InternalRemovePlayer(int)
Internal method to remove a player from the player list.
Declaration
protected void InternalRemovePlayer(int playerId)
Parameters
| Type | Name | Description |
|---|---|---|
| int | playerId | The player ID of the player to remove. |
OnChange(RoomFieldsFlags)
Called when one or more properties are refreshed.
Declaration
protected virtual void OnChange(BaseNetworkRoom.RoomFieldsFlags changedFields)
Parameters
| Type | Name | Description |
|---|---|---|
| BaseNetworkRoom.RoomFieldsFlags | changedFields | Flag indicating which fields have been changed. |
WriteToMessage(OutgoingMessage, RoomFieldsFlags)
Writes the specified fields to an outgoing message.
Declaration
protected void WriteToMessage(OutgoingMessage message, BaseNetworkRoom.RoomFieldsFlags includedFields)
Parameters
| Type | Name | Description |
|---|---|---|
| OutgoingMessage | message | The outgoing message. |
| BaseNetworkRoom.RoomFieldsFlags | includedFields | Indicates the fields that must be synchronized. |
Events
MasterClientIdChanged
Occurs when the master client ID changes
Declaration
public event EventHandler MasterClientIdChanged
Event Type
| Type | Description |
|---|---|
| EventHandler |