Yevhen Samoilov
Yevhen Samoilov

Reputation: 159

The issue with real-time multiplayer from google services (adding an exclusive bitmask to your room configuration)

So, I am writing real-time multiplayer it based on Google Services (Real-time Multiplayer). And I want to add different roles for automatch criteria. In the google documentation it look like this:

If your game has multiple player roles (such as farmer, archer, and wizard) and you want to restrict auto-matched games to one player of each role, add an exclusive bitmask to your room configuration. When auto-matching with this option, players will only be considered for a match when the logical AND of their exclusive bit masks is equal to 0. The following example shows how to use the bit mask to perform auto matching with three exclusive roles:

In this example we will wait 2 random opponents with an exclusive role.

private static final long ROLE_FARMER = 0x1; // 001 in binary
private static final long ROLE_ARCHER = 0x2; // 010 in binary
private static final long ROLE_WIZARD = 0x4; // 100 in binary

    private void startQuickGame(long role) {
        // auto-match with two random auto-match opponents of different roles
        Bundle am = RoomConfig.createAutoMatchCriteria(2, 2, role);

        // build the room config
        RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
        roomConfigBuilder.setAutoMatchCriteria(am);

        // create room, etc.
        // ...
    }

When I replace an exlusive role to 0 it works fine. But if I add some bit mask, such as 0x1 for each opponent it dosen't works. Players don't connect to the room. I tested this issue with google sample for Real-time multiplayer: https://github.com/playgameservices/android-basic-samples/tree/master/BasicSamples/ButtonClicker It doesn't work too. Could you help me with this problem? I can not solve it.

Upvotes: 1

Views: 233

Answers (1)

Yevhen Samoilov
Yevhen Samoilov

Reputation: 159

So, I solve my problem. If you want to connect players with specific options. You need to use roomConfigBuilder.setVariant(0x4);

Upvotes: 4

Related Questions