mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix: NetworkServer.OnConnected allows for connectionIds < 0 now. some transports like kcp use hashing where connectionIds can easily be < 0, which previously was not allowed.
This commit is contained in:
parent
11e2216894
commit
12ee96f5d9
@ -499,10 +499,12 @@ static void OnConnected(int connectionId)
|
|||||||
{
|
{
|
||||||
if (logger.LogEnabled()) logger.Log("Server accepted client:" + connectionId);
|
if (logger.LogEnabled()) logger.Log("Server accepted client:" + connectionId);
|
||||||
|
|
||||||
// connectionId needs to be > 0 because 0 is reserved for local player
|
// connectionId needs to be != 0 because 0 is reserved for local player
|
||||||
if (connectionId <= 0)
|
// note that some transports like kcp generate connectionId by
|
||||||
|
// hashing which can be < 0 as well, so we need to allow < 0!
|
||||||
|
if (connectionId == 0)
|
||||||
{
|
{
|
||||||
logger.LogError("Server.HandleConnect: invalid connectionId: " + connectionId + " . Needs to be >0, because 0 is reserved for local player.");
|
logger.LogError("Server.HandleConnect: invalid connectionId: " + connectionId + " . Needs to be != 0, because 0 is reserved for local player.");
|
||||||
Transport.activeTransport.ServerDisconnect(connectionId);
|
Transport.activeTransport.ServerDisconnect(connectionId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ public void ConnectionsDictTest()
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void OnConnectedOnlyAllowsGreaterZeroConnectionIdsTest()
|
public void OnConnectedOnlyAllowsNonZeroConnectionIdsTest()
|
||||||
{
|
{
|
||||||
// OnConnected should only allow connectionIds >= 0
|
// OnConnected should only allow connectionIds >= 0
|
||||||
// 0 is for local player
|
// 0 is for local player
|
||||||
@ -230,8 +230,8 @@ public void OnConnectedOnlyAllowsGreaterZeroConnectionIdsTest()
|
|||||||
Transport.activeTransport.OnServerConnected.Invoke(0);
|
Transport.activeTransport.OnServerConnected.Invoke(0);
|
||||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
||||||
|
|
||||||
// connect <0
|
// connect == 0 should fail
|
||||||
Transport.activeTransport.OnServerConnected.Invoke(-1);
|
Transport.activeTransport.OnServerConnected.Invoke(0);
|
||||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
||||||
LogAssert.ignoreFailingMessages = false;
|
LogAssert.ignoreFailingMessages = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user