Diarkis MatchMaker - How To Search Items

We explain how to handle Diarkis MatchMaker search with Diarkis Room.

How To Search In MatchMaker

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 conditions
conds := make(map[string]int)
conds["level"] = 14
conds["rank"] = 3

// How many search results you require
howmany := 10

matching.Search(matchingNames, conds, howmany, func(err error, results []interface{}) {

if err != nil {
// Handle error
return
}

// 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 found
func tryToJoin(next func(error)) {

if index == len(results) {
// We tried all rooms we found, but none worked
// try matching.Search again
  done(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 MatchMaker
for _, 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 rooms
  done(nil)
})

}

}

// This function will be called when everything is finished
func done(err error) {
if err != nil {
// Handle error
  return
}
logger.Debug("We are done!")
}
}