MatchMaker の Ticket ロジックの管理と制御

MatchMaker Ticket は、マッチメイキングの処理をサーバが完全に制御することを可能にします。

サーバーは、チケット (Ticket) によって実行されるすべてのマッチメイキングのロジックを管理・制御することができます。

サーバーがマッチメイキングのロジックを管理・制御することの利点は、マッチメイキングのルールやロジックを変更するときに、クライアントを変更する必要がないことです。

クライアントがチケットを発行したときに、コールバックでチケットを作成するように設定する

このコールバックは、クライアントがマッチメイキング・チケットを発行したときに、すべてのマッチメイキング・チケットを作成する役割を担います。

このコールバックは、クライアントがチケットを発行するたびに呼び出されます。チケットを発行したユーザー(クライアント)に応じて、チケットの値を変更することができます。

ここでは、チケットの内容を制御することができます。

// import github.com/Diarkis/diarkis/matching github.com/Diarkis/diarkis/user


// userData is the data representation of the client issued the ticket
matching.SetOnIssueTicket(func(userData *user.User) *matching.TicketParams {
 return &matching.TicketParams{
   
// Control which matchmaking profiles the issued ticket should use
ProfileIDs:     []string{"RankMatch", "RankMatch2"},

// Control the maximum number of clients to be matched
MaxMembers:     2,

// Controls how long the each search should wait before performing next search
SearchInterval: 100, // 100 milliseconds

// Controls how long should the issued ticket be valid in seconds
TicketDuration: 60,  // 1 minute

// Controls how many matched candidates should a search should retrieve
HowMany:        20,

// Controls if the issued ticket should use MatchMaker Tag
Tag: "",

   // Controls the conditions of the matchmaking wait (conditions to be found by others)
  AddProperties: map[string]int{"rank": userData.Get("UserRank")},

  // Controls the conditions for matchmaking search
  SearchProperties: map[string][]int{ "rank": []int{ 1, 2, 3 } },
}
}

マッチメイキングの完了を判断するカスタムロジックの追加

チケットが MaxMembers の値と同じ数のマッチしたクライアントを見つけると、MatchMaker は自動的にマッチメイキングが完了したと判断し、マッチしたすべてのクライアントに通知を送信します。

このコールバックを使うことで、 MaxMembers に達していなくても、いつどのようにマッチングが "完了 "したと判断するかを決めるために、独自のカスタムロジックを追加することができます。

matching.SetOnTicketMatch(func(userData *user.User, roomID string, memberIDs []string) bool {
// Add custom logic to decide matchmaking completion here
// userData represents the client that issued the ticket
// roomID represents the matchmaking room that all matched clients belong to
// memberIDs is the list of all matched clients' user IDs
return false
})

通知メッセージの作成にコールバックを設定する

マッチング完了通知にはメッセージデータが含まれますが、以下に説明するコールバックを使用することで、クライアントへの通知として送信する内容を管理・制御することができます。

matching.SetOnTicketComplete(func(roomID string, userData *user.User) []byte {
 // roomID represents the matchmaking room that all matched clients belong to
 // userData represents the client that issued the ticket
return []byte("Send some meaningful information here...")
}