void OnMakeMatch(INMatchmakeTicket result)
    {
        Debug.Log("Added to Matchmaker pool");

        // store ticket to leave match maker pool
        cancelTicket = result.Ticket;
    }
Exemplo n.º 2
0
    private void SetupMatchmakeListener()
    {
        // Attach an event handler for when the user is matched with other users.
        // This only needs to be done once.
        // For more information have a look at: https://heroiclabs.com/docs/development/matchmaker/
        _client.OnMatchmakeMatched = (INMatchmakeMatched matched) => {
            // Set the local cache to null now that we've been offered a match.
            _matchmakeTicket = null;
            Debug.Log("Matchmaker found an opponent.");

            // The match token is used to join a multiplayer match.
            // Lets accept the match and join it.
            var message = NMatchJoinMessage.Default(matched.Token);
            _client.Send(message, (INResultSet <INMatch> matches) => {
                Debug.Log("Successfully joined matches.");

                _match = matches.Results[0];
                foreach (var presence in _match.Presence)
                {
                    Debug.LogFormat("Presence initial state: User handle '{0}' is in the match.", presence.Handle);
                }

                // Lets enable the button now that we've joined a match.
                _matchSendDataButtonEnable = true;
            }, (INError error) => {
                Debug.LogErrorFormat("Send error: code '{1}' with '{0}'.", error.Message, error.Code);
            });
        };
    }
Exemplo n.º 3
0
 private NMatchmakeRemoveMessage(INMatchmakeTicket ticket)
 {
     payload = new Envelope {
         MatchmakeRemove = new TMatchmakeRemove()
     };
     payload.MatchmakeRemove.Ticket = ticket.Ticket;
 }
Exemplo n.º 4
0
    // This is invoked by clicking on the scene UI button.
    public void DoMatchmake()
    {
        // Add self to the matchmaker pool.
        var message = NMatchmakeAddMessage.Default(MatchPlayerSize);

        _client.Send(message, (INMatchmakeTicket ticket) => {
            // Store the matchmakeTicket so it can be used to cancel later.
            Debug.Log("Added to the pool by Matchmaker.");
            _matchmakeTicket = ticket;
        }, (INError error) => {
            Debug.LogErrorFormat("Send error: code '{1}' with '{0}'.", error.Message, error.Code);
        });
    }
    public void StartMatchMaking(Action onMatchMakeSucceeded, Action onMatchMakeFailed)
    {
        INMatchmakeTicket      matchmake         = null;
        IList <INUserPresence> matchParticipants = null;

        // Look for a match for two participants. Yourself and one more.
        var message = NMatchmakeAddMessage.Default(numMatchParticipants);

        _client.Send(message, (INMatchmakeTicket result) => {
            Debug.Log("Added user to matchmaker pool.");

            var cancelTicket = result.Ticket;
            Debug.LogFormat("The cancellation code {0}", cancelTicket);
        }, (INError err) => {
            Debug.LogErrorFormat("Error: code '{0}' with '{1}'.", err.Code, err.Message);
        });

        _client.OnMatchmakeMatched = (INMatchmakeMatched matched) => {
            // a match token is used to join the match.
            Debug.LogFormat("Match token: '{0}'", matched.Token);

            matchParticipants = matched.Presence;
            // a list of users who've been matched as opponents.
            foreach (var presence in matched.Presence)
            {
                Debug.LogFormat("User id: '{0}'.", presence.UserId);
                Debug.LogFormat("User handle: '{0}'.", presence.Handle);
            }

            // list of all match properties
            foreach (var userProperty in matched.UserProperties)
            {
                foreach (KeyValuePair <string, object> entry in userProperty.Properties)
                {
                    Debug.LogFormat("Property '{0}' for user '{1}' has value '{2}'.", entry.Key, userProperty.Id, entry.Value);
                }

                foreach (KeyValuePair <string, INMatchmakeFilter> entry in userProperty.Filters)
                {
                    Debug.LogFormat("Filter '{0}' for user '{1}' has value '{2}'.", entry.Key, userProperty.Id, entry.Value.ToString());
                }
            }

            var jm = NMatchJoinMessage.Default(matched.Token);
            _client.Send(jm, (INResultSet <INMatch> matches) => {
                Debug.Log("Successfully joined match.");
                _match             = matches.Results[0];
                _matchParticipants = matchParticipants;
//				foreach(Action a in OnMatchJoinedActions) {
//					a();
//				}

                foreach (INMatch match in matches.Results)
                {
                    Debug.LogFormat("Match id: {0} Presence", match.Id);

                    foreach (INUserPresence presence in match.Presence)
                    {
                        Debug.LogFormat("User handle: {0} id {1}.", presence.Handle, presence.UserId);
                    }
                }

                Enqueue(() => {
                    onMatchJoined(_match);
                });
            }, (INError error) => {
                Debug.LogErrorFormat("Error: code '{0}' with '{1}'.", error.Code, error.Message);
            });

            // TODO callback to UI
            onMatchMakeSucceeded();
        };
    }
Exemplo n.º 6
0
 public static NMatchmakeRemoveMessage Default(INMatchmakeTicket ticket)
 {
     return(new NMatchmakeRemoveMessage(ticket));
 }