Disconnect and close a Match - UNET Unity3d 5.2

Hallo everyone,

im wrote the following Script and it works fine. But I have some Questions:

  • But now i´m trying to close a match after it is opend from the host. How can I close or destroy it?
  • How can I disconnect a Client?
  • If i create a Match an leave it, i have to quit & restart the whole game, because the Network isn´t working anymore. Is there a possibilty to restart the NetworkManager?

I´m using the Networkmanagert in Editor and the following selfmade customized NetworkManagerHUD-Script:

#if ENABLE_UNET
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;

namespace UnityEngine.Networking
{
    [AddComponentMenu("Network/NetworkManagerHUD")]
    [RequireComponent(typeof(NetworkManager))]
    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
    public class NetworkManagerHUD : MonoBehaviour
    {
        public NetworkManager manager;
        [SerializeField] public bool showGUI = true;
        [SerializeField] public int offsetX;
        [SerializeField] public int offsetY;

        // Runtime variable
        bool showServer = false;

        public GameObject ScoreEntryPanel;
        public GameObject ScoreScrollList;
        public GameObject LoadingText;
        public bool loading = true;

        public bool hNetStart = true;

        public string randomNumber;
        public string gameName;


        void Awake() {

            manager = GetComponent<NetworkManager> ();
            manager.StopMatchMaker();
        }

        void Update()
        {   
            if (hNetStart) {

                if (NetworkClient.active && ClientScene.ready && MultiplayerGameController.Instance.Player==2 ) {
                    MultiplayerGameController.Instance.Player2Status = 1;
                    Debug.Log("TRUE2");
                    hNetStart=false;
                }
                if (NetworkClient.active && ClientScene.ready && MultiplayerGameController.Instance.Player==1) {
                    MultiplayerGameController.Instance.Player1Status = 1;
                    Debug.Log("TRUE1");
                    hNetStart=false;
                }

            }

        }

        public void DestroyMatch(){

            if (manager != null) {
                manager.StopHost ();
                ClientScene.ClearSpawners ();
                ClientScene.DestroyAllClientObjects ();
                manager.StopMatchMaker ();
           
           
                Network.Disconnect ();
                MasterServer.UnregisterHost ();
           

                manager.StartMatchMaker ();
           
                StartCoroutine (refreshingList ());
            }
        }

        public void QuickMatch(){
            FindInternetMatch ();
            if (manager.matches.Count > 0) {
                joinMatch (0);
                MultiplayerGameController.Instance.raisePlayerStatus();
            } else
                MultiplayerGameController.Instance.Player = 1;
                createMatch ();
                MultiplayerGameController.Instance.raisePlayerStatus();

        }

        public void createMatch()
        {
            manager.networkPort = Random.Range (7000, 70000);
            randomizeRoom ();
            manager.matchMaker.CreateMatch(gameName, 2, true, "", manager.OnMatchCreate);

            //manager.StartClient();
        }
        void randomizeRoom()
        {
            string nameForRoom = StaticHighscore.Instance.Name;
            if (nameForRoom == "")
                nameForRoom = "NoName";
            randomNumber=Random.Range (1,1000).ToString()+Random.Range (1,1000).ToString();
            gameName=nameForRoom+" "+randomNumber;
        }
        public void FindInternetMatch()
        {
            StartCoroutine (refreshingList ());
        }

        IEnumerator refreshingList()
        {
            loading = true;
            //FindInternetMatch
            yield return manager.matchMaker.ListMatches(0,25, "", manager.OnMatchList);
            loading = false;
            getScrollEntrys ();
        }


        public void joinMatch(int hNetworkID)
        {

            manager.matchMaker.JoinMatch(manager.matches[hNetworkID].networkId, "", manager.OnMatchJoined);
            MultiplayerGameController.Instance.setRoomPanelActive ();
        }



        public void getScrollEntrys()
        {
            int i = 0;
            //Destroy Objects that exists, because of a possible Call bevore
            foreach (Transform childTransform in ScoreScrollList.transform) Destroy(childTransform.gameObject);
            //Debug.Log ("Hostlist.length= " + NetworkManager.Instance.hostList.Length);
            foreach (var match in manager.matches) {
                loading=false;
                if(match.currentSize>0 && match.currentSize<2 && match.name!=gameName)
                {
               
                    Debug.Log ("Matchname== " + match.name);
                    Debug.Log ("Gamename== " + gameName);
                GameObject ScorePanel;
                ScorePanel = Instantiate (ScoreEntryPanel) as GameObject;
                ScorePanel.transform.parent = ScoreScrollList.transform;
                ScorePanel.transform.localScale = ScoreScrollList.transform.localScale;
                Transform ThisScoreName = ScorePanel.transform.Find ("ScoreText");
                Text ScoreName = ThisScoreName.GetComponent<Text> ();
                string helpString = "Room: "+match.name.ToString();
                if (helpString.Length>25)
                {helpString= helpString.Substring(0, 25);}
                ScoreName.text=helpString;
                //help= help.Substring(5, hs_get.text.Length-5);
                ButtonJoinHost ButtonJoinHost = ScorePanel.GetComponent<ButtonJoinHost>();
                ButtonJoinHost.changeID(i);
                i++;
                }


            }
           
        }

    }
#endif //ENABLE_UNET
}

I’m “shutting it all down” like this:

    void Disconnect() {
        if (isHost) {
            if (matchMaker != null) {
                if (matchInfo != null) {
                    matchMaker.DestroyMatch(matchInfo.networkId, OnMatchMakerDestroy);
                }
            }
            NetworkServer.Shutdown ();
        }
        if (client != null) {
            client.Disconnect ();
        }
    }

and that seems to work for me. However, the callback – OnMatchMakerDestroy – is never called, and the match remains in the matchmaking queue for some time (~15 seconds?). I’m wondering if there’s a way to remove the match from the matchmaking servers and get a confirmation when that’s done?

(Edit: see also, this thread: Matchmaking - DestroyMatch Does Not Do Anything - Unity Engine - Unity Discussions )