Google play services 16.0.0 realtime Multiplayer problem. One single broadcast of a message causes hundreds of onRealTimeMessageReceived

0

We have published an app on September 2017 with realtime multiplayer play-services-games:9.8.0 and it is functioning properly.

Now that we have to update to play-services-games:16.0.0 we encounter serious problems.

During gameplay player sends till 70 UnreliableMessage and gets till 210 onRealTimeMessageReceived per second to update positions, velocities, and ranking. I have checked in the Google API Console that this is well below my quotas limits and everything is just fine in play-services-games:9.8.0.

Right after gameplay, player sends a single ReliableMessage broadcast that he has finished

my Logcat output:

D: 'F' state == 1 multiLVL:1 myVelX:0
D: state: p.getParticipantId(): p.getDisplayName():1 :p_CL-dmtHltfqngwEQAQ :JohnWarrior2006 :p_CL-dmtHltfqngwEQAw :Kostas43
D: state: p.getParticipantId(): p.getDisplayName():1 :p_CL-dmtHltfqngwEQBA :Johnny20061117 :p_CL-dmtHltfqngwEQAw :Kostas43
D: state: p.getParticipantId(): p.getDisplayName():1 :p_CL-dmtHltfqngwEQAg :Nikos2010 :p_CL-dmtHltfqngwEQAw :Kostas43
D: &&& GAME &&&& FinishedPl broadcastScore

but the other players get hundreds onRealTimeMessageReceived of the single message continuously for some time in play-services-games:16.0.0. This malfunction does not appear if i disable position, velocities updating during gameplay.

my Logcat output:

D: Message received: F thisScore:36698 sender:p_CJHbxo3H8bKE-wEQBA
D: Message received: F thisScore:39910 sender:p_CJHbxo3H8bKE-wEQAw
D: Message received: F thisScore:36698 sender:p_CJHbxo3H8bKE-wEQBA
D: Message received: F thisScore:39910 sender:p_CJHbxo3H8bKE-wEQAw
D: Message received: F thisScore:36698 sender:p_CJHbxo3H8bKE-wEQBA
D: Message received: F thisScore:39910 sender:p_CJHbxo3H8bKE-wEQAw
D: Message received: F thisScore:36698 sender:p_CJHbxo3H8bKE-wEQBA
                        .............
                        .............
                        .............
D: Message received: F thisScore:39910 sender:p_CJHbxo3H8bKE-wEQAw
D: Message received: F thisScore:36698 sender:p_CJHbxo3H8bKE-wEQBA
D: Message received: F thisScore:39910 sender:p_CJHbxo3H8bKE-wEQAw
D: Message received: F thisScore:36698 sender:p_CJHbxo3H8bKE-wEQBA
D: Message received: F thisScore:39910 sender:p_CJHbxo3H8bKE-wEQAw
D: Message received: F thisScore:36698 sender:p_CJHbxo3H8bKE-wEQBA
D: Message received: F thisScore:39910 sender:p_CJHbxo3H8bKE-wEQAw

If the player presses the button to rematch, he sends a single ReliableMessage broadcast

my Logcat output:

D: 'R' state == 3 multiLVL:0 myVelX:0
D: state: p.getParticipantId(): p.getDisplayName():3 :p_CL-dmtHltfqngwEQAQ :JohnWarrior2006 :p_CL-dmtHltfqngwEQAw :Kostas43
D: state: p.getParticipantId(): p.getDisplayName():3 :p_CL-dmtHltfqngwEQBA :Johnny20061117 :p_CL-dmtHltfqngwEQAw :Kostas43
D: state: p.getParticipantId(): p.getDisplayName():3 :p_CL-dmtHltfqngwEQAg :Nikos2010 :p_CL-dmtHltfqngwEQAw :Kostas43
D: GAME multiGameBounds > broadcastScore

but again the other players get hundreds onRealTimeMessageReceived of the single message continuously for some time in play-services-games:16.0.0. This malfunction does not appear in all devices.

my Logcat output:

D: (char) buf[0] == 'R':
D: Message received: R thisScore:47262 sender:p_CJHbxo3H8bKE-wEQAw
D: (char) buf[0] == 'R':
D: Message received: R thisScore:47262 sender:p_CJHbxo3H8bKE-wEQAw
D: (char) buf[0] == 'R':
                       .............
                       .............
                       .............
D: (char) buf[0] == 'R':
D: Message received: R thisScore:47262 sender:p_CJHbxo3H8bKE-wEQAw
D: (char) buf[0] == 'R':
D: Message received: R thisScore:47262 sender:p_CJHbxo3H8bKE-wEQAw
D: (char) buf[0] == 'R':

Some relevant parts of code:

OnRealTimeMessageReceivedListener mOnRealTimeMessageReceivedListener = new OnRealTimeMessageReceivedListener() {
    @Override
    public void onRealTimeMessageReceived(@NonNull RealTimeMessage realTimeMessage) {
        byte[] buf = realTimeMessage.getMessageData();
        String sender = realTimeMessage.getSenderParticipantId();
        //Log.d(TAG,"ParticipantID: "+sender);

                        .............

        //if (buf[0] != 'F') {
                Log.d(TAG, "Message received: " + (char) buf[0] + " thisScore:" + thisScore+" sender:"+sender);
        //}

                        .............

        if ((char) buf[0] == 'F') {
            int r1st = buf[6] & 0x000000ff;
            if (r1st == 1) {
                somebody1st = true;
                for (int p = 0; p < pls.size(); p++) {
                    if (pls.get(p).playerId.equals(sender)) {
                        pls.get(p).multiLevel = true;
                    }
                }
            }
            int finPosY = buf[5] & 0x000000ff;
            for (int i = 0; i < pNUM; i++) {
                 if (/*finishedPlayers[i].equals(" ") ||*/ !finishedPlayers[0].equals(sender) &&
                   !finishedPlayers[1].equals(sender) && !finishedPlayers[2].equals(sender) &&
                   !finishedPlayers[3].equals(sender)) {
                   if (finishedPlayers[i].equals(" ")) {
                       finishedPlayers[i] = realTimeMessage.getSenderParticipantId();
                       playLifeSound++;
                       Log.d(TAG, "FinishedPl: " + finishedPlayers[i] + " sender:" + sender);
                       break;
                    }
                 }
             }
             for (int p = 0; p < pls.size(); p++) {
                  if (pls.get(p).playerId.equals(sender)) {
                       if (finPosY == 1)
                           pls.get(p).positionY = 2000;
                       else
                           pls.get(p).positionY = 0;
                      break;
                  }
             }
        }

                        .............                           

        if ((char) buf[0] == 'R') {
             rPLA = realTimeMessage.getSenderParticipantId();
             Log.d(TAG, "(char) buf[0] == 'R':" );
             for (int p = 0; p < pls.size(); p++) {
                  if (pls.get(p).playerId.equals(sender)) {
                      pls.get(p).jetSurf = buf[5] & 0x000000ff;
                      break;
                  }
             }
        }

                        .............                          

        updatePeerScoresDisplay();
    }
};

and:

public void broadcastScore(int state,int myScore,int myCordx,int myCordy,int multiLVL,int myVelX,int myVelY) {

                        .............

     if (state == 1) {
            mMsgBuf[0] = (byte) 'F';
            mMsgBuf[5] = (byte) multiLVL;
            mMsgBuf[6] = (byte) myVelX;
            Log.d(TAG,"'F' state == 1 multiLVL:"+multiLVL+" myVelX:"+myVelX);
     } 

                        .............

     if (state == 3) {
            mMsgBuf[0] = (byte) 'R';
            mMsgBuf[5] = (byte) multiLVL;
            Log.d(TAG,"'R' state == 3 multiLVL:"+multiLVL+" myVelX:"+myVelX);
     } 

                        .............

    // Send to every other participant.
    if (mParticipants != null) {
        for (Participant p : mParticipants) {
            if (p.getParticipantId().equals(mMyId))
                continue;
            if (p.getStatus() != Participant.STATUS_JOINED)
                continue;
            if (leftPL < 3 && mRoomId != null && isSignedIn()) {
                if (state != 0 && state != 5) {
                    // final score notification must be sent via reliable message
                    Log.d(TAG, "state: p.getParticipantId(): p.getDisplayName():" + state + " :" + p.getParticipantId() + " :" + p.getDisplayName()
                            + " :" + mMyId+ " :" + myName);
                    mRealTimeMultiplayerClient.sendReliableMessage(mMsgBuf,
                            mRoomId, p.getParticipantId(), new RealTimeMultiplayerClient.ReliableMessageSentCallback() {
                                @Override
                                public void onRealTimeMessageSent(int statusCode, int tokenId, String recipientParticipantId) {
                                    //Log.d(TAG, "RealTime message sent");
                                    //Log.d(TAG, "  statusCode: " + statusCode);
                                    //Log.d(TAG, "  tokenId: " + tokenId);
                                    //Log.d(TAG, "  recipientParticipantId: " + recipientParticipantId);
                                }
                            })
                            .addOnSuccessListener(new OnSuccessListener<Integer>() {
                                @Override
                                public void onSuccess(Integer tokenId) {
                                    //Log.d(TAG, "Created a reliable message with tokenId: " + tokenId);
                                }
                            });    
                } else {
                    // it's an interim score notification, so we can use unreliable
                    mRealTimeMultiplayerClient.sendUnreliableMessage(mMsgBuf, mRoomId, p.getParticipantId());    

                }
            }
        }
    }
}
google-play-services
real-time-multiplayer
asked on Stack Overflow Jan 29, 2019 by Kostas Trakos

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0