コード例 #1
0
        public bool BecomeNewHost(int port)
        {
            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkMigrationManager BecomeNewHost " + m_MatchInfo);
            }
            NetworkServer.RegisterHandler(47, OnServerReconnectPlayerMessage);
            NetworkClient networkClient = NetworkServer.BecomeHost(m_Client, port, m_MatchInfo, oldServerConnectionId, peers);

            if (networkClient != null)
            {
                if (NetworkManager.singleton != null)
                {
                    NetworkManager.singleton.RegisterServerMessages();
                    NetworkManager.singleton.UseExternalClient(networkClient);
                }
                else
                {
                    Debug.LogWarning("MigrationManager BecomeNewHost - No NetworkManager.");
                }
                networkClient.RegisterHandlerSafe(11, OnPeerInfo);
                RemovePendingPlayer(m_OldServerConnectionId);
                Reset(-1);
                SendPeerInfo();
                return(true);
            }
            if (LogFilter.logError)
            {
                Debug.LogError("NetworkServer.BecomeHost failed");
            }
            return(false);
        }
コード例 #2
0
        /// <summary>
        ///   <para>This causes a client that has been disconnected from the host to become the new host of the game.</para>
        /// </summary>
        /// <param name="port">The network port to listen on.</param>
        /// <returns>
        ///   <para>True if able to become the new host.</para>
        /// </returns>
        public bool BecomeNewHost(int port)
        {
            if (LogFilter.logDebug)
            {
                Debug.Log((object)("NetworkMigrationManager BecomeNewHost " + (object)this.m_MatchInfo));
            }
            NetworkServer.RegisterHandler((short)47, new NetworkMessageDelegate(this.OnServerReconnectPlayerMessage));
            NetworkClient externalClient = NetworkServer.BecomeHost(this.m_Client, port, this.m_MatchInfo, this.oldServerConnectionId, this.peers);

            if (externalClient != null)
            {
                if ((Object)NetworkManager.singleton != (Object)null)
                {
                    NetworkManager.singleton.RegisterServerMessages();
                    NetworkManager.singleton.UseExternalClient(externalClient);
                }
                else
                {
                    Debug.LogWarning((object)"MigrationManager BecomeNewHost - No NetworkManager.");
                }
                externalClient.RegisterHandlerSafe((short)11, new NetworkMessageDelegate(this.OnPeerInfo));
                this.RemovePendingPlayer(this.m_OldServerConnectionId);
                this.Reset(-1);
                this.SendPeerInfo();
                return(true);
            }
            if (LogFilter.logError)
            {
                Debug.LogError((object)"NetworkServer.BecomeHost failed");
            }
            return(false);
        }
コード例 #3
0
        public bool BecomeNewHost(int port)
        {
            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkMigrationManager BecomeNewHost " + this.m_MatchInfo);
            }
            NetworkServer.RegisterHandler(47, new NetworkMessageDelegate(this.OnServerReconnectPlayerMessage));
            NetworkClient networkClient = NetworkServer.BecomeHost(this.m_Client, port, this.m_MatchInfo, this.oldServerConnectionId, this.peers);
            bool          result;

            if (networkClient != null)
            {
                if (NetworkManager.singleton != null)
                {
                    NetworkManager.singleton.RegisterServerMessages();
                    NetworkManager.singleton.UseExternalClient(networkClient);
                }
                else
                {
                    Debug.LogWarning("MigrationManager BecomeNewHost - No NetworkManager.");
                }
                networkClient.RegisterHandlerSafe(11, new NetworkMessageDelegate(this.OnPeerInfo));
                this.RemovePendingPlayer(this.m_OldServerConnectionId);
                this.Reset(-1);
                this.SendPeerInfo();
                result = true;
            }
            else
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("NetworkServer.BecomeHost failed");
                }
                result = false;
            }
            return(result);
        }