-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(gamelift): add MatchmakingRuleSet L2 Construct for GameLift #23091
Merged
mergify
merged 6 commits into
aws:main
from
stevehouel:houes/rfc-436-matchmaking-ruleset
Dec 6, 2022
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
96d844e
Adding new MatchmakingRuleSet construct and related tests
stevehouel 37397d3
Merge branch 'main' into houes/rfc-436-matchmaking-ruleset
stevehouel 38bdf89
Adding MatchmakingRuleSet JSON format check
stevehouel 5ce2783
Update matchmaking ruleset class property interface format
stevehouel 0b52011
Merge branch 'main' into houes/rfc-436-matchmaking-ruleset
stevehouel 9d36557
Merge branch 'main' into houes/rfc-436-matchmaking-ruleset
stevehouel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
packages/@aws-cdk/aws-gamelift/lib/matchmaking-ruleset-body.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import * as fs from 'fs'; | ||
import { Construct } from 'constructs'; | ||
|
||
/** | ||
* The rule set determines the two key elements of a match: your game's team structure and size, and how to group players together for the best possible match. | ||
* | ||
* For example, a rule set might describe a match like this: | ||
* - Create a match with two teams of five players each, one team is the defenders and the other team the invaders. | ||
* - A team can have novice and experienced players, but the average skill of the two teams must be within 10 points of each other. | ||
* - If no match is made after 30 seconds, gradually relax the skill requirements. | ||
*/ | ||
export abstract class RuleSetBody { | ||
|
||
/** | ||
* Matchmaking ruleSet body from a file | ||
* @returns `JsonFileRuleSetBody` with inline code. | ||
* @param path The path to the ruleSet body file | ||
*/ | ||
public static fromJsonFile(path: string): RuleSetBody { | ||
return new JsonFileRuleSetBody(path); | ||
} | ||
|
||
/** | ||
* Inline body for Matchmaking ruleSet | ||
* @returns `InlineRuleSetBody` with inline code. | ||
* @param body The actual ruleSet body (maximum 65535 characters) | ||
*/ | ||
public static fromInline(body: string): RuleSetBody { | ||
return new InlineRuleSetBody(body); | ||
} | ||
|
||
/** | ||
* Called when the matchmaking ruleSet is initialized to allow this object to bind | ||
* to the stack and add resources. | ||
* | ||
* @param scope The binding scope. | ||
*/ | ||
public abstract bind(scope: Construct): RuleSetBodyConfig; | ||
} | ||
|
||
/** | ||
* Result of binding `RuleSetBody` into a `MatchmakingRuleSet`. | ||
*/ | ||
export interface RuleSetBodyConfig { | ||
/** | ||
* Inline ruleSet body. | ||
*/ | ||
readonly ruleSetBody: string; | ||
} | ||
|
||
/** | ||
* Matchmaking ruleSet body from an inline string. | ||
*/ | ||
export class InlineRuleSetBody extends RuleSetBody { | ||
|
||
/** | ||
* @param path The ruleSet body. | ||
*/ | ||
constructor(private body: string) { | ||
super(); | ||
|
||
if (body.length === 0) { | ||
throw new Error('Matchmaking ruleSet body cannot be empty'); | ||
} | ||
|
||
if (body.length > 65535) { | ||
throw new Error(`Matchmaking ruleSet body cannot exceed 65535 characters, actual ${body.length}`); | ||
} | ||
} | ||
|
||
public bind(_scope: Construct): RuleSetBodyConfig { | ||
return { | ||
ruleSetBody: this.body, | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Matchmaking ruleSet body from aJSON File. | ||
*/ | ||
export class JsonFileRuleSetBody extends RuleSetBody { | ||
/** | ||
* Json file body content | ||
*/ | ||
private content: string; | ||
|
||
/** | ||
* @param path The path to the ruleSert body file. | ||
*/ | ||
constructor(private path: string) { | ||
super(); | ||
if (!fs.existsSync(path)) { | ||
throw new Error(`Matchmaking ruleSet path does not exist, please verify it, actual ${this.path}`); | ||
} | ||
|
||
if (!fs.lstatSync(path).isFile()) { | ||
throw new Error(`Matchmaking ruleSet path is not link to a single file, please verify your path, actual ${this.path}`); | ||
} | ||
const file = fs.readFileSync(path); | ||
|
||
if (file.toString().length > 65535) { | ||
throw new Error(`Matchmaking ruleSet body cannot exceed 65535 characters, actual ${file.toString().length}`); | ||
} | ||
|
||
this.content = file.toString(); | ||
} | ||
|
||
public bind(_scope: Construct): RuleSetBodyConfig { | ||
return { | ||
ruleSetBody: this.content, | ||
}; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also make sure that the string is a valid JSON? (Same for the inline case).