Exemplo n.º 1
0
        internal void OnClientDisconnectInternal(NetworkMessage netMsg)
        {
            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkManager:OnClientDisconnectInternal");
            }

#if ENABLE_UNET_HOST_MIGRATION
            if (m_MigrationManager != null)
            {
                if (m_MigrationManager.LostHostOnClient(netMsg.conn))
                {
                    // should OnClientDisconnect be called?
                    return;
                }
            }
#endif

            if (m_OfflineScene != "")
            {
                //ClientChangeScene(m_OfflineScene, false);
            }

            // If we have a valid connection here drop the client in the matchmaker before shutting down below
            if (matchMaker != null && matchInfo != null && matchInfo.networkId != NetworkID.Invalid && matchInfo.nodeId != NodeID.Invalid)
            {
                matchMaker.DropConnection(matchInfo.networkId, matchInfo.nodeId, matchInfo.domain, OnDropConnection);
            }

            OnClientDisconnect(netMsg.conn);
        }
Exemplo n.º 2
0
 public void OnShutdownButtonClick()
 {
     m_StateDisplay.text = "已断开与服务器的连接";
     m_NetworkMatch.DropConnection(m_MatchInfo.networkId, m_MatchInfo.nodeId, 0, OnConnectionDropped);
     m_CreateButton.SetActive(true);
     m_JoinButton.SetActive(true);
     m_ShutdownButton.SetActive(false);
 }
Exemplo n.º 3
0
 internal void OnClientDisconnectInternal(NetworkMessage netMsg)
 {
     if (LogFilter.logDebug)
     {
         Debug.Log("NetworkManager:OnClientDisconnectInternal");
     }
     if (!(m_MigrationManager != null) || !m_MigrationManager.LostHostOnClient(netMsg.conn))
     {
         if (!string.IsNullOrEmpty(m_OfflineScene))
         {
             ClientChangeScene(m_OfflineScene, forceReload: false);
         }
         if (matchMaker != null && matchInfo != null && matchInfo.networkId != NetworkID.Invalid && matchInfo.nodeId != 0)
         {
             matchMaker.DropConnection(matchInfo.networkId, matchInfo.nodeId, matchInfo.domain, OnDropConnection);
         }
         OnClientDisconnect(netMsg.conn);
     }
 }
    void OnApplicationQuit()
    {
        if (isHost && matchInfo != null)
        {
            // If the match is not destroyed, the room will stay visible for 20-30 seconds, confusing new clients

            // This method is not reliable, as the application quits before DestroyMatch is able to finish
            networkMatcher.DestroyMatch(matchInfo.networkId, 0, OnDestroyMatch);
            PrintLogger.printLog("NetworkManager: Application quit with client as host; destroying room");
        }
        networkMatcher.DropConnection(matchInfo.networkId, matchInfo.nodeId, 0, OnDropConnection);

        GameManagerScript.instance.isActivePlayer = false;
        GameManagerScript.instance.registerPlayers();
    }
Exemplo n.º 5
0
    void OnGUI()
    {
        if (string.IsNullOrEmpty(Application.cloudProjectId))
        {
            GUILayout.Label("You must set up the project first. See the Multiplayer tab in the Service Window");
        }
        else
        {
            GUILayout.Label("Cloud Project ID: " + Application.cloudProjectId);
        }

        if (m_MatchJoined)
        {
            GUILayout.Label("Match joined '" + m_MatchName + "' on Matchmaker server");
        }
        else if (m_MatchCreated)
        {
            GUILayout.Label("Match '" + m_MatchName + "' created on Matchmaker server");
        }

        GUILayout.Label("Connection Established: " + m_ConnectionEstablished);

        if (m_MatchCreated || m_MatchJoined)
        {
            GUILayout.Label("Relay Server: " + m_MatchInfo.address + ":" + m_MatchInfo.port);
            GUILayout.Label("NetworkID: " + m_MatchInfo.networkId + " NodeID: " + m_MatchInfo.nodeId);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Outgoing message:");
            m_NetworkMessage = GUILayout.TextField(m_NetworkMessage);
            GUILayout.EndHorizontal();
            GUILayout.Label("Last incoming message: " + m_LastReceivedMessage);

            if (m_ConnectionEstablished && GUILayout.Button("Send message"))
            {
                m_Writer.SeekZero();
                m_Writer.Write(m_NetworkMessage);
                byte error;
                for (int i = 0; i < m_ConnectionIds.Count; ++i)
                {
                    NetworkTransport.Send(m_HostId,
                                          m_ConnectionIds[i], 0, m_Writer.AsArray(), m_Writer.Position, out error);
                    if ((NetworkError)error != NetworkError.Ok)
                    {
                        Debug.LogError("Failed to send message: " + (NetworkError)error);
                    }
                }
            }

            if (GUILayout.Button("Shutdown"))
            {
                m_NetworkMatch.DropConnection(m_MatchInfo.networkId,
                                              m_MatchInfo.nodeId, 0, OnConnectionDropped);
            }
        }
        else
        {
            if (GUILayout.Button("Create Room"))
            {
                m_NetworkMatch.CreateMatch(m_MatchName, 4, true, "", "", "", 0, 0, OnMatchCreate);
            }

            if (GUILayout.Button("Join first found match"))
            {
                m_NetworkMatch.ListMatches(0, 1, "", true, 0, 0, (success, info, matches) =>
                {
                    if (success && matches.Count > 0)
                    {
                        m_NetworkMatch.JoinMatch(matches[0].networkId, "", "", "", 0, 0, OnMatchJoined);
                    }
                });
            }

            if (GUILayout.Button("List rooms"))
            {
                m_NetworkMatch.ListMatches(0, 20, "", true, 0, 0, OnMatchList);
            }

            if (m_MatchList.Count > 0)
            {
                GUILayout.Label("Current rooms:");
            }
            foreach (var match in m_MatchList)
            {
                if (GUILayout.Button(match.name))
                {
                    m_NetworkMatch.JoinMatch(match.networkId, "", "", "", 0, 0, OnMatchJoined);
                }
            }
        }
    }
Exemplo n.º 6
0
 public static void Desconectar_Servidor()
 {
     m_NetworkMatch.DropConnection(m_MatchInfo.networkId,
                                   m_MatchInfo.nodeId, 0, OnConnectionDropped);
 }
Exemplo n.º 7
0
 public void OnDisable()
 {
     m_NetworkMatch.DropConnection(m_MatchInfo.networkId, m_MatchInfo.nodeId, 0, null);
     NetworkTransport.Disconnect(hostId, connectionId, out error);
 }