Example #1
0
 private static void ApplySpawnPayload(NetworkIdentity uv, Vector3 position, byte[] payload, NetworkInstanceId netId, GameObject newGameObject)
 {
     if (!uv.gameObject.activeSelf)
     {
         uv.gameObject.SetActive(true);
     }
     uv.transform.position = position;
     if (payload != null && payload.Length > 0)
     {
         NetworkReader reader = new NetworkReader(payload);
         uv.OnUpdateVars(reader, true);
     }
     if ((Object)newGameObject == (Object)null)
     {
         return;
     }
     newGameObject.SetActive(true);
     uv.SetNetworkInstanceId(netId);
     ClientScene.SetLocalObject(netId, newGameObject);
     if (!ClientScene.s_IsSpawnFinished)
     {
         return;
     }
     uv.OnStartClient();
     ClientScene.CheckForOwner(uv);
 }
Example #2
0
 internal void OnStartServer(bool allowNonZeroNetId)
 {
     if (m_IsServer)
     {
         return;
     }
     m_IsServer = true;
     if (m_LocalPlayerAuthority)
     {
         m_HasAuthority = false;
     }
     else
     {
         m_HasAuthority = true;
     }
     m_Observers           = new List <NetworkConnection>();
     m_ObserverConnections = new HashSet <int>();
     CacheBehaviours();
     if (netId.IsEmpty())
     {
         m_NetId = GetNextNetworkId();
     }
     else if (!allowNonZeroNetId)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("Object has non-zero netId " + netId + " for " + base.gameObject);
         }
         return;
     }
     if (LogFilter.logDev)
     {
         Debug.Log("OnStartServer " + base.gameObject + " GUID:" + netId);
     }
     NetworkServer.instance.SetLocalObjectOnServer(netId, base.gameObject);
     for (int i = 0; i < m_NetworkBehaviours.Length; i++)
     {
         NetworkBehaviour networkBehaviour = m_NetworkBehaviours[i];
         try
         {
             networkBehaviour.OnStartServer();
         }
         catch (Exception ex)
         {
             Debug.LogError("Exception in OnStartServer:" + ex.Message + " " + ex.StackTrace);
         }
     }
     if (NetworkClient.active && NetworkServer.localClientActive)
     {
         ClientScene.SetLocalObject(netId, base.gameObject);
         OnStartClient();
     }
     if (m_HasAuthority)
     {
         OnStartAuthority();
     }
 }
Example #3
0
 internal void OnStartServer(bool allowNonZeroNetId)
 {
     if (!this.m_IsServer)
     {
         this.m_IsServer = true;
         if (this.m_LocalPlayerAuthority)
         {
             this.m_HasAuthority = false;
         }
         else
         {
             this.m_HasAuthority = true;
         }
         this.m_Observers           = new List <NetworkConnection>();
         this.m_ObserverConnections = new HashSet <int>();
         this.CacheBehaviours();
         if (this.netId.IsEmpty())
         {
             this.m_NetId = GetNextNetworkId();
         }
         else if (!allowNonZeroNetId)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError(string.Concat(new object[] { "Object has non-zero netId ", this.netId, " for ", base.gameObject }));
             }
             return;
         }
         if (LogFilter.logDev)
         {
             Debug.Log(string.Concat(new object[] { "OnStartServer ", base.gameObject, " GUID:", this.netId }));
         }
         NetworkServer.instance.SetLocalObjectOnServer(this.netId, base.gameObject);
         for (int i = 0; i < this.m_NetworkBehaviours.Length; i++)
         {
             NetworkBehaviour behaviour = this.m_NetworkBehaviours[i];
             try
             {
                 behaviour.OnStartServer();
             }
             catch (Exception exception)
             {
                 Debug.LogError("Exception in OnStartServer:" + exception.Message + " " + exception.StackTrace);
             }
         }
         if (NetworkClient.active && NetworkServer.localClientActive)
         {
             ClientScene.SetLocalObject(this.netId, base.gameObject);
             this.OnStartClient();
         }
         if (this.m_HasAuthority)
         {
             this.OnStartAuthority();
         }
     }
 }
 internal void OnStartServer(bool allowNonZeroNetId)
 {
     if (this.m_IsServer)
     {
         return;
     }
     this.m_IsServer            = true;
     this.m_HasAuthority        = !this.m_LocalPlayerAuthority;
     this.m_Observers           = new List <NetworkConnection>();
     this.m_ObserverConnections = new HashSet <int>();
     this.CacheBehaviours();
     if (this.netId.IsEmpty())
     {
         this.m_NetId = NetworkIdentity.GetNextNetworkId();
     }
     else if (!allowNonZeroNetId)
     {
         if (!LogFilter.logError)
         {
             return;
         }
         Debug.LogError((object)("Object has non-zero netId " + (object)this.netId + " for " + (object)this.gameObject));
         return;
     }
     if (LogFilter.logDev)
     {
         Debug.Log((object)("OnStartServer " + (object)this.gameObject + " GUID:" + (object)this.netId));
     }
     NetworkServer.instance.SetLocalObjectOnServer(this.netId, this.gameObject);
     for (int index = 0; index < this.m_NetworkBehaviours.Length; ++index)
     {
         NetworkBehaviour networkBehaviour = this.m_NetworkBehaviours[index];
         try
         {
             networkBehaviour.OnStartServer();
         }
         catch (Exception ex)
         {
             Debug.LogError((object)("Exception in OnStartServer:" + ex.Message + " " + ex.StackTrace));
         }
     }
     if (NetworkClient.active && NetworkServer.localClientActive)
     {
         ClientScene.SetLocalObject(this.netId, this.gameObject);
         this.OnStartClient();
     }
     if (!this.m_HasAuthority)
     {
         return;
     }
     this.OnStartAuthority();
 }
Example #5
0
        internal void AddLocalPlayer(PlayerController localPlayer)
        {
            if (LogFilter.logDev)
            {
                Debug.Log((object)("Local client AddLocalPlayer " + localPlayer.gameObject.name + " conn=" + (object)this.m_Connection.connectionId));
            }
            this.m_Connection.isReady = true;
            this.m_Connection.SetPlayerController(localPlayer);
            NetworkIdentity unetView = localPlayer.unetView;

            if ((Object)unetView != (Object)null)
            {
                ClientScene.SetLocalObject(unetView.netId, localPlayer.gameObject);
                unetView.SetConnectionToServer(this.m_Connection);
            }
            ClientScene.InternalAddPlayer(unetView, localPlayer.playerControllerId);
        }
Example #6
0
        internal void AddLocalPlayer(PlayerController localPlayer)
        {
            if (LogFilter.logDev)
            {
                Debug.Log(string.Concat(new object[] { "Local client AddLocalPlayer ", localPlayer.gameObject.name, " conn=", base.m_Connection.connectionId }));
            }
            base.m_Connection.isReady = true;
            base.m_Connection.SetPlayerController(localPlayer);
            NetworkIdentity unetView = localPlayer.unetView;

            if (unetView != null)
            {
                ClientScene.SetLocalObject(unetView.netId, localPlayer.gameObject);
                unetView.SetConnectionToServer(base.m_Connection);
            }
            ClientScene.InternalAddPlayer(unetView, localPlayer.playerControllerId);
        }
        // Called by the server to set the LocalClient's LocalPlayer object during NetworkServer.AddPlayer()
        internal void AddLocalPlayer(PlayerController localPlayer)
        {
            if (LogFilter.logDev)
            {
                Debug.Log("Local client AddLocalPlayer " + localPlayer.gameObject.name + " conn=" + m_Connection.connectionId);
            }
            m_Connection.isReady = true;
            m_Connection.SetPlayerController(localPlayer);
            var uv = localPlayer.unetView;

            if (uv != null)
            {
                ClientScene.SetLocalObject(uv.netId, localPlayer.gameObject);
                uv.SetConnectionToServer(m_Connection);
            }
            // there is no SystemOwnerMessage for local client. add to ClientScene here instead
            ClientScene.InternalAddPlayer(uv, localPlayer.playerControllerId);
        }
Example #8
0
        internal void OnStartServer(bool allowNonZeroNetId)
        {
            if (m_IsServer)
            {
                return;
            }
            m_IsServer     = true;
            m_HasAuthority = !m_LocalPlayerAuthority;

            m_Observers           = new List <NetworkConnection>();
            m_ObserverConnections = new HashSet <int>();
            CacheBehaviours();

            // If the instance/net ID is invalid here then this is an object instantiated from a prefab and the server should assign a valid ID
            if (netId.IsEmpty())
            {
                m_NetId = GetNextNetworkId();
            }
            else
            {
                if (!allowNonZeroNetId)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Object has non-zero netId " + netId + " for " + gameObject);
                    }
                    return;
                }
            }

            if (LogFilter.logDev)
            {
                Debug.Log("OnStartServer " + gameObject + " GUID:" + netId);
            }
            NetworkServer.SetLocalObjectOnServer(netId, gameObject);

            for (int i = 0; i < m_NetworkBehaviours.Length; i++)
            {
                NetworkBehaviour comp = m_NetworkBehaviours[i];
                try
                {
                    comp.OnStartServer();
                }
                catch (Exception e)
                {
                    Debug.LogError("Exception in OnStartServer:" + e.Message + " " + e.StackTrace);
                }
            }

            if (NetworkClient.active && NetworkServer.localClientActive)
            {
                // there will be no spawn message, so start the client here too
                ClientScene.SetLocalObject(netId, gameObject);
                OnStartClient();
            }

            if (m_HasAuthority)
            {
                OnStartAuthority();
            }
        }