|
R-Type
Distributed multiplayer game engine in C++
|
Automatic matchmaking service. More...
#include <MatchmakingService.hpp>


Public Member Functions | |
| MatchmakingService (size_t minPlayers=2, size_t maxPlayers=4, std::shared_ptr< server::EventBus > eventBus=nullptr) | |
| Construct matchmaking service. | |
| ~MatchmakingService () override=default | |
| void | addPlayer (uint32_t playerId) override |
| Add a player to the matchmaking queue. | |
| void | removePlayer (uint32_t playerId) override |
| Remove a player from the matchmaking queue. | |
| void | tick () override |
| Process matchmaking queue and create matches Called periodically by the server. | |
| size_t | getQueueSize () const override |
| Get the number of players waiting in queue. | |
| void | setMatchCreatedCallback (MatchCreatedCallback callback) override |
| Set callback for when a match is created. | |
| std::pair< std::shared_ptr< Room >, bool > | findOrCreateMatch (uint32_t playerId, const std::vector< std::shared_ptr< Room > > &availableRooms, bool allowSpectator=true) override |
| Find an available room or add player to matchmaking queue. | |
| std::vector< PlayerQueueInfo > | getWaitingPlayers () const |
| Get list of waiting players. | |
| void | setMinPlayers (size_t min) |
| Set minimum players required to start a match. | |
| void | setMaxPlayers (size_t max) |
| Set maximum players per match. | |
| std::string | getStatistics () const |
| Get statistics about matchmaking. | |
Public Member Functions inherited from server::IMatchmakingService | |
| virtual | ~IMatchmakingService ()=default |
Private Member Functions | |
| bool | _tryCreateMatch () |
| Try to create a match from waiting players. | |
| std::string | _generateRoomId () |
| Generate unique room ID for a new match. | |
Private Attributes | |
| size_t | _minPlayers |
| size_t | _maxPlayers |
| std::shared_ptr< server::EventBus > | _eventBus |
| std::vector< PlayerQueueInfo > | _waitingPlayers |
| std::mutex | _mutex |
| MatchCreatedCallback | _matchCreatedCallback |
| uint32_t | _totalMatchesCreated {0} |
| uint32_t | _totalPlayersMatched {0} |
Automatic matchmaking service.
Manages matchmaking for players in two modes:
Features:
Definition at line 53 of file MatchmakingService.hpp.
|
explicit |
Construct matchmaking service.
| minPlayers | Minimum players to start a match (default: 2) |
| maxPlayers | Maximum players per match (default: 4) |
| eventBus | Shared event bus for server-wide events |
Definition at line 16 of file MatchmakingService.cpp.
References _maxPlayers, _minPlayers, and LOG_INFO.
|
overridedefault |
|
private |
Generate unique room ID for a new match.
Definition at line 138 of file MatchmakingService.cpp.
References _totalMatchesCreated.
Referenced by _tryCreateMatch().
|
private |
Try to create a match from waiting players.
Definition at line 75 of file MatchmakingService.cpp.
References _eventBus, _generateRoomId(), _matchCreatedCallback, _maxPlayers, _minPlayers, _totalMatchesCreated, _totalPlayersMatched, _waitingPlayers, LOG_ERROR, and LOG_INFO.
Referenced by tick().

|
overridevirtual |
Add a player to the matchmaking queue.
| playerId | Player ID to add |
Implements server::IMatchmakingService.
Definition at line 28 of file MatchmakingService.cpp.
References _mutex, _waitingPlayers, server::PlayerQueueInfo::joinTime, LOG_INFO, LOG_WARNING, and server::PlayerQueueInfo::playerId.
|
overridevirtual |
Find an available room or add player to matchmaking queue.
Implements intelligent matchmaking strategy:
| playerId | Player ID requesting matchmaking |
| availableRooms | List of currently available rooms to search |
| allowSpectator | Whether player can join as spectator if no waiting rooms |
Implements server::IMatchmakingService.
Definition at line 151 of file MatchmakingService.cpp.
References _mutex, _waitingPlayers, server::IN_PROGRESS, server::PlayerQueueInfo::joinTime, LOG_INFO, server::PlayerQueueInfo::playerId, and server::WAITING.
|
overridevirtual |
Get the number of players waiting in queue.
Implements server::IMatchmakingService.
Definition at line 142 of file MatchmakingService.cpp.
References _mutex, and _waitingPlayers.
| std::string server::MatchmakingService::getStatistics | ( | ) | const |
Get statistics about matchmaking.
Definition at line 218 of file MatchmakingService.cpp.
References _maxPlayers, _minPlayers, _mutex, _totalMatchesCreated, _totalPlayersMatched, and _waitingPlayers.
| std::vector< PlayerQueueInfo > server::MatchmakingService::getWaitingPlayers | ( | ) | const |
Get list of waiting players.
Definition at line 197 of file MatchmakingService.cpp.
References _mutex, and _waitingPlayers.
|
overridevirtual |
Remove a player from the matchmaking queue.
| playerId | Player ID to remove |
Implements server::IMatchmakingService.
Definition at line 49 of file MatchmakingService.cpp.
References _mutex, _waitingPlayers, LOG_INFO, and LOG_WARNING.
|
overridevirtual |
Set callback for when a match is created.
| callback | Function to call when match is ready |
Implements server::IMatchmakingService.
Definition at line 147 of file MatchmakingService.cpp.
References _matchCreatedCallback.
| void server::MatchmakingService::setMaxPlayers | ( | size_t | max | ) |
Set maximum players per match.
| max | Maximum player count (must be >= minPlayers) |
Definition at line 210 of file MatchmakingService.cpp.
References _maxPlayers, _minPlayers, _mutex, and LOG_INFO.
| void server::MatchmakingService::setMinPlayers | ( | size_t | min | ) |
Set minimum players required to start a match.
| min | Minimum player count (must be >= 1 and <= maxPlayers) |
Definition at line 202 of file MatchmakingService.cpp.
References _maxPlayers, _minPlayers, _mutex, and LOG_INFO.
|
overridevirtual |
Process matchmaking queue and create matches Called periodically by the server.
Implements server::IMatchmakingService.
Definition at line 64 of file MatchmakingService.cpp.
References _minPlayers, _mutex, _tryCreateMatch(), and _waitingPlayers.

|
private |
Definition at line 113 of file MatchmakingService.hpp.
Referenced by _tryCreateMatch().
|
private |
Definition at line 118 of file MatchmakingService.hpp.
Referenced by _tryCreateMatch(), and setMatchCreatedCallback().
|
private |
Definition at line 112 of file MatchmakingService.hpp.
Referenced by _tryCreateMatch(), getStatistics(), MatchmakingService(), setMaxPlayers(), and setMinPlayers().
|
private |
Definition at line 111 of file MatchmakingService.hpp.
Referenced by _tryCreateMatch(), getStatistics(), MatchmakingService(), setMaxPlayers(), setMinPlayers(), and tick().
|
mutableprivate |
Definition at line 116 of file MatchmakingService.hpp.
Referenced by addPlayer(), findOrCreateMatch(), getQueueSize(), getStatistics(), getWaitingPlayers(), removePlayer(), setMaxPlayers(), setMinPlayers(), and tick().
|
private |
Definition at line 121 of file MatchmakingService.hpp.
Referenced by _generateRoomId(), _tryCreateMatch(), and getStatistics().
|
private |
Definition at line 122 of file MatchmakingService.hpp.
Referenced by _tryCreateMatch(), and getStatistics().
|
private |
Definition at line 115 of file MatchmakingService.hpp.
Referenced by _tryCreateMatch(), addPlayer(), findOrCreateMatch(), getQueueSize(), getStatistics(), getWaitingPlayers(), removePlayer(), and tick().