Skip to content

Commit ab17a38

Browse files
authored
fix: GameLift allocator MatchProperties Region and MaxPlayers (#16)
1 parent 827c61b commit ab17a38

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

modules/GameLiftAllocator/Project/GameLiftAllocator.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ public class GameLiftAllocator(IGameApiClient gameApiClient, IGameLiftFactory ga
4343
public async Task<AllocateResponse> Allocate(IExecutionContext context, AllocateRequest request)
4444
{
4545
// Determine AWS region from match properties or use default
46-
var region = request.MatchmakingResults.MatchProperties.GetValueOrDefault("region")?.ToString() ?? DefaultAwsRegion;
46+
var regionValue = request.MatchmakingResults.MatchProperties.GetValueOrDefault("Region")?.ToString();
47+
var region = string.IsNullOrEmpty(regionValue) ? DefaultAwsRegion : regionValue;
48+
49+
// maxPlayers is only available in match properties when using Cloud Code hosting
50+
// It is not present when using Multiplay hosting with Cloud Code override
51+
var maximumPlayerSessionCount = request.MatchmakingResults.MatchProperties.GetValueOrDefault("MaxPlayers") ?? DefaultMaximumPlayerSessionCount;
4752

4853
try
4954
{
@@ -62,7 +67,7 @@ public async Task<AllocateResponse> Allocate(IExecutionContext context, Allocate
6267
{
6368
PlacementId = request.MatchId, // Use matchId for idempotency
6469
GameSessionQueueName = GameSessionQueueName,
65-
MaximumPlayerSessionCount = DefaultMaximumPlayerSessionCount,
70+
MaximumPlayerSessionCount = Convert.ToInt32(maximumPlayerSessionCount),
6671
GameSessionData = gameSessionData
6772
};
6873

tests/AllocatorTests/GameLiftAllocatorTests.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,29 @@ public async Task TestThatGameLiftCanAllocate()
5555
Assert.That(allocation.AllocationData["placementId"], Is.EqualTo("placementId"));
5656
}
5757

58+
[Test]
59+
public async Task TestThatGameLiftDefaultsRegionWhenEmptyString()
60+
{
61+
_gameLiftMock.Reset();
62+
_gameLiftMock.Setup(g => g.StartGameSessionPlacementAsync(It.IsAny<StartGameSessionPlacementRequest>(), CancellationToken.None))
63+
.ReturnsAsync(new StartGameSessionPlacementResponse
64+
{
65+
GameSessionPlacement = new GameSessionPlacement
66+
{
67+
PlacementId = "placementId",
68+
}
69+
});
70+
71+
var allocation = await _allocator.Allocate(_executionContextMock.Object, new AllocateRequest("1234",
72+
new MatchmakingResults(null, "matchId", "poolId", "poolName", "queueName", new
73+
Dictionary<string, object>{
74+
{"Region", ""},
75+
})));
76+
77+
Assert.That(allocation.AllocationData, Is.Not.Null);
78+
Assert.That(allocation.AllocationData["awsRegion"], Is.EqualTo("eu-west-2"));
79+
}
80+
5881
[Test]
5982
public async Task TestThatGameLiftCanAllocateToRegions()
6083
{
@@ -71,7 +94,7 @@ public async Task TestThatGameLiftCanAllocateToRegions()
7194
var allocation = await _allocator.Allocate(_executionContextMock.Object, new AllocateRequest("1234",
7295
new MatchmakingResults(null, "matchId", "poolId", "poolName", "queueName", new
7396
Dictionary<string, object>{
74-
{"region", "customRegion"},
97+
{"Region", "customRegion"},
7598
})));
7699

77100
Assert.That(allocation.AllocationData, Is.Not.Null);

0 commit comments

Comments
 (0)