19

I'm having trouble figuring out how to reinvite a disconnected player in a good way, using the GKMatch class for the Game Center. The game is a 1 vs. 1 game.

When I detect a disconnected player, I try to reinvite that specific player to the match with this call:

[[GKMatchmaker sharedMatchmaker] addPlayersToMatch:theMatch matchRequest:request completionHandler:^(NSError *error)

This works as it's supposed to do. When the other player has established the connection he gets reinvited and the match can continue. But this leaves a problem I haven't been able to solve. Here comes the scenario:

  • Player 1 disconnects.
  • Player 2 leaves the match while Player 1 is disconnected.
  • Player 1 reconnects and detects that he lost connection to Player 2 and tries to reconnect to player2.
  • Player 2 is looking for a new match, which he is doing with the matchmakerViewController.
  • Player 2 suddenly joins the old match with Player 1, which he had left.

So my problem is that the matchmakerViewController let's players join old matches if they're reinvited. Is there a better way to handle this reconnection scenario so people won't get invited back to old matches?

ThomasCle
  • 6,792
  • 7
  • 41
  • 81
  • @Cupcake.In my code it is happening that when 1player get disconnected other automatically disconnect from the game.Y it happen so?how to avoid this disconnection of player 1 though player 2get diconnect – ios developer Oct 03 '12 at 10:58

2 Answers2

1

You could provide an option to the player that still is connected, to either re-invite, or quit. You could also remove the matchmaking request to the player that left if the other player leaves.

wquist
  • 2,569
  • 1
  • 15
  • 14
  • My problems is the reinviting. Player 1 reinvites player 2 while player 2 is looking for a new game. This is a problem because player 2 will get reinvited to a game he left. I can't remove the matchmaking request if the other player leaves, because I don't know when he leaves. They're not connected at this point and cannot tell if the player leaves. – ThomasCle Jun 19 '12 at 10:13
0

I would go ahead and prevent the reinvite from Player 1 on the same game if I detected Player 2 has used the quit function instead of timing out on a disconnect.

John
  • 61
  • 2