This used to work perfectly, but currently Game Services appear unable to handle the request issued by TurnBasedMultiplayer.finishMatch()
and my players cannot complete their games. Nothing unusual occurs during game play (taking turns), but completion results in response code 400.
What might be going on and what can I do about it?
Logcat:
W/GLSUser ( 887): GoogleAccountDataService.getToken()
I/qtaguid ( 1173): Failed write_ctrl(u 180) res=-1 errno=22
I/qtaguid ( 1173): Untagging socket 180 failed errno=-22
W/NetworkManagementSocketTagger( 1173): untagSocket(180) failed with errno -22
E/Volley ( 1188): [87] tm.a: Unexpected response code 400 for https://www.googleapis.com/games/v1/turnbasedmatches/ChEKCQjrgfqCvgsQAhACGAAgARDruaLm9un3vyg/finish?language=de_DE
E/dwr ( 1188): Failed to finish match: null
W/dwr ( 1188): {"code":400,"errors":[{"message":"Invalid results. results","domain":"global","reason":"InvalidMatchResults"}]}
D/UPDATE_MATCH_RESULT(30627): Status{statusCode=unknown status code: 6504, resolution=null}
Code:
ParticipantResult opponentResult = null;
ParticipantResult creatorResult = null;
if (mMatchData.opponentWonCounter > mMatchData.creatorWonCounter) {
opponentResult = new ParticipantResult(getParticipantId(),
ParticipantResult.MATCH_RESULT_WIN, 1);
creatorResult = new ParticipantResult(
mMatchData.creatorParticipantId,
ParticipantResult.MATCH_RESULT_LOSS, 2);
} else if (mMatchData.opponentWonCounter < mMatchData.creatorWonCounter) {
opponentResult = new ParticipantResult(getParticipantId(),
ParticipantResult.MATCH_RESULT_LOSS, 2);
creatorResult = new ParticipantResult(
mMatchData.creatorParticipantId,
ParticipantResult.MATCH_RESULT_WIN, 1);
} else {
opponentResult = new ParticipantResult(getParticipantId(),
ParticipantResult.MATCH_RESULT_TIE, 1);
creatorResult = new ParticipantResult(
mMatchData.creatorParticipantId,
ParticipantResult.MATCH_RESULT_TIE, 1);
}
Games.TurnBasedMultiplayer
.finishMatch(getApiClient(), mMatch.getMatchId(), data,
creatorResult, opponentResult)
.setResultCallback(
new ResultCallback<TurnBasedMultiplayer.UpdateMatchResult>() {
@Override
public void onResult(
TurnBasedMultiplayer.UpdateMatchResult result) {
Log.d("UPDATE_MATCH_RESULT", result
.getStatus().toString());
dismissProgress();
completeMatch();
}
});
EDIT:
I confirm that this works as intended. Also, the player taking the last turn can finish the match and post the final results.
I introduced a bug myself, so sorry for the confusion. (I have a two player setup. The 'creator' wasn't able to finish the match whereas the 'opponent' was. This was caused by participant IDs getting mixed up and code blindness preventing me from identifying the problem.)
Old answer:
Further investigation revealed that these methods had stopped working:
finishMatch(GoogleApiClient apiClient, String matchId, byte[] matchData, ParticipantResult... results)
finishMatch(GoogleApiClient apiClient, String matchId, byte[] matchData, List<ParticipantResult> results)
Whereas this one was still working flawlessly:
finishMatch(GoogleApiClient apiClient, String matchId)
I filed a bug report here: https://code.google.com/p/play-games-platform/issues/list .
EDIT: Acknowledged by Google: http://goo.gl/Ubqy9n
So here's the nasty workaround: 1) Take an extra turn to update the match. 2) Finish the match.
Games.TurnBasedMultiplayer
.takeTurn(getApiClient(), mMatch.getMatchId(), data,
nextParticipantId)
.setResultCallback(
new ResultCallback<TurnBasedMultiplayer.UpdateMatchResult>() {
@Override
public void onResult(UpdateMatchResult result) {
mMatch = result.getMatch();
Games.TurnBasedMultiplayer
.finishMatch(getApiClient(),
mMatch.getMatchId())
.setResultCallback(
new ResultCallback<TurnBasedMultiplayer.UpdateMatchResult>() {
@Override
public void onResult(
TurnBasedMultiplayer.UpdateMatchResult result) {
Log.d("UPDATE_MATCH_RESULT",
result.getStatus()
.toString());
dismissProgress();
completeMatch();
}
});
}
});