我有这段代码:
RoomConfig.Builder rtmConfigBuilder = makeBasicRoomConfigBuilder();
rtmConfigBuilder.addPlayersToInvite(opponentId);
rtmConfigBuilder.setAutoMatchCriteria(null);
mGamesClient.createRoom(rtmConfigBuilder.build());
但我收到错误代码 6004 , STATUS_MULTIPLAYER_ERROR_INVALID_OPERATION
此多人游戏操作无效,服务器拒绝了该操作。查看日志以获取更多信息。
我认为这是因为 addPlayersToInvite 方法,因为我在Android文档中阅读了以下内容......
public RoomConfig.Builder addPlayersToInvite (String... playerIds)
Add one or more player IDs to invite to the room. This should be set only when calling create(GoogleApiClient, RoomConfig)
Parameters
playerIds One or more player IDs to invite to the room.
Returns
The builder instance.
请注意它是如何说这应该只在调用create(GoogleApiClient,RoomConfig)时设置,但我不知道如何调用方法或做什么。
所以我的问题基本上是这样的:我有我邀请的球员的身份,现在我想为球员和我创造一个空间。我怎么能这样做?
答案 0 :(得分:4)
我只是偶然发现了这个,所以很抱歉挖掘这个,但为后代:
您无法将autoMatchCriteria设置为null:
rtmConfigBuilder.setAutoMatchCriteria(null);
另外,您实际上无法将minAutoMatchPlayers和maxAutoMatchPlayers设置为0。
避免这种情况的最佳方法是进行零检查,如果minAutoMatchPlayers或maxAutoMatchPlayers等于0,则根本不使用setAutoMatchCriteria():
final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);
Bundle autoMatchCriteria = null;
int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);
if (minAutoMatchPlayers > 0) {
autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minAutoMatchPlayers, maxAutoMatchPlayers, 0);
} else {
autoMatchCriteria = null;
}
RoomConfig.Builder roomConfigBuilder = RoomConfig.builder(this);
if (autoMatchCriteria != null) {
roomConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
}
roomConfigBuilder.addPlayersToInvite(invitees);