Conceitos de Autoridade
Tudo o que você precisa saber sobre os conceitos de Autoridade & Autoridade de Rede.
Autoridade
Algumas Classes só podem ser geradas no servidor, outras só podem ser geradas no Cliente, e há alguns que podem ser gerados no Servidor ou Cliente. O lado que a Classe é gerada é chamado de Autoridade.
Methods and Events Availability
Alguns métodos e eventos na API só estão disponíveis em um lado específico (Cliente ou Servidor), outros estão disponíveis apenas no lado que gerou o lado de autoridade):
Lado do servidor
Método ou eventos que só podem ser chamados pelo lado do servidor.
Lado do Cliente
Métodos ou eventos que só podem ser chamados no lado do Cliente.
Lado de Autoridade
Métodos ou eventos que só podem ser chamados pelo lado que o geraram.
Network Authority Side
Methods or Events which can be called in the Server and also in the Client if the Local Player is the Network Authority of that entity.
Both Sides
Methods or Events which can only be called in any side.
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.
Autoridade de rede
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:
- A distância **** do personagem ao objeto
- If the Character is grabbing a Prop
- If the Character is handling a Base Pickable
- Se o personagem é dirigindo um veículo
- Se o Personagem apenas tirou algo
In all this cases, the Player will be automatically assigned to be the Network Authority of that Object.
Sobrescrevendo a autoridade de rede atual
It is possible to override the current Network Authority of a specific entity by using the method :SetNetworkAuthority()
.
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)
.
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
- Física de Objetos sincronizados (incluindo ao chamar
:SetForce()
). - NPCs walking with
:MoveTo()
or:Follow()
.
Debugging Network & Network Authority
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.
Color | Meaning |
---|---|
BLUE | You are the current Network Authority of that entity. You are sharing sync data to the other players. |
WHITE | You are not the Network Authority and the entity is sleeping. The current Network Authority is not sending sync data because the entity is sleeping. |
BLACK | You are the Authority of that entity. The entity was spawned on client side then you are not sending sync data. |
GREEN | You are not the Network Authority and the entity is being synced in a good cadence (no lag). |
ORANGE | You are not the Network Authority and the entity is being synced in an ok cadence (small lag - < 100ms). |
RED | You are not the Network Authority and the entity is being synced in an bad cadence (big lag - > 100ms, 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.
Color | Meaning |
---|---|
GREEN | The entity is being synced in a good cadence (no lag). |
ORANGE | The entity is being synced in an ok cadence (small lag - < 100ms). |
RED | The entity is being synced in an bad cadence (big lag - > 100ms, maybe even with packet loss). |