Search code examples
androidgoogle-play-servicesmultiplayergoogle-play-games

Detecting out of date ITurnBasedMatch on Android


I am writing a Turn-Based multiplayer Android game using the Google Play API.

Thinking ahead to future versions of the app, I realize I may need to change the format of my Byte Data Blob that gets passed around by the ITurnBasedMatch object.

And if I change the blob format, I will need to detect at runtime which version of the blob data I have received, so that it can be properly deserialized without crashing. Or at the least, throw up an error message and let the user know the match is no longer valid.

Is there anything built into the Google Play library that I could set/get a version number for the blob data, prior to deserializing it?

For reference here is the implementation of the callback function which Google-Play uses to notify the game that match data has changed:

    public void OnTurnBasedMatchReceived(ITurnBasedMatch match)
    {
        // This happens when the other player makes a move in a match we are
        // involved in (although not nessessarily playing right now).
        OnUpdateMatchInfoRecieved(match);
    }

Solution

  • I eneded up using the Serializable attribute built into C#. I chose this route, as it gracefully handles issues around versioning.

    More information can be found here:

    https://msdn.microsoft.com/en-us/library/7ay27kt9(v=vs.110).aspx