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

Draft - Adding matchmaker callback for advanced filtering #727

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ironohki
Copy link

@ironohki ironohki commented May 6, 2024

Summary

Enables the option to pass a filter callback when defining a room in Colyseus.

DRAFT - Awaiting code review and approval.

TODO - Unit tests.

Author Code-Review Questions Questions

The following questions are also noted as inline comments in the code.

  • I defined a new type in interfaces.ts. Types are not defined here, but I was not sure of a more appropriate location to define the time that is referenced throughout this process.
  • I added an optional property to the findOne method and the Query class. This seemed like a minimally intrusive approach, but I considered the new value could be added to the IRoomListingData interface, which is passed as a partial.
  • I used the name "filterMethod" as the user-facing property to define a callback used for filtering, while I defined the type name as "filterCallback" elsewhere in the code. Requesting feedback on Colyseus expectations for user-facing and internal variable naming.

Changes

/MatchMater.ts

  • Passes filterCallback to findOne method in awaitRoomAvailable

/matchmaker/RegisteredHandler.ts

  • Receives filterCallback from server define if provided, uses null if not provided.

/matchmaker/driver/Query.ts

  • Adds logic to use filterCallback if it is defined.
  • If filterCallback is null, use existing behavior.
  • If filterCallback is defined, first manually check locked, name and private.
  • If locked, name and private pass, provide instance options and room options to filterCallback.
  • If filterCallback returns strict boolean false, return false for this room filter check.
  • Proceed with room filter loop process.

/matchmaker/driver/index.ts

  • Adds filterMethod as a property to Query method when FindOne method is called.

/matchmaker/driver/interfaces.ts

  • Adds filterMethod as an optional property to the findOne interface.
  • Defines the type FilterMethod as function with clientOptions and roomOptions optional properties, that returns strict boolean, or null.

Intended implementation example

const filterMethod = (instanceOptions: any, roomOptions: any): boolean => {
  return 
    instanceOptions.alpha !== roomOptions.beta && 
    instanceOptions.gamma === roomOptions.gamma;
} 

initializeGameServer: (gameServer) => {
  gameServer.define('MyRoom', MyRoom).filterBy(['alpha','beta','gamma']).filterMethod(filterCallback);
}

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.

None yet

1 participant