Search Unity

[UNET 5.4] Is there a proper way to completely and immediately destroy a match?

Discussion in 'UNet' started by firestorm713q, Aug 18, 2016.

  1. firestorm713q

    firestorm713q

    Joined:
    Jan 6, 2013
    Posts:
    16
    I'm currently working on a 1v1 multiplayer game (using the 5.4 version of UNET), and a problem I've been running into is that whenever I'm testing, after I disconnect both host and client, I have to sit and wait for 30 seconds, lest I join the match I just left. This also causes problems when players finish a game, or there's a disconnect in the middle of the game, or any other instance where there's an open match sitting on the matchmaker server.

    Is there some magic way to actually flag a match in such a way that people can't join? If not, how would you go about solving the problem of empty matches and matches-in-progress-but-in-the-process-of-being-destroyed.

    Here's the relevant functions

    Code (CSharp):
    1.  
    2.     public void OnTryDisconnect()
    3.     {
    4.         if (numUsers > 0)
    5.             numUsers = 0;
    6.         if (numTimesLobbyConnectCalled > 0)
    7.             numTimesLobbyConnectCalled = 0;
    8.         if(state == NetworkCtrlState.HOSTING || state == NetworkCtrlState.JOINING)
    9.         {
    10.             state = NetworkCtrlState.TRYING_TO_DC;
    11.             return;
    12.         }
    13.         Debug.Log("Disconnecting all network activities");
    14.         Debug.Log(IsServer);
    15.         if(IsServer)
    16.         {
    17.             Debug.Log("Trying to destroy match");
    18.             if (matchMaker != null && matchInfo != null)
    19.                 matchMaker.DestroyMatch(matchInfo.networkId, 0, OnDestroyMatch);
    20.             else
    21.                 OnDestroyMatch(true, "");
    22.         }
    23.         else if(IsConnected)
    24.         {
    25.             Debug.Log("Dropping Connection");
    26.             if (matchMaker != null && matchInfo != null)
    27.                 matchMaker.DropConnection(matchInfo.networkId, matchInfo.nodeId, 0, OnConnectionDrop);
    28.             else
    29.                 OnDropConnection(true, "");
    30.         }
    31.     }
    32.  
    33.  
    which will call

    Code (csharp):
    1.  
    2. public override void OnDestroyMatch(bool success, string extendedInfo)
    3.     {
    4.         StopHost();
    5.         StopMatchMaker();
    6.         if(state == NetworkCtrlState.TRYING_TO_HOST)
    7.         {
    8.             createGame();
    9.         }
    10.         else if(state == NetworkCtrlState.CLIENT_DISCONNECTED_IN_GAME || state == NetworkCtrlState.DISCONNECTING_AS_HOST)
    11.         {
    12.             ChangeState(NetworkCtrlState.DISCONNECTED);
    13.             //CVBNetworkLobbyHUD.CVBNetworkLobbyHUDSingleton.OnBackToMainMenu();
    14.             OnQuickPlay();
    15.         }
    16.         else
    17.         {
    18.             ChangeState(NetworkCtrlState.DISCONNECTED);
    19.             OnQuickPlay();
    20.         }
    21.         base.OnDestroyMatch(success, extendedInfo);
    22.     }
    23.  
    if it's the server, and

    Code (csharp):
    1.  
    2. void OnConnectionDrop(bool success, string extendedInfo)
    3.     {
    4.         StopClient();
    5.         StopMatchMaker();
    6.         if(this.state == NetworkCtrlState.REJOINING_NEW_GAME)
    7.         {
    8.             OnQuickPlay();
    9.         }
    10.         else
    11.         {
    12.             ChangeState(NetworkCtrlState.DISCONNECTED);
    13.             OnQuickPlay();
    14.         }
    15.     }
    16.  
    if it's the client.