mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
NetworkIdentityTests: RebuildObserversAddsOwnReadyPlayer
This commit is contained in:
parent
60226797ac
commit
3e8c6089b0
@ -215,6 +215,16 @@ public override bool OnRebuildObservers(HashSet<NetworkConnection> observers, bo
|
||||
}
|
||||
}
|
||||
|
||||
class RebuildEmptyObserversNetworkBehaviour : NetworkBehaviour
|
||||
{
|
||||
public override bool OnRebuildObservers(HashSet<NetworkConnection> observers, bool initialize)
|
||||
{
|
||||
// return true so that caller knows we implemented
|
||||
// OnRebuildObservers, but return no observers
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class IsClientServerCheckComponent : NetworkBehaviour
|
||||
{
|
||||
// OnStartClient
|
||||
@ -1305,5 +1315,28 @@ public void GetNewObserversFalseIfNoComponents()
|
||||
bool result = identity.GetNewObservers(observers, true);
|
||||
Assert.That(result, Is.False);
|
||||
}
|
||||
|
||||
// RebuildObservers should always add the own ready connection
|
||||
// (if any). fixes https://github.com/vis2k/Mirror/issues/692
|
||||
[Test]
|
||||
public void RebuildObserversAddsOwnReadyPlayer()
|
||||
{
|
||||
// add at least one observers component, otherwise it will just add
|
||||
// all server connections
|
||||
gameObject.AddComponent<RebuildEmptyObserversNetworkBehaviour>();
|
||||
|
||||
// add own player connection
|
||||
ULocalConnectionToClient connection = new ULocalConnectionToClient();
|
||||
connection.connectionToServer = new ULocalConnectionToServer();
|
||||
connection.isReady = true;
|
||||
identity.connectionToClient = connection;
|
||||
|
||||
// call OnStartServer so that observers dict is created
|
||||
identity.OnStartServer();
|
||||
|
||||
// rebuild should at least add own ready player
|
||||
identity.RebuildObservers(true);
|
||||
Assert.That(identity.observers.ContainsKey(identity.connectionToClient.connectionId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user