Skip to content

Commit

Permalink
fix: fixing server setting HasAuthority to true
Browse files Browse the repository at this point in the history
HasAuthority should not be used on server, so should always be false.
Because of the changes to syncvar sender checking HasAuthority we need to ensure that it is false on server
  • Loading branch information
James-Frowen committed May 16, 2023
1 parent 21e6a5a commit a6fa26d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Assets/Mirage/Runtime/ServerObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void ReplaceCharacter(INetworkPlayer player, NetworkIdentity identity, bo
identity.SetClientOwner(player);

// special case, we are in host mode, set hasAuthority to true so that all overrides see it
if (player == _server.LocalPlayer)
if (_server.LocalPlayer != null && player == _server.LocalPlayer)
{
identity.HasAuthority = true;
_server.LocalClient.Player.Identity = identity;
Expand Down Expand Up @@ -217,7 +217,7 @@ public void AddCharacter(INetworkPlayer player, NetworkIdentity identity)
identity.SetClientOwner(player);

// special case, we are in host mode, set hasAuthority to true so that all overrides see it
if (player == _server.LocalPlayer)
if (_server.LocalPlayer != null && player == _server.LocalPlayer)
{
identity.HasAuthority = true;
_server.LocalClient.Player.Identity = identity;
Expand Down Expand Up @@ -415,7 +415,9 @@ public void Spawn(NetworkIdentity identity)

// special case to make sure hasAuthority is set
// on start server in host mode
if (identity.Owner == _server.LocalPlayer)
// note: we need != null here, HasAuthority should never be null on server
// this is so that logic in syncvar sender works correctly
if (_server.LocalPlayer != null && identity.Owner == _server.LocalPlayer)
identity.HasAuthority = true;

if (!identity.IsSpawned)
Expand Down

0 comments on commit a6fa26d

Please sign in to comment.