Diarkis MatchMaker - How to use IssueTicket

We explain how to handle Diarkis MatchMaker IssueTicket.

What Is Issue Ticket?

The IssueTicket feature allows the client side to only issue IssueTicket commands, while the server side searches for a certain amount of time, and after a certain amount of time, becomes the host and waits for matchmaking itself.
Since all the matchmaking definitions are written on the server side, it is possible to change the matchmaking specifications without updating the client.
Also, the client side only needs to execute a single IssueTicket command and wait for the results of the exclusive-handling matching to be returned, which makes the implementation very simple.


What Is Ticket?

A ticket is a search job that can be issued only once by each user at the same time. A single ticket can be used to search for matchmaking with multiple conditions, not just one.
When the ticket times out or the matchmaking is successful, the user can issue the ticket again.

 

Callbacks

The following callback functions are currently available for IssueTicket

- OnTicketMatch
- OnTicketComplete
- OnIssueTicket

- OnTicketMatch
This will be called when a match has been made with someone.
This is used when you want to consider the matching process complete.
For example, if you have 8 out of 10 players and the first user has been waiting for more than 3 minutes, you can start the game even though you don't have all the players.
If you want to assume that the game is completed in the middle, return true.

- OnTickeComplete
This will be called when the matching is complete.
When the matching is complete, it allocates the Agones server, modifies the properties of each user, etc.
Also called in OnTicketMatch when matching is considered complete (true is returned).

- OnIssueTicket
This will be called when a ticket is issued.
If it returns a TicketParams struct, matchmaking will be started using that definition.

CodeSample

matching.SetOnIssueTicket(func(userData *user.User) *matching.TicketParams {
        return &matching.TicketParams{
          ProfileIDs:    []string{"rank", "RankMatch"},  // profileID
          Tag:            userData.Get(SOME_KEY).(string),
            Properties: map[string]int{"rank": rank},
          MaxMembers:     2,
            SearchInterval: 100, // 100ms
          TicketDuration: 60, // 60s
          HowMany:        20,
        }
    })

    // This callback will called when matchmaking is done with someone.
    // If true is returned in this function, the matchmaking is considered to be completed, even if the capacity is not met.
    // At that time, the callback set in SetOnTicketComplete below will ALSO be called.
    matching.SetOnTicketMatch(func(userData *user.User, roomID string, memberIDs []string) bool {
        logger.Debug("matching.OnTicketMatch")
        return true
    })

    // This callback will called when matchmaking finish COMPLETELY.
    // Not called in case of incomplete matchmaking (e.g. members is less than capacity)
    matching.SetOnTicketComplete(func(roomID string, userData *user.User) []byte {
        logger.Debug("matching.OnComplete")
      address, port := allocateGameServer()
      return []byte(address + ":" + strconv.Itoa(port))
    })