Diarkis MatchMaker を使って検索可能なアイテムを追加する

Diarkis MatchMaker と Room を使って検索可能なアイテムを登録する実装例を紹介します。

マッチメイキングにアイテムを追加する方法

マッチメイキングで検索・マッチングできるようにするためには、"add" が必要です。追加するアイテムは TTL を短く設定し、不要になるまで "add" し続けることをお勧めします。add は比較的低負荷な処理ですが、"remove" の負荷は比較的高いためです。

: 最大 TTL は60秒です。60秒以上アイテムを利用する場合、必要がなくなるまで繰り返しアイテムを add する必要があります。

NOTE: この処理は HTTP, TCP, UDP/RUDP のどこにでも実装することが可能です。

下の例は、マッチメイキングに Room を追加する方法です

// Match making item property to be searched by
props := make(map[string]int)
props["level"] = 30
props["rank"] = 7

// Unique name of the match-making definition to add the room to
matchingName := "levelAndRank"

// roomMetadata will be retrieved as the search results.
data := make(map[string]interface{})
data["roomID"] = roomID
data["roomType"] = 2
data["roomName"] = "Room of level 30 and rank 7"

// TTL of the room in match-making. TTL is in seconds
ttl := int64(30)

// relayLimit is the number of server nodes to send the data to at a time:
// Greater the value, the faster and more CPU intense it is
relayLimit := 2

matching.Add(matchingName, roomID, props, roomMetadata, ttl, relayLimit)