mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Set client owner before we send spawn messages
This commit is contained in:
parent
8d98c2983e
commit
31b3035de1
@ -740,10 +740,6 @@ static internal bool InternalAddPlayerForConnection(NetworkConnection conn, Game
|
|||||||
if (LogFilter.logDebug) { Debug.Log("Adding new playerGameObject object netId: " + playerGameObject.GetComponent<NetworkIdentity>().netId + " asset ID " + playerGameObject.GetComponent<NetworkIdentity>().assetId); }
|
if (LogFilter.logDebug) { Debug.Log("Adding new playerGameObject object netId: " + playerGameObject.GetComponent<NetworkIdentity>().netId + " asset ID " + playerGameObject.GetComponent<NetworkIdentity>().assetId); }
|
||||||
|
|
||||||
FinishPlayerForConnection(conn, playerNetworkIdentity, playerGameObject);
|
FinishPlayerForConnection(conn, playerNetworkIdentity, playerGameObject);
|
||||||
if (playerNetworkIdentity.localPlayerAuthority)
|
|
||||||
{
|
|
||||||
playerNetworkIdentity.SetClientOwner(conn);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -782,12 +778,17 @@ static bool SetupLocalPlayerForConnection(NetworkConnection conn, NetworkIdentit
|
|||||||
// so dont spawn it again.
|
// so dont spawn it again.
|
||||||
uv.OnStartServer(true);
|
uv.OnStartServer(true);
|
||||||
}
|
}
|
||||||
|
// paul: The owner must be set before we rebuild observers
|
||||||
|
// during rebuild observers spawn messages might be sent
|
||||||
|
//and if we don't have the owner, we won't receive owner data
|
||||||
|
uv.SetClientOwner(conn);
|
||||||
|
|
||||||
uv.RebuildObservers(true);
|
uv.RebuildObservers(true);
|
||||||
SendSpawnMessage(uv, null);
|
SendSpawnMessage(uv, null);
|
||||||
|
|
||||||
// Set up local player instance on the client instance and update local object map
|
// Set up local player instance on the client instance and update local object map
|
||||||
localConnection.localClient.AddLocalPlayer(newPlayerController);
|
localConnection.localClient.AddLocalPlayer(newPlayerController);
|
||||||
uv.SetClientOwner(conn);
|
|
||||||
|
|
||||||
// Trigger OnAuthority
|
// Trigger OnAuthority
|
||||||
uv.ForceAuthority(true);
|
uv.ForceAuthority(true);
|
||||||
@ -805,7 +806,7 @@ static void FinishPlayerForConnection(NetworkConnection conn, NetworkIdentity uv
|
|||||||
{
|
{
|
||||||
// it is allowed to provide an already spawned object as the new player object.
|
// it is allowed to provide an already spawned object as the new player object.
|
||||||
// so dont spawn it again.
|
// so dont spawn it again.
|
||||||
Spawn(playerGameObject);
|
Spawn(playerGameObject, conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnerMessage owner = new OwnerMessage();
|
OwnerMessage owner = new OwnerMessage();
|
||||||
@ -855,10 +856,6 @@ static internal bool InternalReplacePlayerForConnection(NetworkConnection conn,
|
|||||||
if (LogFilter.logDebug) { Debug.Log("Replacing playerGameObject object netId: " + playerGameObject.GetComponent<NetworkIdentity>().netId + " asset ID " + playerGameObject.GetComponent<NetworkIdentity>().assetId); }
|
if (LogFilter.logDebug) { Debug.Log("Replacing playerGameObject object netId: " + playerGameObject.GetComponent<NetworkIdentity>().netId + " asset ID " + playerGameObject.GetComponent<NetworkIdentity>().assetId); }
|
||||||
|
|
||||||
FinishPlayerForConnection(conn, playerNetworkIdentity, playerGameObject);
|
FinishPlayerForConnection(conn, playerNetworkIdentity, playerGameObject);
|
||||||
if (playerNetworkIdentity.localPlayerAuthority)
|
|
||||||
{
|
|
||||||
playerNetworkIdentity.SetClientOwner(conn);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1063,7 +1060,7 @@ static void OnCommandMessage(NetworkMessage netMsg)
|
|||||||
uv.HandleCommand(message.cmdHash, new NetworkReader(message.payload));
|
uv.HandleCommand(message.cmdHash, new NetworkReader(message.payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
static internal void SpawnObject(GameObject obj)
|
static internal void SpawnObject(GameObject obj, NetworkConnection conn = null)
|
||||||
{
|
{
|
||||||
if (!NetworkServer.active)
|
if (!NetworkServer.active)
|
||||||
{
|
{
|
||||||
@ -1083,6 +1080,13 @@ static internal void SpawnObject(GameObject obj)
|
|||||||
|
|
||||||
if (LogFilter.logDebug) { Debug.Log("SpawnObject instance ID " + objNetworkIdentity.netId + " asset ID " + objNetworkIdentity.assetId); }
|
if (LogFilter.logDebug) { Debug.Log("SpawnObject instance ID " + objNetworkIdentity.netId + " asset ID " + objNetworkIdentity.assetId); }
|
||||||
|
|
||||||
|
// paul: we must set the owner before rebuilding observers or we won't be sending
|
||||||
|
// owner data to the owner
|
||||||
|
if (objNetworkIdentity.localPlayerAuthority && conn != null)
|
||||||
|
{
|
||||||
|
objNetworkIdentity.SetClientOwner(conn);
|
||||||
|
}
|
||||||
|
|
||||||
objNetworkIdentity.RebuildObservers(true);
|
objNetworkIdentity.RebuildObservers(true);
|
||||||
//SendSpawnMessage(objNetworkIdentity, null);
|
//SendSpawnMessage(objNetworkIdentity, null);
|
||||||
}
|
}
|
||||||
@ -1308,11 +1312,11 @@ static public void ClearLocalObjects()
|
|||||||
objects.Clear();
|
objects.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void Spawn(GameObject obj)
|
static public void Spawn(GameObject obj, NetworkConnection conn = null)
|
||||||
{
|
{
|
||||||
if (VerifyCanSpawn(obj))
|
if (VerifyCanSpawn(obj))
|
||||||
{
|
{
|
||||||
SpawnObject(obj);
|
SpawnObject(obj, conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1362,7 +1366,7 @@ static public bool SpawnWithClientAuthority(GameObject obj, NetworkConnection co
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Spawn(obj);
|
Spawn(obj, conn);
|
||||||
|
|
||||||
var uv = obj.GetComponent<NetworkIdentity>();
|
var uv = obj.GetComponent<NetworkIdentity>();
|
||||||
if (uv == null || !uv.isServer)
|
if (uv == null || !uv.isServer)
|
||||||
@ -1376,7 +1380,7 @@ static public bool SpawnWithClientAuthority(GameObject obj, NetworkConnection co
|
|||||||
|
|
||||||
static public bool SpawnWithClientAuthority(GameObject obj, NetworkHash128 assetId, NetworkConnection conn)
|
static public bool SpawnWithClientAuthority(GameObject obj, NetworkHash128 assetId, NetworkConnection conn)
|
||||||
{
|
{
|
||||||
Spawn(obj, assetId);
|
Spawn(obj, assetId, conn);
|
||||||
|
|
||||||
var uv = obj.GetComponent<NetworkIdentity>();
|
var uv = obj.GetComponent<NetworkIdentity>();
|
||||||
if (uv == null || !uv.isServer)
|
if (uv == null || !uv.isServer)
|
||||||
@ -1388,7 +1392,7 @@ static public bool SpawnWithClientAuthority(GameObject obj, NetworkHash128 asset
|
|||||||
return uv.AssignClientAuthority(conn);
|
return uv.AssignClientAuthority(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void Spawn(GameObject obj, NetworkHash128 assetId)
|
static public void Spawn(GameObject obj, NetworkHash128 assetId, NetworkConnection conn = null)
|
||||||
{
|
{
|
||||||
if (VerifyCanSpawn(obj))
|
if (VerifyCanSpawn(obj))
|
||||||
{
|
{
|
||||||
@ -1397,7 +1401,7 @@ static public void Spawn(GameObject obj, NetworkHash128 assetId)
|
|||||||
{
|
{
|
||||||
id.SetDynamicAssetId(assetId);
|
id.SetDynamicAssetId(assetId);
|
||||||
}
|
}
|
||||||
SpawnObject(obj);
|
SpawnObject(obj, conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user