-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: making NetworkServer.players a readonly collection
This will stop other scripts from adding or removing items from the set. We can also remove the set and just use the values from the connection dictionary. BREAKING CHANGE: NetworkServer.Players is now a IReadOnlyCollection<INetworkPlayer>
- Loading branch information
1 parent
f455a2d
commit f1b4512
Showing
8 changed files
with
40 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using Mirage.SocketLayer; | ||
using NSubstitute; | ||
|
||
namespace Mirage.Tests | ||
{ | ||
public static class NetworkIdentityTestExtensions | ||
{ | ||
public static void SetSceneId(this NetworkIdentity identity, int id, int hash = 0) | ||
{ | ||
FieldInfo fieldInfo = typeof(NetworkIdentity).GetField("_sceneId", BindingFlags.Instance | BindingFlags.NonPublic); | ||
fieldInfo.SetValue(identity, (ulong)((((long)hash) << 32) | (long)id)); | ||
} | ||
} | ||
|
||
public static class NetworkServerTestExtensions | ||
{ | ||
public static void AddTestPlayer(this NetworkServer server, INetworkPlayer player) | ||
{ | ||
FieldInfo info = typeof(NetworkServer).GetField("connections", BindingFlags.Instance | BindingFlags.NonPublic); | ||
var connections = (Dictionary<IConnection, INetworkPlayer>)info.GetValue(server); | ||
|
||
IConnection connectiion = Substitute.For<IConnection>(); | ||
player.Connection.Returns(connectiion); | ||
connections.Add(connectiion, player); | ||
} | ||
} | ||
} | ||
|
2 changes: 1 addition & 1 deletion
2
...ver/NetworkIdentityTestExtensions.cs.meta → Assets/Tests/Common/TestExtensions.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
Assets/Tests/Runtime/ClientServer/NetworkIdentityTestExtensions.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters