Skip to content

Commit

Permalink
fix: #1380 - NetworkConnection.clientOwnedObjects changed from uint H…
Browse files Browse the repository at this point in the history
…ashSet to NetworkIdentity HashSet for ease of use and to fix a bug where DestroyOwnedObjects wouldn't find a netId anymore in some cases.
  • Loading branch information
miwarnec committed Jan 8, 2020
1 parent a2173d3 commit a71ecdb
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Assets/Mirror/Runtime/NetworkConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ internal set
/// <para>This includes the player object for the connection - if it has localPlayerAutority set, and any objects spawned with local authority or set with AssignLocalAuthority.</para>
/// <para>This list can be used to validate messages from clients, to ensure that clients are only trying to control objects that they own.</para>
/// </summary>
public readonly HashSet<uint> clientOwnedObjects = new HashSet<uint>();
// IMPORTANT: this needs to be <NetworkIdentity>, not <uint netId>. fixes a bug where DestroyOwnedObjects wouldn't find
// the netId anymore: https://github.com/vis2k/Mirror/issues/1380 . Works fine with NetworkIdentity pointers though.
public readonly HashSet<NetworkIdentity> clientOwnedObjects = new HashSet<NetworkIdentity>();

/// <summary>
/// Setting this to true will log the contents of network message to the console.
Expand Down Expand Up @@ -364,21 +366,21 @@ internal void TransportReceive(ArraySegment<byte> buffer, int channelId)

internal void AddOwnedObject(NetworkIdentity obj)
{
clientOwnedObjects.Add(obj.netId);
clientOwnedObjects.Add(obj);
}

internal void RemoveOwnedObject(NetworkIdentity obj)
{
clientOwnedObjects.Remove(obj.netId);
clientOwnedObjects.Remove(obj);
}

internal void DestroyOwnedObjects()
{
// create a copy because the list might be modified when destroying
HashSet<uint> tmp = new HashSet<uint>(clientOwnedObjects);
foreach (uint netId in tmp)
HashSet<NetworkIdentity> tmp = new HashSet<NetworkIdentity>(clientOwnedObjects);
foreach (NetworkIdentity netIdentity in tmp)
{
if (NetworkIdentity.spawned.TryGetValue(netId, out NetworkIdentity netIdentity))
if (netIdentity != null)
{
NetworkServer.Destroy(netIdentity.gameObject);
}
Expand Down

0 comments on commit a71ecdb

Please sign in to comment.