在此專頁上
This topic will show you how to implement matchmaking in your apps. Its recommended that you integrate matchmaking in steps, starting with simple matchmaking and then adding data settings, queries, and skill components. You can find more details about these features and how add them in Skill, Data Settings and Queries for Matchmaking page.
Before you start your implementation, you should consider the type of game you’re making and the type of matchmaking it needs. Read about the different types of matchmaking in the Matchmaking Overview.
The most basic matchmaking scenario is a 2 player game where the match is not based on skill. In this scenario the system matches users and puts them in a room for that match. A room is created to host the match, and removed the system when the match is over. For example, a board game like checkers or tic-tac-toe would be a good candidate for simple matchmaking. To create an app with simple matchmaking:
ovr_Matchmaking_Enqueue2() from the client code. The user will be continually re-enqueued until they are successfully matched or cancel the process.ovrMessage_Notification_Matchmaking_MatchFound. Information about how the Platform SDK uses notifications can be found on the Requests and Messages page.OVR_MatchmakingEnqueueResult.h file for a list of methods you can call for information about the health of the queue that you may display to the user at this time.ovr_Room_Join2 with the roomID from the notification to place the user into the room.ovrNotification_Room_RoomUpdate for the number of users in the room. When the desired number of users is reached, your app will launch the game.ovr_Matchmaking_Cancel2() to remove themselves from the queue and exit the matchmaking process.Browse matchmaking means that users can browse and join existing rooms, and create rooms for other users to join. For this scenario you must enable the matchmaking pool to manage a queue of rooms.
The following steps show how to implement matchmaking in a game that allows users to browse and select the match that they want to join.
Navigate to the Matchmaking section of the Developer Dashboard, and select **Create Pool. Provide the following configuration:
When you’ve finished the pool configurations, select Save and Deploy to save the pool.
Your code will need to support multiple scenarios depending on the configuration settings you chose when creating your pool and how the user wants to use the service.
If the user wants to join a match:
ovr_Matchmaking_Browse2 to get a list of the available rooms.ovrMessage_Matchmaking_Browse2 response and display the list of rooms to the user. You may wish to periodically refresh the list by periodically calling the browse method.ovr_Room_Join2 when the user chooses room.If the user wants to create a room and host a match:
ovr_Matchmaking_CreateAndEnqueueRoom2 or call ovr_Matchmaking_CreateRoom2, handle the response, and then call ovr_Matchmaking_EnqueueRoom2.ovrMessage_Matchmaking_CreateAndEnqueueRoom2 or ovrMessage_Matchmaking_EnqueueRoom2 response.OVR_MatchmakingEnqueueResult.h file for a list of methods you can call for information about the health of the queue to display to the userYour game will be listening for ovrNotification_Room_RoomUpdate for the number of users in the room. When the desired number of users is reached, your app will launch the game.
Note: At any time in the matchmaking process, you can call
ovr_Matchmaking_Cancel2()to remove a user from the queue and exit the matchmaking process.
Advanced matchmaking applies to multi-player games that have multiple modes of play and involve 2-8 players. In this scenario, players may also join or leave games in progress. Optionally, you can enable users to browse for rooms to join. To support this type of game, you must enable the matchmaking pool to manage a queue of rooms. You should also allow both users and the matchmaking service to create rooms with the option to enable users to browse for matches. For example, a first-person shooter might require a queue of rooms with browse enabled because the game has multiple maps or users may wish to browse or be matched to sessions already in progress.
Go to the Matchmaking section of the Developer Center, and create a pool with the following configurations:
CaptureTheFlag_TwoVsTwo or any value you’d like to use in your game.The example configuration allows both users and the system to create rooms, so these instruction describe how to handle both scenarios. You may need to support different/multiple scenarios depending on the configuration settings you chose when creating your pool and how the user wants to use the matchmaking service.
If a user wants to join a match:
ovr_Matchmaking_Enqueue2. The user will be continually re-enqueued until they are successfully matched or cancel the process. 2. Handle the notification that the user was enqueued, ovrMessage_Matchmaking_Enqueue2. Information about how the Platform SDK uses notifications can be found on the Requests and Messages page. 3. (Optional) Review the methods in the OVR_MatchmakingEnqueueResult.h file for a list of methods you can call for information about the health of the queue to display to the user.ovrMessage_Notification_Matchmaking_MatchFound.ovr_Room_Join2 to place the user into the room identified in the MatchFound notification.If the user wants to create a room and host a match:
ovr_Matchmaking_CreateAndEnqueueRoom2 or ovr_Matchmaking_CreateRoom2, handle the response, and then call ovr_Matchmaking_EnqueueRoom2. The Room will be continually re-enqueued until canceled or a match is found.ovrMessage_Matchmaking_CreateAndEnqueueRoom2 or ovrMessage_Matchmaking_EnqueueRoom2 response.Your game will be listening for ovrNotification_Room_RoomUpdate for the number of users in the room. When the desired number of users is reached, your app will launch the game.
Note: At any time in the matchmaking process, you can call
ovr_Matchmaking_Cancel2()to remove a user from the queue and exit the matchmaking process.
Each user-generated matchmaking room is associated with the user who created the room. That user who created the room becomes the room’s owner. This role may have the permission to update the settings of the room, if you have configured the pool to allow this. During the course of the multiplayer session, it may be necessary to transfer ownership of the room. The requests to update room data and transfer ownership can be found on the Rooms page.
If the room owner leaves without transferring ownership, your pool may be configured to automatically transfer ownership to the user who has been in the room the longest. Enable this setting by choosing Yes for Enable host migration when the room owner leaves the room? when creating your pool.
Next, you can add a skill component or data settings and queries for more advance matching scenarios. For more information, see Adding Skill and Using Queries.