searchGameSessions method
Retrieves all active game sessions that match a set of search criteria and sorts them in a specified order. You can search or sort by the following game session attributes:
-
gameSessionId -- A unique identifier for the game session. You can
use either a
GameSessionId
orGameSessionArn
value. - gameSessionName -- Name assigned to a game session. This value is set when requesting a new game session with CreateGameSession or updating with UpdateGameSession. Game session names do not need to be unique to a game session.
-
gameSessionProperties -- Custom data defined in a game session's
GameProperty
parameter.GameProperty
values are stored as key:value pairs; the filter expression must indicate the key and a string to search the data values for. For example, to search for game sessions with custom data containing the key:value pair "gameMode:brawl", specify the following:gameSessionProperties.gameMode = "brawl"
. All custom data values are searched as strings. - maximumSessions -- Maximum number of player sessions allowed for a game session. This value is set when requesting a new game session with CreateGameSession or updating with UpdateGameSession.
- creationTimeMillis -- Value indicating when a game session was created. It is expressed in Unix time as milliseconds.
- playerSessionCount -- Number of players currently connected to a game session. This value changes rapidly as players join the session or drop out.
- hasAvailablePlayerSessions -- Boolean value indicating whether a game session has reached its maximum number of players. It is highly recommended that all search requests include this filter attribute to optimize search performance and return only sessions that players can join.
You can search for game sessions one fleet at a time only. To find game
sessions across multiple fleets, you must search each fleet separately and
combine the results. This search feature finds only game sessions that are
in ACTIVE
status. To locate games in statuses other than
active, use DescribeGameSessionDetails.
- CreateGameSession
- DescribeGameSessions
- DescribeGameSessionDetails
- SearchGameSessions
- UpdateGameSession
- GetGameSessionLogUrl
- Game session placements
May throw InternalServiceException. May throw NotFoundException. May throw InvalidRequestException. May throw UnauthorizedException. May throw TerminalRoutingStrategyException.
Parameter aliasId
:
A unique identifier for an alias associated with the fleet to search for
active game sessions. You can use either the alias ID or ARN value. Each
request must reference either a fleet ID or alias ID, but not both.
Parameter filterExpression
:
String containing the search criteria for the session search. If no filter
expression is included, the request returns results for all game sessions
in the fleet that are in ACTIVE
status.
A filter expression can contain one or multiple conditions. Each condition consists of the following:
-
Operand -- Name of a game session attribute. Valid values are
gameSessionName
,gameSessionId
,gameSessionProperties
,maximumSessions
,creationTimeMillis
,playerSessionCount
,hasAvailablePlayerSessions
. -
Comparator -- Valid comparators are:
=
,<>
,<
,>
,<=
,>=
. -
Value -- Value to be searched for. Values may be numbers, boolean
values (true/false) or strings depending on the operand. String values are
case sensitive and must be enclosed in single quotes. Special characters
must be escaped. Boolean and string values can only be used with the
comparators
=
and<>
. For example, the following filter expression searches ongameSessionName
: "FilterExpression": "gameSessionName = 'Matt\\'s Awesome Game 1'"
.
AND
, OR
, and NOT
and
parentheses as needed. For example: x AND y AND NOT z
,
NOT (x OR y)
.
Session search evaluates conditions from left to right using the following precedence rules:
-
=
,<>
,<
,>
,<=
,>=
- Parentheses
- NOT
- AND
- OR
"maximumSessions>=10 AND hasAvailablePlayerSessions=true"
.
Parameter fleetId
:
A unique identifier for a fleet to search for active game sessions. You
can use either the fleet ID or ARN value. Each request must reference
either a fleet ID or alias ID, but not both.
Parameter limit
:
The maximum number of results to return. Use this parameter with
NextToken
to get results as a set of sequential pages. The
maximum number of results returned is 20, even if this value is not set or
is set higher than 20.
Parameter nextToken
:
Token that indicates the start of the next sequential page of results. Use
the token that is returned with a previous call to this operation. To
start at the beginning of the result set, do not specify a value.
Parameter sortExpression
:
Instructions on how to sort the search results. If no sort expression is
included, the request returns results in random order. A sort expression
consists of the following elements:
-
Operand -- Name of a game session attribute. Valid values are
gameSessionName
,gameSessionId
,gameSessionProperties
,maximumSessions
,creationTimeMillis
,playerSessionCount
,hasAvailablePlayerSessions
. -
Order -- Valid sort orders are
ASC
(ascending) andDESC
(descending).
"SortExpression": "creationTimeMillis ASC"
. Results
with a null value for the sort operand are returned at the end of the
list.
Implementation
Future<SearchGameSessionsOutput> searchGameSessions({
String? aliasId,
String? filterExpression,
String? fleetId,
int? limit,
String? nextToken,
String? sortExpression,
}) async {
_s.validateStringLength(
'filterExpression',
filterExpression,
1,
1024,
);
_s.validateNumRange(
'limit',
limit,
1,
1152921504606846976,
);
_s.validateStringLength(
'nextToken',
nextToken,
1,
1024,
);
_s.validateStringLength(
'sortExpression',
sortExpression,
1,
1024,
);
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'GameLift.SearchGameSessions'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
if (aliasId != null) 'AliasId': aliasId,
if (filterExpression != null) 'FilterExpression': filterExpression,
if (fleetId != null) 'FleetId': fleetId,
if (limit != null) 'Limit': limit,
if (nextToken != null) 'NextToken': nextToken,
if (sortExpression != null) 'SortExpression': sortExpression,
},
);
return SearchGameSessionsOutput.fromJson(jsonResponse.body);
}