func Add(matchingID string, uniqueID string, tag string, props map[string]int, value map[string]interface{}, ttl int64, limit int)
Add Adds a searchable matching candidate data
matchingID - Pre-defined matching ID that is associated with the matching definition by Define() uniqueID - A unique ID for the match making candidate data to prevent duplicates props - Match making conditions value - Candidate data to be returned when search finds this candidate ttl - Defines how long the candidate should be available for search: This is in seconds maximum TTL is 60 seconds limit - Defines how many mesh node it should distribute at a time
In order to have long lasting (TTL longer than 60 seconds) searable items, the application must "add" searchable items repeatedly with TTL=60.
matchingID string - Matching profile ID to add the searchable data to. unqiueID string - Unique ID of the searchable ID. tag string - Tag is used to isolate and group add and search of matchmaking. If an empty string is given, it will be ignored. props map[string]int - Searchable condition properties. value map[string]interface{} - Searchable data to be returned along with the search resilts. ttl int64 - TTL of the searchable item to be added in seconds. Maximum 60 seconds. limit int - Number of search node to propagate the searchable item data at a time.
func ClearDefinition(matchingID string)
Clear Definition clears already defined match making definition
matchingID string - Matching profile ID to clear the definition.
func Define(matchingID string, props map[string]int)
Define Defines a match making search schema: This must be defined on HTTP server b/c all match making data is stored on HTTP servers. You may define as many matching definition as you require as long as each matchingID is unique.
matchingID string - Unique matching profile ID. props map[string]int - Matching profile condition properties.
func DefineByJSON(jsonBytes []byte)
DefineByJSON defines multiple match making definitions from JSON string.
{ "<matching ID>": { "<property name>": <property range value> "<property name>": <property range value> "<property name>": <property range value> } } jsonBytes []byte - Matching profile byte array data to be used to define the profile.
func ExposeCommands()
func Remove(matchingID string, uniqueIDList []string, limit int)
Remove removes a list of searchable matching candidate items by their unique IDs NOTE: this function is very expensive as it will send a message to all related mesh nodes
matchingID - Target matching profile ID to remove items from uniqueIDList - A list of unique IDs of the searchable items to remove limit - Mesh network relay limit
func Search(searchIDList []string, tag string, props map[string]int, limit int, callback func(error, []interface{}))
Search Searchs for matched data based on the given props' values
searchIDList - a list of matchingID to search by. The order of the list is the order of search attempts tag - a tag is used to isolate and group search meaning the search will not include tags that do not match. props - a property map to act as match making conditions limit - a hard limit to the number of results callback - a callback with the search results or an error
func SetCustomJoinCondition(callback func(string, *user.User) bool)
SetCustomJoinCondition assigns a on join evaluation callback to be called to evaluate if the user should join or not
func Setup(confpath string)
Setup sets up MatchMaker on the server.
confpath string - Absolute path of the configuration file to be loaded.
func Test(method string, data map[string]interface{}) ([]byte, error)
Test this is used ONLY in tests
Ticket matchmaking ticket that manages a life cycle of issued ticket
OnComplete
Raised when matchmaking completes with remote users matched or with an error when no match was found
OnMatch
Raised when a remote user matches. By returning true, you may compelte the ticket and raise OnComplete
type Ticket struct { OnComplete func(err error, userData *user.User, roomID string, memberIDs []string) OnMatch func(userData *user.User, roomID string, memberIDs []string) bool // contains filtered or unexported fields }
func IssueTicket(params *TicketParams, userData *user.User) *Ticket
IssueTicket creates a new matchmaking ticket.
A matchmaking ticket will perform searches and add with the given properties and profile IDs and is event driven.
Usage Example:
// issue a new matchmaking ticket with the ticket parameters ticket := matching.IssueTicket(ticketParams, userData) // set up callbacks ticket.OnComplete = func(err error, userData *userData, roomID string, memberIDs []string) { if err != nil { // ticket has timed out or there was an error return } // matchmaking has completed with success! } ticket.OnMatch = func(userData *user.User, roomID string, memberIDs []string) bool { // if we return true, the matchmaking will be completed and OnComplete callback will be invoked with success } // now we start the ticket ticket.Start(userData)
func (t *Ticket) Start() bool
Start starts the life cycle of a ticket.
TicketParams parameter struct for IssueTicket
ProfileIDs
A list of profiles to add to and search against
Properties matchmaking properties (conditions) SearchTimeout Search timeout in seconds. If the ticket does not find any match when SearchTimeout expires, the ticket will move to "Add" SearchInterval
The interval for search in milliseconds
AddTimeout Waiting time for "Add" in seconds. If the ticket does not find any match, the ticket will raise OnComplete with an error
type TicketParams struct { ProfileIDs []string Tag string Properties map[string]int MaxMembers uint8 SearchTimeout uint8 SearchInterval uint16 AddTimeout uint8 HowMany uint8 }