NetworkIdentityTests: RebuildObserversAddsOwnReadyPlayer

This commit is contained in:
vis2k 2020-03-03 23:05:14 +01:00
parent 60226797ac
commit 3e8c6089b0

View File

@ -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));
}
}
}