Esempio 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();
        }
    }
Esempio n. 2
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);
    }