Skip to content
This repository was archived by the owner on Jul 10, 2022. It is now read-only.

Matchmaking

Ian Castaño edited this page Nov 7, 2020 · 2 revisions

The matchmaking flow all starts from a user request known as MatchmakingRequest, which will obtain essential data such as GameMode, Map, creation date and aditional criteria if necessary.

Property Description
Issued Date A general-purpose field to validate issuing
GameMode Database ID of the registered GameMode
SubGameMode Database ID of the registered SubGameMode
Map (Optional) Database ID of a desired GameMap

Who is the game requester?

The matchmaking request can be requested by one, two or a thousand users, this depends on the general production restrictions, however, it always must have a leader, also known as responsible and a list of users who are involved in the request without be directly responsible.

MatchAssignable assignable = new MatchAssignable() {
    @Override
    public String getResponsible() {
        return player.getDatabaseIdentifier();
    }

    @Override
    public Set<String> getInvolved() {
        return new HashSet<>();
    }
};

Creating a request

Creating a request manually will not do you any good, unless you want to print and hang it on your door. In order to avoid you to constantly print requests and preserve the ecosystem we have designed the MatchmakingRegistryHandler, with this you will only have to pass the parameters you need and a registry will be created in Redis with the request information, in addition to sending an event called MatchmakingRequestEvent, which will determine if there are games that comply with the matchmaking or will request a new server from the cloud.

public class AwesomeNPCSelector {

    private @Inject MatchmakingRegistryHandler matchmakingRegistryHandler;

    public void assignMatch() {

        // ...
        matchmakingRegistryHandler.generateRequest(assignable, "GAMEMODE", "SUBGAMEMODE");
    }

}

For now, this is all you have to do in order to assign a match, but below this we will explain a little more about game assignation.

How to determine which match is the best to be assigned?

Simple, in case there are several games that meet the criteria of the request, one will be selected through the IdealMatchSelector, the only thing you have to pass is games that meet the requirements of the request, which you can obtain with the AvailableMatchProvider.

Assigning a match

To assign a matchmaking to a request, you just have to use the MatchAssigner, which will match the request with a game and send a signal to the server hosting the game to teleport requesters to it.

Optional<Match> match = idealMatchSelector.sortAvailableMatches(
    availableMatchProvider.getCriteriaAvailableMatches(event.getMatchmakingRequest())
);

if (match.isPresent()) {
    matchAssigner.assign(event.getMatchmakingRequest().getRequesters(), match.get());
} else {
    // Here you say to someone to open a server and bring you some cookies
}

Clone this wiki locally