-
Notifications
You must be signed in to change notification settings - Fork 1
fix: latent issues in lobby management + added tests #71
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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,61 @@ | ||
| namespace OpenPolytopia.Common; | ||
|
|
||
| /// <summary> | ||
| /// Rules a lobby must respect to be valid | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Lives in the common assembly so the client can check a lobby before asking the server for it | ||
| /// </remarks> | ||
| public static class LobbyRules { | ||
| /// <summary> | ||
| /// Smallest world a game can be played on | ||
| /// </summary> | ||
| public const uint MIN_WORLD_SIZE = 11; | ||
|
|
||
| /// <summary> | ||
| /// Biggest world a game can be played on | ||
| /// </summary> | ||
| public const uint MAX_WORLD_SIZE = 30; | ||
|
|
||
| /// <summary> | ||
| /// Minimum players needed to start a game; solo games aren't allowed | ||
| /// </summary> | ||
| public const uint MIN_PLAYERS = 2; | ||
|
|
||
| /// <summary> | ||
| /// World size from which a lobby can hold <see cref="MAX_PLAYERS_BIG_WORLD"/> players | ||
| /// </summary> | ||
| private const uint BIG_WORLD_SIZE = 14; | ||
|
|
||
| /// <summary> | ||
| /// Max players a world smaller than <see cref="BIG_WORLD_SIZE"/> can hold | ||
| /// </summary> | ||
| private const uint MAX_PLAYERS_SMALL_WORLD = 9; | ||
|
|
||
| /// <summary> | ||
| /// Max players a world of at least <see cref="BIG_WORLD_SIZE"/> can hold | ||
| /// </summary> | ||
| private const uint MAX_PLAYERS_BIG_WORLD = 16; | ||
|
|
||
| /// <summary> | ||
| /// Max players a lobby on a given world can hold | ||
| /// </summary> | ||
| /// <param name="worldSize">the size of the world</param> | ||
| /// <returns>the max players allowed on that world</returns> | ||
| public static uint MaxPlayersFor(uint worldSize) => | ||
| worldSize < BIG_WORLD_SIZE ? MAX_PLAYERS_SMALL_WORLD : MAX_PLAYERS_BIG_WORLD; | ||
|
|
||
| /// <summary> | ||
| /// Checks if a world can host a game | ||
| /// </summary> | ||
| /// <param name="worldSize">the size of the world</param> | ||
| public static bool IsValidWorldSize(uint worldSize) => worldSize is >= MIN_WORLD_SIZE and <= MAX_WORLD_SIZE; | ||
|
|
||
| /// <summary> | ||
| /// Checks if a lobby of a given size can be created on a given world | ||
| /// </summary> | ||
| /// <param name="maxPlayers">max players that can join the lobby</param> | ||
| /// <param name="worldSize">the size of the world</param> | ||
| public static bool IsValidLobby(uint maxPlayers, uint worldSize) => | ||
| IsValidWorldSize(worldSize) && maxPlayers >= MIN_PLAYERS && maxPlayers <= MaxPlayersFor(worldSize); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.