Skip to content
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

Feature/matchmaking #59

Open
wants to merge 3 commits into
base: feature/matchmaking
Choose a base branch
from

Conversation

eXPeRi91
Copy link

@eXPeRi91 eXPeRi91 commented Aug 25, 2024

Here is all the changes made:

  • Updated matchmaking session management logic for accurate role assignment and merging.
  • Refined types to match API requirements.
  • Added detailed matchmaking and character loadout types.
  • Corrected lobby management logic for better consistency with matchmaking system.
  • Always check and handle errors in callbacks to prevent unexpected crashes.
  • Async Wrapper for Nedb (MongoDB will come other time)
  • Enum called LobbyAction to replace string literals for action types.
  • Improved logging messages for better debugging and monitoring.

…gnment and merging.

- Refined types in custom-lobby-types.ts to match API requirements.
- Added detailed matchmaking and character loadout types in vhs-the-game-types.ts.
- Corrected lobby management logic in lobby-manager.ts for better consistency with matchmaking system."
…gnment and merging.

- Refined types in custom-lobby-types.ts to match API requirements.
- Added detailed matchmaking and character loadout types in vhs-the-game-types.ts.
- Corrected lobby management logic in lobby-manager.ts for better consistency with matchmaking system."
…rashes.

- Async Wrapper for Nedb (MongDB will come other time)
- Forgotten Timestamp declaration.
- Enum called LobbyAction to replace string literals for action types, reduces the risk of errors.
- Improved logging messages for better debugging and monitoring.
Copy link
Owner

@LuisMayo LuisMayo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!

Thanks a lot for the PR, those are a lot of good changes this project desperately needed. Also advancing a lot in the matchmaking feature

I've left some comments I'll like to address before merging.

Again, thanks a lot for your contributions, and sorry for taking so long to review.

Thanks.

} catch(e) {
msg = 'Error while removing user ' + e;
// Method for Nedb
collection.remove({ [DBConstants.userIdField]: req.body.userId }, { multi: false }, (err, numRemoved) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason for changing this from the async/await syntax into the callback one?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The primary reason for switching to callback syntax is due to NeDB's native callback-based design, avoiding the extra overhead of wrapping those methods with promises unless necessary. With callbacks, the execution is immediate, and the function typically returns as soon as the operation is complete. (we are getting closer to VHS standarts)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Giving this is a REST API (i.e: most of the overhead is the HTTP+TCP handshake) I doubt a microtask queuing (that's all the overhead a promise gives) is really relevant but it is an improvement, so thanks for doing it and for your patience explaining it

src/classes/admin-handler.ts Show resolved Hide resolved
src/classes/admin-handler.ts Show resolved Hide resolved
interface GameSession {
sessionId: string;
players: string[]; // Array of player IDs in the session
state: string; // e.g., 'waiting', 'active', 'completed'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required for merging, but this could be an ENUM

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're correct, I will make it as enum's

// Initialize the matchmaking queue if necessary
const queue = await collection.findOneAsync({});
if (!queue) {
await collection.insertAsync({ players: [] }); // Empty initial queue
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the design here, do we only have a queue?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial testing for me, we can do more here like:

  queueId: string; // Unique ID for the queue (game mode, region, etc.)
  gameMode: string; // The game mode for the queue, e.g., 'ranked', 'casual'
  region: string; // Region, e.g., 'NA', 'EU'
  combineRegions: regions; // Combine NA and EU for more players
  players: string[]; // Players waiting in the queue

This part can be deleted, because I was testing...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, knowing it's a test, it's good to merge. About your suggestion, we're not gonna use regions yet, also, a single region may have several queues (for instance, several monsters queue). I was hoping to have Matchmaking Sessions in the Array instead of players themselves

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about this, I just don't think I want the matchmaking data on the database. It doesn't make sense because if a server restarts we're losing the websocket connections anyway, so all matchmaking info is irrelevant.

This is not blocking for merging the pull request because it can be deleted anyway

@@ -184,7 +240,6 @@ export class Handler {
return response.send({
log: { logSuccessful: true },
data: {
// TODO return the truth instead of this
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to remove this comment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean I can't remember removing this ..

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so if you agree I'll add it back

src/classes/lobby-manager.ts Show resolved Hide resolved
@LuisMayo
Copy link
Owner

This will be good to merge once I redo the removed comment.

Thanks again!

@LuisMayo
Copy link
Owner

LuisMayo commented Nov 2, 2024

Ok this branch doesn't compile so it won't be merge until compile errors are fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants