Advanced Simulator Authority
Last updated
Was this helpful?
Last updated
Was this helpful?
Some games require enhanced security against cheating or player griefing. This is done by giving authoritative privileges to only.
Advanced Simulator Authority is a specific feature set meant for advanced use cases. Most projects should consider simpler setups first, like or simple . This approach adds complexity, especially around object creation and error handling.
In the Project Settings section of the under Advanced Authority Config, you can select which Host Authority features are enabled for Rooms and Worlds separately, under Rooms Host Authority and Worlds Host Authority.
In the coherence , under Local Replication Server, you can select which Host Authority features are enabled for a locally run Replication Server World. If you are manually launching the Replication Server from the CLI, the --host-authority-features
parameter should be passed into the command with comma-separated dash-cased-enabled features names.
For example:
replication-server worlds --host-authority-features=create-entities,validate-connection
To select which Host Authority features are enabled for a locally run Room, you need to set SelfHostedRoomCreationOptions.HostAuthority
at Room creation time.
If any host authority feature is enabled, the Replication Server will not allow Clients to be connected without a Simulator being connected as well.
If a Client tries to connect before a Simulator, the connection will be denied with the ConnectionCloseReason.HostNotReady
.
If a Simulator disconnects, while other Clients are connected to the server, the Replication Server will forcefully disconnect all other Clients as well with the ConnectionCloseReason.HostDisconnected
.
The HostAuthority.CreateEntities
feature is used to only allow Simulators to create entities. Once created, these entities can have their state authority transferred and their lifetime managed by non-simulators, but no Client is allowed to create entities while this restriction is active.
By default, all CoherenceSyncs have set to "Steal". This means that malicious players could steal the authority of any entity and break the game.
Instead of manually changing the AuthorityTransferType on every new CoherenceSync, you can change the default value of it in the coherence . See .
The HostAuthority.ValidateConnection
feature is used to restrict who can connect to a World or a Room. Upon enabling this feature, the connected Simulator will receive a validation request on every connection attempt from a Client. The connection is allowed only if the Simulator responds with the accepted validation response.
To handle the connection validation requests, the Simulator can subscribe to CoherenceBridge.onValidateConnectionRequest
. To respond to the validation request, call Respond()
on the ConnectionValidationRequest
provided, passing in the validation response:
Before initiating the connection, the user can set an optional custom user payload which will be sent to the Simulator for validation. The payload is of type byte[]
, and can contain an access token or any other data. To send the payload for validation, you must set it before initiating the connection:
When responding to a connection validation request, the Simulator can also send a custom payload back to the user. This is done by passing the payload to the ConnectionValidationResponse
when calling the Respond()
method.
The payload size is limited to 512 bytes.
The Client can access the payload sent by the Simulator depending if the connection validation was accepted or rejected:
A Simulator can forcefully disconnect other Clients by kicking them. When kicking a Client, the Simulator can also send an optional host payload of type byte[]
which will be sent to the kicked Client, together with the ConnectionCloseReason.KickedByHost
.
It is sometimes useful for the client creating a room to pass information to the Simulator handling that room. If the information is public and can be seen by other clients, using room Tags or a Key-Value dictionary is the best way to pass it.
If, however, the information is secret and should be known only to the Simulator, then we can use the Simulator Payload:
With entity creation restriction enabled, the CoherenceSyncs that have the option set to Client Side or Server Side With Client Input and are spawned by a Client will automatically get destroyed. The ones set to Server Side will just get disabled.
Simulator can still use any of the available options. Client Side works the same as Server Side and has no effect on the Simulator-side entities, while the Server Side With Client Input should be used together with .
By default, when are active, the will automatically create a global query entity on behalf of the Client. If the Client is not authorized to create entities, this results in an error on the Replication Server indicating that an entity creation was rejected. To avoid these error logs, the auto creation of the global query can be disabled in the CoherenceBridge configuration:
as part of a prefab by using the component. This prefab can then be transferred to other clients from the simulator to give those clients access to the global client connections.
If the Simulator rejects the connection, the Client will receive a with the ConnectionCloseReason.ConnectionRejectedByHost
.
If the connection was accepted, the payload can be accessed by calling the function GetValidatedHostPayload()
after the connection was established.
Or, if the connection was rejected, the payload is contained inside the together with the ConnectionCloseReason.ConnectionRejectedByHost
.
This feature is also available for Worlds. The payload can be set via , in the World configurator (Simulator configuration -> Optional simulator payload).
The system is not fully operable when entity creation restriction is enabled. While connections will be registered and their ClientIDs are available, the Client connection objects' state won't be synced and no commands can be sent for those objects. This applies only to the client-side connection objects. This limitation is slated to be removed in the future.