2 Replies
      Latest reply on Mar 21, 2020 3:53 PM by uncletr
      uncletr Level 1 Level 1 (0 points)

        In my application, the player can HOST a game or can JOIN(FIND) a game randomly.

         

        The HOST player calls the function below to create a match with min/max players.  This results in the "GKMatchmakerViewController" being displayed where the HOST can then select "Play Now" to find other players automatically.   When all players are found and the match is created, then the "didFind match" function (below) is called.

         

        • findMatchWithGKMatchmakerVC(minPlayers: Int, maxPlayers: Int)
        • matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch)

         

        The player who wants to JOIN(FIND) a match calls the following function to find a match to join.  When the match is located and the match instance is provided, then the completion handler of this function is called.

         

            GKMatchmaker.shared().findMatch(for: matchRequest, withCompletionHandler: )

         

         

        After a player requests to JOIN a match, my application allows the player the option of "canceling" the match in case they want to stop waiting.  If the player cancels their request, then I need to ensure the current game environment is "cleaned up" properly so if the player then decides to make another JOIN request then their request will work.   I have seen when a player requests to JOIN, then cancels, then re-requests to JOIN, then the active GKMatchmakerViewController will not find the player at all.   This makes me think that I did not "clean up" my previous JOIN request properly/fully.

         

        I am performing the following to "clean up" the game environment when a player cancels their JOIN match request.

         

        1) When the call to find a match has been made but the "matchrequest completionHandler" has not been called yet (ie: no "match" instance  provided by Game Center yet), then I call the following to cancel the match request only:

         

                GKMatchmaker.shared().cancel( )

         

        2) Otherwise, when the "matchrequest completionHandler" was called already (meaning a "match" instance was provided by Game Center), then my application calls the following to disconnect from the match only

         

                myMatch.disconnect( )

         

         

        Question

        Do I need to do anything else to properly clean up the Game Center match request in my game environment?

        • Re: How to clean up match when canceling a findMatch request?
          PBK Level 7 Level 7 (3,765 points)

          A question.  You wrote:

           

          >  I have seen when a player requests to JOIN, then cancels, then re-requests to JOIN, then the active GKMatchmakerViewController will not find the player at all.  

           

          by "active GKMatchmakerViewController" are you referring the one that the player had just cancelled?

            • Re: How to clean up match when canceling a findMatch request?
              uncletr Level 1 Level 1 (0 points)

              Hey PBK,

               

              After many hours of investigation, I finally figured out what was going on which explains why the GKMatchmakerViewController did not find the players who requested join a match only (ie: not host a match).   It was because the player was being added into another match with another player who was a non-HOST.

               

              Basically, I had one player who set options for the game and was the HOST, and requested the matchmaker to go find other players to join the match.   This would result in the GKMatchmakerViewController interface being initiated, which would eventually spin looking for players.  I then had multiple other players simply request to "join" a match only (ie: not host a match).    I never saw these players being added to the GKMatchmakerViewController, however, I discovered these other players were being paired up for a match themselves.    For some reason I thought my code logic would prevent non-HOST players from being paired together but that turned out not to be the case.  

               

              This is all explained, along with my request for help, in my latest forum post called "How to prevent 2 players from joining a match together?"   Perhaps you can take a look at that post and see what you think?   If I cannot find a easy solution then I will need to redo a bunch of my user interface logic to fix my game (ie: a lot more effort)

               

              I do not think I need any assistance in this forum post anymore since this post turned out to be a red herring (ie: going down the wrong path on what I thought was happening, but really was not happening).