mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
breaking: NetworkServer.NoExternalConnections => HasExternalConnections to avoid double negative checks as usual
This commit is contained in:
parent
7488aac1d6
commit
bf2350030b
@ -250,10 +250,24 @@ internal static void RemoveLocalConnection()
|
||||
}
|
||||
|
||||
/// <summary>True if we have no external connections (host is allowed)</summary>
|
||||
public static bool NoExternalConnections()
|
||||
// DEPRECATED 2022-02-05
|
||||
[Obsolete("Use !HasExternalConnections() instead of NoExternalConnections() to avoid double negatives.")]
|
||||
public static bool NoExternalConnections() => !HasExternalConnections();
|
||||
|
||||
/// <summary>True if we have external connections (that are not host)</summary>
|
||||
public static bool HasExternalConnections()
|
||||
{
|
||||
return connections.Count == 0 ||
|
||||
(connections.Count == 1 && localConnection != null);
|
||||
// any connections?
|
||||
if (connections.Count > 0)
|
||||
{
|
||||
// only host connection?
|
||||
if (connections.Count == 1 && localConnection != null)
|
||||
return false;
|
||||
|
||||
// otherwise we have real external connections
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// send ////////////////////////////////////////////////////////////////
|
||||
|
@ -1204,37 +1204,37 @@ public void SendToReady_CalledWhileNotActive_ShouldGiveWarning()
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NoExternalConnections_WithNoConnection()
|
||||
public void HasExternalConnections_WithNoConnection()
|
||||
{
|
||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
||||
Assert.That(NetworkServer.NoExternalConnections(), Is.True);
|
||||
Assert.That(NetworkServer.HasExternalConnections(), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NoExternalConnections_WithConnections()
|
||||
public void HasExternalConnections_WithConnections()
|
||||
{
|
||||
NetworkServer.connections.Add(1, null);
|
||||
NetworkServer.connections.Add(2, null);
|
||||
Assert.That(NetworkServer.NoExternalConnections(), Is.False);
|
||||
Assert.That(NetworkServer.HasExternalConnections(), Is.True);
|
||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NoExternalConnections_WithHostOnly()
|
||||
public void HasExternalConnections_WithHostOnly()
|
||||
{
|
||||
CreateLocalConnectionPair(out LocalConnectionToClient connectionToClient, out _);
|
||||
|
||||
NetworkServer.SetLocalConnection(connectionToClient);
|
||||
NetworkServer.connections.Add(0, connectionToClient);
|
||||
|
||||
Assert.That(NetworkServer.NoExternalConnections(), Is.True);
|
||||
Assert.That(NetworkServer.HasExternalConnections(), Is.False);
|
||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(1));
|
||||
|
||||
NetworkServer.RemoveLocalConnection();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NoExternalConnections_WithHostAndConnection()
|
||||
public void HasExternalConnections_WithHostAndConnection()
|
||||
{
|
||||
CreateLocalConnectionPair(out LocalConnectionToClient connectionToClient, out _);
|
||||
|
||||
@ -1242,7 +1242,7 @@ public void NoExternalConnections_WithHostAndConnection()
|
||||
NetworkServer.connections.Add(0, connectionToClient);
|
||||
NetworkServer.connections.Add(1, null);
|
||||
|
||||
Assert.That(NetworkServer.NoExternalConnections(), Is.False);
|
||||
Assert.That(NetworkServer.HasExternalConnections(), Is.True);
|
||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(2));
|
||||
|
||||
NetworkServer.RemoveLocalConnection();
|
||||
|
Loading…
Reference in New Issue
Block a user