Reputation: 1
I want to add matchmaking to my game but I don't really know how to implement it. I have a few concepts based on examples from the internet but I would like to ask if my conjectures are right.
Game Description Game is really easy there are 3 roles for players support, guardian and DPS each player before game choose roles(Multichoose), region, a language so matchmaking in the first place must match players in a team.
(1) So my first idea is to create a lobby and save it in database now if a user is looking for a match he makes a request to database if there is a lobby for him he joint to lobby and emit socket if there is no lobby system is creating lobby and user is waiting for another people.
This solution makes a lot of trouble like how like: (How to check if there is an empty slot for support or guardian, What to do if someone quit and more)
(2) The second idea is to create a queue and keep people in a variable or use redis and make a function matching people in a team. Here is my question node js is able to keep let's say 10k players in variable and making operation and still handle game's webserver or I should choose the first solution.
Maybe you have another idea how to solve this problem
Thanks in advance
Upvotes: 0
Views: 1755
Reputation: 21
I know this tread is getting old. Nevertheless, maybe my thoughts may help someone.
What I would do in your case is to not use database at all for the matchmaking system. Calls to databases are expensive in terms of time, resources and monetary. In the other hand, holding it only server side would be much more faster, scalable and cheap. More than that, you really don't need to use a database for this feature (it's not its purpose in my opinion because if the server is down then every player are disconnected anyway and don't expect to still being looking for a match).
Just use an object stored in your game manager like so :
this.match = {
123: {
support: idPlayer1,
dps: idPlayer2,
guardian: undefined,
region: 'EU',
language: 'fr'
}
}
123 is an id for the matchmaking and idPlayerX is the id of a player. As soon as someone is looking for a match, you would just need to loop through the object and to extract each match that may fit the player then to filter the match that fit the best and to register the user to that match (just his id should be far enough). Then, you could also save the id of the match in the player object (server side).
I use "undefined" value for free role because it is very easy to test if the role is free or not like so.
If someone left the queue, just retrieve the match with the id, set the role to undefined and free the match variable in the player object.
If a match is finally full (or everyone left), just delete the entry :
delete this.match[id]
This way you should keep a very light variable and save a god damn lot of calls to your database. This is a very basic matchmaking system but very easy to complexify if needed.
Upvotes: 2