com.google.android.gms.games.multiplayer.realtime.RealTimeMessage Java Examples

The following examples show how to use com.google.android.gms.games.multiplayer.realtime.RealTimeMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RealTimeMultiplayer.java    From godot-gpgs with MIT License 5 votes vote down vote up
@Override
public void onRealTimeMessageReceived(RealTimeMessage rtm) {
    byte[] buf = rtm.getMessageData();
    String sender = rtm.getSenderParticipantId();
    Log.d(TAG, "Message received: " + (char) buf[0] + "/" + (int) buf[1]);
    String msg = new String(buf);
    GodotLib.calldeferred(instanceId, "_on_gpgs_rtm_message_received", new Object[] { sender, msg });
}
 
Example #2
Source File: DrawingActivity.java    From 8bitartist with Apache License 2.0 5 votes vote down vote up
@Override
public void onRealTimeMessageReceived(RealTimeMessage realTimeMessage) {
    Log.d(TAG, "onRealTimeMessageReceived");
    byte[] data = realTimeMessage.getMessageData();

    onMessageReceived(data);
}
 
Example #3
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onRealTimeMessageReceived(@NonNull RealTimeMessage realTimeMessage) {
  byte[] buf = realTimeMessage.getMessageData();
  String sender = realTimeMessage.getSenderParticipantId();
  Log.d(TAG, "Message received: " + (char) buf[0] + "/" + (int) buf[1]);

  if (buf[0] == 'F' || buf[0] == 'U') {
    // score update.
    int existingScore = mParticipantScore.containsKey(sender) ?
        mParticipantScore.get(sender) : 0;
    int thisScore = (int) buf[1];
    if (thisScore > existingScore) {
      // this check is necessary because packets may arrive out of
      // order, so we
      // should only ever consider the highest score we received, as
      // we know in our
      // game there is no way to lose points. If there was a way to
      // lose points,
      // we'd have to add a "serial number" to the packet.
      mParticipantScore.put(sender, thisScore);
    }

    // update the scores on the screen
    updatePeerScoresDisplay();

    // if it's a final score, mark this participant as having finished
    // the game
    if ((char) buf[0] == 'F') {
      mFinishedParticipants.add(realTimeMessage.getSenderParticipantId());
    }
  }
}