startMatchmaking method
Uses FlexMatch to create a game match for a group of players based on
custom matchmaking rules. If you're also using GameLift hosting, a new
game session is started for the matched players. Each matchmaking request
identifies one or more players to find a match for, and specifies the type
of match to build, including the team configuration and the rules for an
acceptable match. When a matchmaking request identifies a group of players
who want to play together, FlexMatch finds additional players to fill the
match. Match type, rules, and other features are defined in a
MatchmakingConfiguration
.
To start matchmaking, provide a unique ticket ID, specify a matchmaking
configuration, and include the players to be matched. For each player, you
must also include the player attribute values that are required by the
matchmaking configuration (in the rule set). If successful, a matchmaking
ticket is returned with status set to QUEUED
.
Track the status of the ticket to respond as needed. If you're also using GameLift hosting, a successfully completed ticket contains game session connection information. Ticket status updates are tracked using event notification through Amazon Simple Notification Service (SNS), which is defined in the matchmaking configuration.
Learn more
Add FlexMatch to a Game Client
Set Up FlexMatch Event Notification
Related operations
May throw InvalidRequestException. May throw NotFoundException. May throw InternalServiceException. May throw UnsupportedRegionException.
Parameter configurationName
:
Name of the matchmaking configuration to use for this request. Matchmaking
configurations must exist in the same Region as this request. You can use
either the configuration name or ARN value.
Parameter players
:
Information on each player to be matched. This information must include a
player ID, and may contain player attributes and latency data to be used
in the matchmaking process. After a successful match, Player
objects contain the name of the team the player is assigned to.
Parameter ticketId
:
A unique identifier for a matchmaking ticket. If no ticket ID is specified
here, Amazon GameLift will generate one in the form of a UUID. Use this
identifier to track the matchmaking ticket status and retrieve match
results.
Implementation
Future<StartMatchmakingOutput> startMatchmaking({
required String configurationName,
required List<Player> players,
String? ticketId,
}) async {
ArgumentError.checkNotNull(configurationName, 'configurationName');
_s.validateStringLength(
'configurationName',
configurationName,
1,
256,
isRequired: true,
);
ArgumentError.checkNotNull(players, 'players');
_s.validateStringLength(
'ticketId',
ticketId,
0,
128,
);
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'GameLift.StartMatchmaking'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'ConfigurationName': configurationName,
'Players': players,
if (ticketId != null) 'TicketId': ticketId,
},
);
return StartMatchmakingOutput.fromJson(jsonResponse.body);
}