コード例 #1
0
 /// <summary>
 /// <para>This causes objects for known players to be disabled.</para>
 /// </summary>
 public void DisablePlayerObjects()
 {
     if (LogFilter.logDev)
     {
         Debug.Log("NetworkMigrationManager DisablePlayerObjects");
     }
     if (this.m_Peers != null)
     {
         for (int i = 0; i < this.m_Peers.Length; i++)
         {
             PeerInfoMessage message = this.m_Peers[i];
             if (message.playerIds != null)
             {
                 for (int j = 0; j < message.playerIds.Length; j++)
                 {
                     PeerInfoPlayer player = message.playerIds[j];
                     if (LogFilter.logDev)
                     {
                         Debug.Log(string.Concat(new object[] { "DisablePlayerObjects disable player for ", message.address, " netId:", player.netId, " control:", player.playerControllerId }));
                     }
                     GameObject obj2 = ClientScene.FindLocalObject(player.netId);
                     if (obj2 != null)
                     {
                         obj2.SetActive(false);
                         this.AddPendingPlayer(obj2, message.connectionId, player.netId, player.playerControllerId);
                     }
                     else if (LogFilter.logWarn)
                     {
                         Debug.LogWarning(string.Concat(new object[] { "DisablePlayerObjects didnt find player Conn:", message.connectionId, " NetId:", player.netId }));
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
        private void OnPeerClientAuthority(NetworkMessage netMsg)
        {
            PeerAuthorityMessage message = netMsg.ReadMessage <PeerAuthorityMessage>();

            if (LogFilter.logDebug)
            {
                Debug.Log("OnPeerClientAuthority for netId:" + message.netId);
            }
            if (this.m_Peers != null)
            {
                for (int i = 0; i < this.m_Peers.Length; i++)
                {
                    PeerInfoMessage message2 = this.m_Peers[i];
                    if (message2.connectionId == message.connectionId)
                    {
                        if (message2.playerIds == null)
                        {
                            message2.playerIds = new PeerInfoPlayer[0];
                        }
                        if (message.authorityState)
                        {
                            for (int j = 0; j < message2.playerIds.Length; j++)
                            {
                                if (message2.playerIds[j].netId == message.netId)
                                {
                                    return;
                                }
                            }
                            PeerInfoPlayer player = new PeerInfoPlayer {
                                netId = message.netId,
                                playerControllerId = -1
                            };
                            message2.playerIds = new List <PeerInfoPlayer>(message2.playerIds)
                            {
                                player
                            }.ToArray();
                        }
                        else
                        {
                            for (int k = 0; k < message2.playerIds.Length; k++)
                            {
                                if (message2.playerIds[k].netId == message.netId)
                                {
                                    List <PeerInfoPlayer> list2 = new List <PeerInfoPlayer>(message2.playerIds);
                                    list2.RemoveAt(k);
                                    message2.playerIds = list2.ToArray();
                                    break;
                                }
                            }
                        }
                    }
                }
                GameObject go = ClientScene.FindLocalObject(message.netId);
                this.OnAuthorityUpdated(go, message.connectionId, message.authorityState);
            }
        }
コード例 #3
0
        private void OnPeerClientAuthority(NetworkMessage netMsg)
        {
            PeerAuthorityMessage peerAuthorityMessage = netMsg.ReadMessage <PeerAuthorityMessage>();

            if (LogFilter.logDebug)
            {
                Debug.Log("OnPeerClientAuthority for netId:" + peerAuthorityMessage.netId);
            }
            if (m_Peers == null)
            {
                return;
            }
            for (int i = 0; i < m_Peers.Length; i++)
            {
                PeerInfoMessage peerInfoMessage = m_Peers[i];
                if (peerInfoMessage.connectionId != peerAuthorityMessage.connectionId)
                {
                    continue;
                }
                if (peerInfoMessage.playerIds == null)
                {
                    peerInfoMessage.playerIds = new PeerInfoPlayer[0];
                }
                if (peerAuthorityMessage.authorityState)
                {
                    for (int j = 0; j < peerInfoMessage.playerIds.Length; j++)
                    {
                        if (peerInfoMessage.playerIds[j].netId == peerAuthorityMessage.netId)
                        {
                            return;
                        }
                    }
                    PeerInfoPlayer item = default(PeerInfoPlayer);
                    item.netId = peerAuthorityMessage.netId;
                    item.playerControllerId = -1;
                    List <PeerInfoPlayer> list = new List <PeerInfoPlayer>(peerInfoMessage.playerIds);
                    list.Add(item);
                    peerInfoMessage.playerIds = list.ToArray();
                    continue;
                }
                for (int k = 0; k < peerInfoMessage.playerIds.Length; k++)
                {
                    if (peerInfoMessage.playerIds[k].netId == peerAuthorityMessage.netId)
                    {
                        List <PeerInfoPlayer> list2 = new List <PeerInfoPlayer>(peerInfoMessage.playerIds);
                        list2.RemoveAt(k);
                        peerInfoMessage.playerIds = list2.ToArray();
                        break;
                    }
                }
            }
            GameObject go = ClientScene.FindLocalObject(peerAuthorityMessage.netId);

            OnAuthorityUpdated(go, peerAuthorityMessage.connectionId, peerAuthorityMessage.authorityState);
        }
コード例 #4
0
 public void DisablePlayerObjects()
 {
     if (LogFilter.logDev)
     {
         Debug.Log("NetworkMigrationManager DisablePlayerObjects");
     }
     if (m_Peers == null)
     {
         return;
     }
     for (int i = 0; i < m_Peers.Length; i++)
     {
         PeerInfoMessage peerInfoMessage = m_Peers[i];
         if (peerInfoMessage.playerIds == null)
         {
             continue;
         }
         for (int j = 0; j < peerInfoMessage.playerIds.Length; j++)
         {
             PeerInfoPlayer peerInfoPlayer = peerInfoMessage.playerIds[j];
             if (LogFilter.logDev)
             {
                 Debug.Log("DisablePlayerObjects disable player for " + peerInfoMessage.address + " netId:" + peerInfoPlayer.netId + " control:" + peerInfoPlayer.playerControllerId);
             }
             GameObject gameObject = ClientScene.FindLocalObject(peerInfoPlayer.netId);
             if (gameObject != null)
             {
                 gameObject.SetActive(value: false);
                 AddPendingPlayer(gameObject, peerInfoMessage.connectionId, peerInfoPlayer.netId, peerInfoPlayer.playerControllerId);
             }
             else if (LogFilter.logWarn)
             {
                 Debug.LogWarning("DisablePlayerObjects didnt find player Conn:" + peerInfoMessage.connectionId + " NetId:" + peerInfoPlayer.netId);
             }
         }
     }
 }
コード例 #5
0
        public void SendPeerInfo()
        {
            if (!m_HostMigration)
            {
                return;
            }
            PeerListMessage        peerListMessage = new PeerListMessage();
            List <PeerInfoMessage> list            = new List <PeerInfoMessage>();
            PeerInfoPlayer         item            = default(PeerInfoPlayer);
            PeerInfoPlayer         item2           = default(PeerInfoPlayer);

            for (int i = 0; i < NetworkServer.connections.Count; i++)
            {
                NetworkConnection networkConnection = NetworkServer.connections[i];
                if (networkConnection == null)
                {
                    continue;
                }
                PeerInfoMessage peerInfoMessage = new PeerInfoMessage();
                NetworkTransport.GetConnectionInfo(NetworkServer.serverHostId, networkConnection.connectionId, out string address, out int port, out NetworkID _, out NodeID _, out byte _);
                peerInfoMessage.connectionId = networkConnection.connectionId;
                peerInfoMessage.port         = port;
                if (i == 0)
                {
                    peerInfoMessage.port    = NetworkServer.listenPort;
                    peerInfoMessage.isHost  = true;
                    peerInfoMessage.address = "<host>";
                }
                else
                {
                    peerInfoMessage.address = address;
                    peerInfoMessage.isHost  = false;
                }
                List <PeerInfoPlayer> list2 = new List <PeerInfoPlayer>();
                for (int j = 0; j < networkConnection.playerControllers.Count; j++)
                {
                    PlayerController playerController = networkConnection.playerControllers[j];
                    if (playerController != null && playerController.unetView != null)
                    {
                        item.netId = playerController.unetView.netId;
                        item.playerControllerId = playerController.unetView.playerControllerId;
                        list2.Add(item);
                    }
                }
                if (networkConnection.clientOwnedObjects != null)
                {
                    foreach (NetworkInstanceId clientOwnedObject in networkConnection.clientOwnedObjects)
                    {
                        GameObject gameObject = NetworkServer.FindLocalObject(clientOwnedObject);
                        if (!(gameObject == null))
                        {
                            NetworkIdentity component = gameObject.GetComponent <NetworkIdentity>();
                            if (component.playerControllerId == -1)
                            {
                                item2.netId = clientOwnedObject;
                                item2.playerControllerId = -1;
                                list2.Add(item2);
                            }
                        }
                    }
                }
                if (list2.Count > 0)
                {
                    peerInfoMessage.playerIds = list2.ToArray();
                }
                list.Add(peerInfoMessage);
            }
            peerListMessage.peers = list.ToArray();
            for (int k = 0; k < NetworkServer.connections.Count; k++)
            {
                NetworkConnection networkConnection2 = NetworkServer.connections[k];
                if (networkConnection2 != null)
                {
                    peerListMessage.oldServerConnectionId = networkConnection2.connectionId;
                    networkConnection2.Send(11, peerListMessage);
                }
            }
        }
コード例 #6
0
        // received on both host and clients
        void OnPeerClientAuthority(NetworkMessage netMsg)
        {
            var msg = netMsg.ReadMessage <PeerAuthorityMessage>();

            if (LogFilter.logDebug)
            {
                Debug.Log("OnPeerClientAuthority for netId:" + msg.netId);
            }

            if (m_Peers == null)
            {
                // havent received peers yet. just ignore this. the peer list will contain this data.
                return;
            }

            // find the peer for connId
            foreach (var p in m_Peers)
            {
                if (p.connectionId == msg.connectionId)
                {
                    if (p.playerIds == null)
                    {
                        p.playerIds = new PeerInfoPlayer[0];
                    }

                    if (msg.authorityState)
                    {
                        foreach (var playerId in p.playerIds)
                        {
                            if (playerId.netId == msg.netId)
                            {
                                // already in list
                                return;
                            }
                        }
                        var newPlayerId = new PeerInfoPlayer();
                        newPlayerId.netId = msg.netId;
                        newPlayerId.playerControllerId = -1;

                        var pl = new List <PeerInfoPlayer>(p.playerIds);
                        pl.Add(newPlayerId);
                        p.playerIds = pl.ToArray();
                    }
                    else
                    {
                        for (int i = 0; i < p.playerIds.Length; i++)
                        {
                            if (p.playerIds[i].netId == msg.netId)
                            {
                                var pl = new List <PeerInfoPlayer>(p.playerIds);
                                pl.RemoveAt(i);
                                p.playerIds = pl.ToArray();
                                break;
                            }
                        }
                    }
                }
            }

            var foundObj = ClientScene.FindLocalObject(msg.netId);

            OnAuthorityUpdated(foundObj, msg.connectionId, msg.authorityState);
        }