Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct response to remote player quit in Game Center

I have a turn-based match with two participants, A and B. It is currently A's turn. B quits out of turn by calling:

[match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit ... etc.

As far as A's Game Center app is concerned, the match with B is still in play – the match status is GKTurnBasedMatchStatusOpen, and the match outcomes are GKTurnBasedMatchOutcomeNone and GKTurnBasedMatchOutcomeQuit respectively.

From the documentation, it appears that participant A should detect this and call:

participantA.matchOutcome = GKTurnBasedMatchOutcomeWon;
participantB.matchOutcome = GKTurnBasedMatchOutcomeQuit;

[self endMatchInTurnWithMatchData: ... etc.

However, there seems to be no notification for participantQuitOutOfTurnWithOutcome, and periodically iterating through each match to end turns feels like a kludge.

What is the correct approach to ending these matches?

like image 371
jnic Avatar asked May 19 '14 20:05

jnic


1 Answers

It has a nice solution :)

First of all you set a handler

[GKTurnBasedEventHandler sharedTurnBasedEventHandler].delegate = self;

After which, you will get the callbacks

handleInviteFromGameCenter:
handleTurnEventForMatch:didBecomeActive:
handleMatchEnded:
handleTurnEventForMatch:didBecomeActive:
handleTurnEventForMatch:didBecomeActive:
player:receivedExchangeRequest:forMatch:
player:receivedExchangeCancellation:forMatch:
player:receivedExchangeReplies:forCompletedExchange:forMatch:

You need this method

handleMatchEnded:

To handle the match end on the opponent side.

Here is link to documentation https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/ImplementingaTurn-BasedMatch/ImplementingaTurn-BasedMatch.html#//apple_ref/doc/uid/TP40008304-CH15-SW12

like image 105
l0gg3r Avatar answered Sep 22 '22 03:09

l0gg3r