Refactor multiplayer room initialisation and context #319
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.
Overview
The primary purpose of this change is to enable the following change: smoogipoo@e24be0e - making the matchmaking background service able to initialise rooms and perform post-initialisation adjustments.
As part of this change:
ServerMultiplayerRoom.InitialiseAsync()
.ServerMultiplayerRoom
constructor made private.MultiplayerHubContext
moved to global singleton dependency.This will also allow testing that users are eligible for the room, such as in smoogipoo@522ed4c
Important changes
This affects normal multiplayer room initialisation. In particular, the first user that joins the room will become the host of the room, and users are allowed to join in any order. Given that room join + creation happens sequentially server-side (as opposed to through a client-server round-trip), I don't expect this to result in too many race conditions (although still possible).
I think this is something that can be further improved by splitting out the
JoinRoom
logic. If agreed upon/requested I can try to do that in this PR - I think the scope of changes is https://gist.github.com/smoogipoo/de57193d7fa7077ea2cf163ac22ee988Alternatives
I think this is the nicest of three possible directions I had in mind, the others include:
IMemoryCache
and querying them on room init.