We explain how to handle Diarkis MatchMaker search with Diarkis Room.
You need to choose which MatchMaker definition(s) to search in. You may search in multiple MatchMaker definitions by giving multiple MatchMaker definition names. The order of the search will be the same as the order of the MatchMaker definition array passed to the search function.
NOTE: This can be written on HTTP, TCP, and/or UDP/RUDP
/*** Must import the following:** github.com/Diarkis/diarkis/matching* github.com/Diarkis/diarkis/room* github.com/Diarkis/diarkis/util**/matchingNames := []string{ "levelAndRank" }// Search conditionsconds :=make(map[string]int)conds["level"] =14conds["rank"] =3// How many search results you requirehowmany :=10matching.Search(matchingNames, conds, howmany, func(err error, results []interface{}) {if err !=nil {// Handle errorreturn }// util.Waterfall executes a list of functions in order operations :=make([]func(error), len(results))for i :=range results { operations[i] = tryToJion } utill.Waterfall(operations, done) index :=0// We try the rooms we foundfunctryToJoin(next func(error)) {if index ==len(results) {// We tried all rooms we found, but none worked// try matching.Search againdone(nil)return } roomID := results[index]["roomID"].(string) room.Join(roomID, userData, ver, cmd, func(err error, members []string, owner string, createdTime int64, props map[string]interface{}) {
if err !=nil {// this room was no good, remove from MatchMakerfor _, matchingName :=range {// we assume roomID is used as a unique ID with matching.Addd matching.Remove(matchingName, roomID) }// We have failed to join the room - try the next room index++next(nil)return }// We have joined the room successfully - skip the rest of the roomsdone(nil) }) }}// This function will be called when everything is finishedfuncdone(err error) {if err !=nil {// Handle errorreturn } logger.Debug("We are done!") }}