Exemplo n.º 1
0
    void FixedUpdate()
    {
        if (!m_useMatchmaking)
        {
            return;
        }

        if (m_matchmaker == null)
        {
            m_matchmaker = new Matchmaker(MatchmakingServer);
            MatchmakingPlayerProperties playerProps = new MatchmakingPlayerProperties()
            {
                hats = 5
            };
            MatchmakingGroupProperties groupProps = new MatchmakingGroupProperties()
            {
                mode = 0
            };
            MatchmakingRequest request = Matchmaker.CreateMatchmakingRequest(Guid.NewGuid().ToString(), playerProps, groupProps);
            m_matchmaker.RequestMatch(request, OnMatchmakingSuccess, OnMatchmakingError);
        }
        else
        {
            m_matchmaker.Update();
        }
    }
Exemplo n.º 2
0
 public void onMatchMakingButtonClick()
 {
     BlockMatchInput();
     BlockJoinHostGameButtons();
     if (matching)
     {
         findingMatchText.color = ColorPalette.invisible;
         matchmakingButton.gameObject.GetComponentInChildren <TMPro.TextMeshProUGUI>().text = "Find Match";
         Debug.Log("Making/sending matchmaking request");
         MatchmakingRequest request = new MatchmakingRequest();
         request.SetAction("cancel");
         request.SetMatchShortCode("DefaultMatch");
         request.SetSkill(0);
         request.Send(OnMatchmakingSuccess, OnMatchmakingError);
         matching = false;
         UnblockMatchInput();
         UnblockJoinHostGameButtons();
     }
     else
     {
         findingMatchText.color = ColorPalette.white;
         matchmakingButton.gameObject.GetComponentInChildren <TMPro.TextMeshProUGUI>().text = "Stop";
         Debug.Log("Making/sending matchmaking request");
         MatchmakingRequest request = new MatchmakingRequest();
         request.SetMatchShortCode("DefaultMatch");
         request.SetSkill(0);
         request.Send(OnMatchmakingSuccess, OnMatchmakingError);
         matching = true;
         UnblockMatchInput();
     }
 }
        public void Start(Action <string> onCompletion = null, CancellationToken token = default)
        {
            if (m_MatchmakingRequest != null && !m_MatchmakingRequest.IsDone)
            {
                throw new InvalidOperationException($"Cannot call {nameof(Start)} twice on the same {nameof(MatchmakingWrapper)}; it represents a single stateful operation.");
            }

            Completed         = onCompletion;
            CancellationToken = token;

            m_AssignmentText = null;

            // Create a new ticket (our custom data) to be passed in with our match request
            var ticket = new CreateTicketRequest
            {
                Attributes = BuildTicketAttributes(),
                Properties = BuildTicketProperties()
            };

            // Create a new match request
            m_MatchmakingRequest = new MatchmakingRequest(m_MatchmakingServiceUrl, ticket)
            {
                // Pass in our own non-default network settings (optional)
                GetTicketPollIntervalSeconds = 1.0f
            };

            m_MatchmakingRequest.Completed += OnMatchmakingComplete;
            m_MatchmakingRequest.SendRequest();
        }
    public void CancelHosting()
    {
        if (hosting)
        {
            MatchmakingRequest matchmakingRequest = new MatchmakingRequest();
            matchmakingRequest.SetMatchShortCode("HostedMatch");

            GameSparks.Core.GSRequestData participantData = new GameSparks.Core.GSRequestData();
            participantData.AddString("displayName", gameSparksUserID.myDisplayName);
            participantData.AddBoolean("hosting", true);
            matchmakingRequest.SetParticipantData(participantData);
            matchmakingRequest.SetMatchData(participantData);
            matchmakingRequest.SetSkill(0);
            // Cancel host
            hosting = false;
            matchmakingRequest.SetAction("cancel");
            matchmakingRequest.Send(OnMatchmakingSuccess, OnMatchmakingError);
            // Change button text to represent hosting a game
            var buttonText = hostGameButton.GetComponentsInChildren <TMPro.TextMeshProUGUI>();
            buttonText[0].text          = "Host Game";
            joinGameButton.interactable = true;
            onRefreshGamesButtonClick();
            UnblockMatchmakingButton();
        }
    }
Exemplo n.º 5
0
    internal void FindPlayers(Action callback)
    {
        MatchFoundCallback = callback;

        GameSparks.Api.Messages.MatchFoundMessage.Listener += (resp) =>
        {
            OnMatchFound(resp);
        };

        MatchmakingRequest request = new MatchmakingRequest();

        request.SetSkill(0);
        request.SetMatchShortCode("SLIME_1V1");

        request.Send(
            (resp) =>
        {
            Debug.Log(resp.JSONString);
        },
            (resp) =>
        {
            Debug.LogError(resp.JSONString);
        }
            );
    }
    private void onRefreshGamesButtonClick()
    {
        BlockRefreshInput();
        // Make sure the user isn't currently hosting that way the refresh doesn't remove their hosted lobby/game
        if (!hosting)
        {
            GameSparksUserID gameSparksUserIDScript = GameObject.Find("GameSparksUserID").GetComponent <GameSparksUserID>();
            // Do a matchmaking request
            MatchmakingRequest matchmakingRequest = new MatchmakingRequest();
            matchmakingRequest.SetMatchShortCode("HostedMatch");

            GameSparks.Core.GSRequestData participantData = new GameSparks.Core.GSRequestData();
            participantData.AddString("displayName", gameSparksUserIDScript.myDisplayName);
            participantData.AddBoolean("hosting", false);
            matchmakingRequest.SetParticipantData(participantData);
            matchmakingRequest.SetMatchData(participantData);
            matchmakingRequest.SetSkill(0);
            // Store this request incase we get a throttled message
            lastMatchmakingRequest = matchmakingRequest;

            matchmakingRequest.Send(OnMatchmakingSuccess, OnMatchmakingError);
            FindGameLobbies();
        }
        else
        {
            FindGameLobbies();
        }
    }
Exemplo n.º 7
0
    /// <summary>
    /// Generate a Match Request object using pre-serialized player and group properties.  Does not check for valid JSON.
    /// </summary>
    /// <param name="playerId">Unique ID of the player</param>
    /// <param name="serializedPlayerProps">Pre-serialized player properties</param>
    /// <param name="serializedGroupProps">Pre-serialized group properties</param>
    /// <returns>A properly-formed matchmaking request object that can be used in calls to the matchmaking API</returns>
    public static MatchmakingRequest CreateMatchmakingRequest(string playerId, string serializedPlayerProps, string serializedGroupProps)
    {
        if (string.IsNullOrEmpty(playerId))
        {
            throw new ArgumentException($"{nameof(playerId)} must be a non-null, non-0-length string", nameof(playerId));
        }

        if (string.IsNullOrEmpty(serializedPlayerProps))
        {
            throw new ArgumentException($"{nameof(serializedPlayerProps)} must be a non-null, non-0-length string", nameof(serializedPlayerProps));
        }

        if (string.IsNullOrEmpty(serializedGroupProps))
        {
            throw new ArgumentException($"{nameof(serializedGroupProps)} must be a non-null, non-0-length string", nameof(serializedGroupProps));
        }

        var thisPlayer = new MatchmakingPlayer(playerId, serializedPlayerProps);
        var players    = new List <MatchmakingPlayer>()
        {
            thisPlayer
        };
        var request = new MatchmakingRequest(players, serializedGroupProps);

        return(request);
    }
Exemplo n.º 8
0
    private void MatchmakingButtonClickedResponder()
    {
        MatchmakingRequest request = new MatchmakingRequest();

        request.SetMatchShortCode("Test_Match");
        request.SetSkill(0);
        request.Send(OnMatchmakingResponseSuccess, OnMatchmakingResponseError);
    }
Exemplo n.º 9
0
    public void OnClickFindMatch()
    {
        MatchmakingRequest request = new MatchmakingRequest();

        request.SetMatchShortCode("defMatch");
        request.SetSkill(0);
        request.Send(OnMatchMakingSuccess, OnMatchMakingError);
        BlockInput();
    }
Exemplo n.º 10
0
    private void Play()
    {
        BlockInput();
        MatchmakingRequest request = new MatchmakingRequest();

        request.SetMatchShortCode("QUIZ_BATTLE");
        request.SetSkill(1);
        request.Send(OnMatchmakingSuccess, OnMatchmakingError);
        Debug.Log("Match Making Request: " + request.JSONString);
    }
Exemplo n.º 11
0
    /// <summary>
    /// Start matchmaking by issuing a request to the provided endpoint. Use client.matchmaker value
    /// as endpoint if none given.
    /// </summary>
    void CmdMatchmake(string[] args)
    {
        if (m_matchmaker != null)
        {
            GameDebug.Log("matchmake: Already in a matchmaking session. Wait for completion before matchmaking again.");
            return;
        }

        string endpoint = clientMatchmaker.Value;

        if (args.Length > 0)
        {
            endpoint = args[0];
        }

        if (string.IsNullOrEmpty(endpoint))
        {
            GameDebug.LogError("matchmake: command requires an endpoint <ip:port>");
            return;
        }

        if (string.IsNullOrEmpty(clientPlayerName.Value))
        {
            GameDebug.LogError("matchmake: Player name must be set before matchmaking can be started");
            return;
        }

        if (m_StateMachine.CurrentState() != ClientState.Browsing)
        {
            GameDebug.LogError("matchmake: matchmaking can only be started in Browsing state.  Current state is " + m_StateMachine.CurrentState().ToString());
            return;
        }

        GameDebug.Log($"matchmake: Starting the matchmaker. Requesting match from {endpoint} for player {clientPlayerName.Value}.");
        m_useMatchmaking = true;
        m_matchmaker     = new Matchmaker(endpoint);

        MatchmakingPlayerProperties playerProps = new MatchmakingPlayerProperties()
        {
            hats = 5
        };
        MatchmakingGroupProperties groupProps = new MatchmakingGroupProperties()
        {
            mode = 0
        };
        MatchmakingRequest request = Matchmaker.CreateMatchmakingRequest(clientPlayerName.Value, playerProps, groupProps);

        m_matchmaker.RequestMatch(request, OnMatchmakingSuccess, OnMatchmakingError);
    }
Exemplo n.º 12
0
    private void FindPlayers()
    {
        var request = new MatchmakingRequest();

        request.SetMatchShortCode("test_match");
        request.SetSkill(0);

        request.Send(r =>
        {
            if (r.HasErrors)
            {
                Debug.LogError("GSM | MatchMaking Error" + r.Errors.JSON);
            }
        });
    }
Exemplo n.º 13
0
        /**
         * Submit a Matchmaking Request
         */
        private static void MatchmakingRequest(int skill, string matchShortcode)
        {
            var req = new MatchmakingRequest();

            req.SetSkill(skill);
            req.SetMatchShortCode(matchShortcode);
            req.Send(r =>
            {
                if (r.HasErrors)
                {
                    Console.WriteLine("MatchmakingError: {0}", r.JSONString);
                }
                else
                {
                    Console.WriteLine("MatchmakingRequest Successful");
                }
            });
        }
    public void OnHostGameButtonClick()
    {
        BlockMatchmakingButton();
        joinGameButton.interactable = false;
        EventSystem.current.SetSelectedGameObject(null);

        gameSparksUserID = GameObject.Find("GameSparksUserID").GetComponent <GameSparksUserID>();

        MatchmakingRequest matchmakingRequest = new MatchmakingRequest();

        matchmakingRequest.SetMatchShortCode("HostedMatch");

        GameSparks.Core.GSRequestData participantData = new GameSparks.Core.GSRequestData();
        participantData.AddString("displayName", gameSparksUserID.myDisplayName);
        participantData.AddBoolean("hosting", true);
        matchmakingRequest.SetParticipantData(participantData);
        matchmakingRequest.SetMatchData(participantData);
        matchmakingRequest.SetSkill(0);


        if (!hosting)
        {
            hosting = true;
            // Change button text to represent canceling host
            var buttonText = hostGameButton.GetComponentsInChildren <TMPro.TextMeshProUGUI>();
            buttonText[0].text = "Cancel Host";
        }
        else
        {
            // Cancel host
            hosting = false;
            matchmakingRequest.SetAction("cancel");
            matchmakingRequest.Send(OnMatchmakingSuccess, OnMatchmakingError);
            // Change button text to represent hosting a game
            var buttonText = hostGameButton.GetComponentsInChildren <TMPro.TextMeshProUGUI>();
            buttonText[0].text          = "Host Game";
            joinGameButton.interactable = true;
            onRefreshGamesButtonClick();
            UnblockMatchmakingButton();
        }

        matchmakingRequest.Send(OnMatchmakingSuccess, OnMatchmakingError);
    }
Exemplo n.º 15
0
    public IEnumerator onMatchMakingButtonClick()
    {
        BlockInput();
        Debug.Log("Making/sending matchmaking request");

        string matchGroupNumber = "";

        yield return(GetMatchmakingGroupNumber(matchGroupNumber));

        MatchmakingRequest request = new MatchmakingRequest();

        request.SetMatchShortCode("DefaultMatch");
        request.SetSkill(0);
        request.SetMatchGroup(matchGroupNumber);
        // Store last request incase we get a throttled response
        lastMatchmakingRequest = request;

        request.Send(OnMatchmakingSuccess, OnMatchmakingError);
    }
Exemplo n.º 16
0
    private void MatchMaking(bool cancel = false)
    {
        var matchRequest = new MatchmakingRequest().SetMatchShortCode("matchRanked");

        if (cancel)
        {
            matchRequest
            .SetSkill(Skill)
            .SetMatchGroup("group1");
        }
        else
        {
            matchRequest.SetAction("cancel");
        }

        matchRequest.Send((response) => {
            GSData scriptData = response.ScriptData;
        });
    }
    public void CheckHosting()
    {
        if (hosting)
        {
            MatchmakingRequest matchmakingRequest = new MatchmakingRequest();
            matchmakingRequest.SetMatchShortCode("HostedMatch");

            GameSparks.Core.GSRequestData participantData = new GameSparks.Core.GSRequestData();
            participantData.AddString("displayName", gameSparksUserID.myDisplayName);
            participantData.AddBoolean("hosting", true);
            matchmakingRequest.SetParticipantData(participantData);
            matchmakingRequest.SetMatchData(participantData);
            matchmakingRequest.SetSkill(0);
            // Store this request incase we get a throttled message
            lastMatchmakingRequest = matchmakingRequest;

            matchmakingRequest.Send(OnMatchmakingSuccess, OnMatchmakingError);
            FindGameLobbies();
        }
        hostingCheckTimer.ResetTimer();
        hostingCheckTimer.StartCountdown();
    }
 /// <summary>
 /// Begin a new MatchmakingRequest
 /// </summary>
 /// <param name="requestData"></param>
 /// <returns></returns>
 public GameSparksBaseMultiplayerResponse MatchmakingRequest(MatchmakingRequest requestData)
 {
     return(JsonConvert.DeserializeObject <GameSparksBaseMultiplayerResponse>(Requestor.PostString(Urls.MatchmakingRequest, JsonHelper.SerializeData(requestData)).ResponseJson));
 }
Exemplo n.º 19
0
 public MatchmakingGroupData(MatchmakingRequest request)
 {
     Request = request;
 }
        /// <summary>
        /// Begin a new asynchronous MatchmakingRequest
        /// </summary>
        /// <param name="requestData"></param>
        /// <returns></returns>
        public async Task <GameSparksBaseMultiplayerResponse> MatchmakingRequestAsync(MatchmakingRequest requestData)
        {
            var res = await Requestor.PostStringAsync(Urls.MatchmakingRequest, JsonHelper.SerializeData(requestData));

            return(JsonConvert.DeserializeObject <GameSparksBaseMultiplayerResponse>(res.ResponseJson));
        }