Passer au contenu principal
Version: bleeding-edge 🩸

Authority Concepts

Tout ce que vous avez besoin de savoir sur les concepts d'autorité et d'autorité de réseau.

Autorité

Certaines classes ne peuvent être créées que par le serveur, d'autres ne peuvent être créées que par le client, et il y en a quelques-unes qui peuvent être créées à la fois par le serveur ou par le client. Le côté où la Classe est créée est appelé Autorité.

Disponibilité des méthodes et des événements

Certaines méthodes et événements dans l'API ne sont disponibles que sur un côté spécifique \(Client ou Serveur\), les autres ne sont disponibles que dans le côté qui a l'autorité):

Côté Serveur

  • Methods: can be called only in the Server side.
  • Events: will be triggered only in the Server side.

Côté Client

  • Methods: can be called only in the Client side.
  • Events: will be triggered only in the Client side.

Côté Autorité

  • Methods: can be called only in the side which spawned this entity.
  • Events: will be triggered only in the side which spawned this entity.

Network Authority Side

  • Methods: can be called only in the Server side and also in the Client if the Local Player is the Network Authority of this entity.
  • Events: will be triggered only in the Server side and also in the Client if the Local Player is the Network Authority of this entity.

Both Sides

  • Methods: can be called in both Server and Client side.
  • Events: will be triggered in both Server and Client side.

Both Sides (Network. Authority First)

  • Methods: Does only apply to Events.
  • Events: will be triggered in both Server and Client side. But will be called in the Network Authority Client first (before sending to the Server). I.e. you don't need to wait for the Server to call it on all the clients, as it will be immediately called on the Client that is the Network Authority of that entity.
tip

All entities spawned in the Server will be automatically synced in the Client. I.e. you can access it's methods and get all data from it without needing to manually sync it.

In the same way, entities spawned in the Client will only exist for that Client, trying to send those entities to the server will cause errors.

Autorité Réseau

Another important concept in nanos world is the Network Authority. We have a "distributed network authority" concept, which means the work of calculating physics and AI (for example) are automatically assigned and distributed to the clients. In general, if a Base Actor is near an in-game Character, it's physics will be calculated by that player's device. The Player that is responsible for calculating and sharing the results is called Network Authority.

The Player assigned is automatically calculated by the server and takes some things into consideration, this calculation is only made if the Player is possessing a Character:

  • La distance entre le Personnage et l'objet
  • Si le Personnage saisit un objet Prop
  • If the Character is handling a Base Pickable
  • If the Character is driving a Base Vehicle
  • If the Character has just shot an entity (e.g. Prop, Weapon, Base Vehicle, etc)
  • If the Character has just roamed a Character with a Vehicle

In all this cases, the Player will be automatically assigned to be the Network Authority of that Object.

Outrepasser l'Autorité Réseau actuelle

It is possible to override the current Network Authority of a specific entity by using the method :SetNetworkAuthority().

tip

Under certain circumstances, actors may not be in Distributed Network Authority mode. This means they cannot have their current network authority changed. Example: if a player is driving a Vehicle or using a Weapon, mandatorily he is the the Vehicle and Weapons's Network Authority, and this cannot be overwritten through scripting. To validate if an Actor can have it overridden, you can use the method :IsNetworkDistributed().

You can also prevent it from being automatically distributed to other Players by calling :SetNetworkAuthorityAutoDistributed(false).

attention

Always remember to restore the automatic Network Authority Distribution by calling :SetNetworkAuthorityAutoDistributed(true). Otherwise that entity may behave completely weird.

Examples of actions that are only executed by the Network Authority of that Actor

Débogage du Réseau & de l'Autorité Réseau

We've added a new option in the settings to Draw Network Debug information in the World, you can toggle it in the settings (Settings -> Debug -> Draw Network Debug), it will draw squares on each entity and traces representing their networked movement.

Entity Square ■ Colors Meaning

The Square in the entities represent the state in the Network Authority and it's health.

CouleurMeaning
BLUEYou are the current Network Authority of that entity and the entity is sleeping.
You are sharing sync data to the other players.
CYANYou are the current Network Authority of that entity and the you are currently transmitting data.
You are sharing sync data to the other players.
MAGENTAYou are the Authority of that entity.
The entity was spawned on client side then you are not sending sync data.
WHITEYou are not the Network Authority and the entity is sleeping or attached.
The current Network Authority is not sending sync data because the entity is sleeping or attached.
GREENYou are not the Network Authority and the entity is being synced in a perfect cadence (no lag - less than 2 frames - < 66ms).
YELLOWYou are not the Network Authority and the entity is being synced in an good cadence (small lag - less than 4 frames - < 132ms).
ORANGEYou are not the Network Authority and the entity is being synced in an ok cadence (average lag - less than 6 frames - < 198ms).
REDYou are not the Network Authority and the entity is being synced in an bad cadence (big lag - more than 6 frames - > 198ms, maybe even with packet loss).
BLACKYou are not the Network Authority and the entity is skipping packets received from the network, due they are coming in wrong order (cause of bad connection - maybe even with packet loss).

Entity Arrow → Traces Colors Meaning

The Arrow Traces in the entities represent the network data received from the server. If you are the network authority you won't see the arrow traces. The arrow points from where the entity is currently in your machine and where it should be accordingly to the network authority.

CouleurMeaning
GREENThe entity is receiving packets in a perfect cadence (no more than 2 frames delay).
YELLOWThe entity does not receive any packet for more than 2 and less than 4 frames.
ORANGEThe entity does not receive any packet for more than 4 and less than 6 frames.
REDThe entity does not receive any packet for more than 6 frames.