public void StartMatchmaking()
    {
        cancelMatchButton.SetActive(false);
        queueStatusText.text = "Searching For Player...";
        randomMatchMakingPanel.SetActive(true);
        mainPanel.SetActive(false);

        PlayFabMultiplayerAPI.CreateMatchmakingTicket(
            new CreateMatchmakingTicketRequest
        {
            Creator = new MatchmakingPlayer
            {
                Entity = new EntityKey
                {
                    Id   = authentication.id,
                    Type = "title_player_account",
                },
                Attributes = new MatchmakingPlayerAttributes
                {
                    DataObject = new { IP = playerID }
                }
            },

            GiveUpAfterSeconds = 120,

            QueueName = queueName
        },
            OnMatchmakingTicketCreated,
            OnMatchmakingError
            );
    }
        public IEnumerator CreateMatchmakingTicket(string attributeValue)
        {
            ExecutionCompleted = false;

            PlayFabMultiplayerAPI.CreateMatchmakingTicket(
                new CreateMatchmakingTicketRequest
            {
                Creator = new MatchmakingPlayer
                {
                    Attributes = GetMatchmakingAttribute(attributeValue),
                    Entity     = new EntityKey
                    {
                        Id   = Player.Entity.Id,
                        Type = Player.Entity.Type,
                    },
                },
                GiveUpAfterSeconds    = QueueConfiguration.GiveUpAfterSeconds,
                QueueName             = QueueConfiguration.QueueName,
                AuthenticationContext = PlayFabAuthenticationContext
            },
                (result) =>
            {
                ExecutionCompleted      = true;
                MatchmakingTicketResult = result;
            },
                (error) =>
            {
                var result = $"On CreateMatchmakingTicket failed. Message: {error.ErrorMessage}, Code: {error.HttpCode}";
                Debug.Log(result);
            }
                );

            yield return(WaitForExecution());
        }
Beispiel #3
0
        void CreateTicket()
        {
            var matchingplayer = new MatchmakingPlayer {
                Entity = new PlayFab.MultiplayerModels.EntityKey {
                    Id   = PlayFabSettings.staticPlayer.EntityId,
                    Type = PlayFabSettings.staticPlayer.EntityType,
                },
                Attributes = new MatchmakingPlayerAttributes {
                    DataObject = new { },
                }
            };

            PlayFabMultiplayerAPI.CreateMatchmakingTicket(
                new CreateMatchmakingTicketRequest {
                Creator            = matchingplayer,
                GiveUpAfterSeconds = 12,     // 最大600秒
                QueueName          = QUEUE_NAME,
            },
                result => {
                StartCoroutine(Polling(result.TicketId));
            },
                error => {
                Debug.LogError(error.GenerateErrorReport());
            }
                );
        }
Beispiel #4
0
    private void StartMatchmakingRequest(string entityID, string entityType)
    {
        // Create a matchmaking request
        PlayFabMultiplayerAPI.CreateMatchmakingTicket(
            new CreateMatchmakingTicketRequest {
            Creator = new MatchmakingPlayer {
                Entity = new PlayFab.MultiplayerModels.EntityKey {
                    Id   = entityID,
                    Type = entityType
                },
                Attributes = new MatchmakingPlayerAttributes {
                    DataObject = new {
                        Latencies = new object[] {
                            new {
                                region  = region,
                                latency = 100
                            }
                        },
                    },
                },
            },

            // Cancel matchmaking after this time in seconds with no match found
            GiveUpAfterSeconds = matchmakingTimeout,

            // name of the queue to poll
            QueueName = matchmakingQueue,
        },

            this.OnMatchmakingTicketCreated,
            this.OnPlayFabError
            );
    }
Beispiel #5
0
 void CreateMatchmakingTicket()
 {
     PlayFabMultiplayerAPI.CreateMatchmakingTicket(
         new CreateMatchmakingTicketRequest
     {
         Creator = new MatchmakingPlayer
         {
             Entity = _entityKey,
         },
         GiveUpAfterSeconds = _matchTimeout,
         QueueName          = SelectedQueue,
     },
         (result) => _ticketID = result.TicketId,
         (error) => print(error.GenerateErrorReport())
         );
 }
Beispiel #6
0
        public IEnumerator CreateTicket(string attribute, string networkId = "")
        {
            ExecutionCompleted = false;

            PlayFabMultiplayerAPI.CreateMatchmakingTicket(
                GetCreateRequest(GetPlayerAttribute(attribute, networkId)),
                (result) =>
            {
                ExecutionCompleted      = true;
                MatchmakingTicketResult = result;
            },
                (error) =>
            {
                var result = $"On CreateMatchmakingTicket failed. Message: {error.ErrorMessage}, Code: {error.HttpCode}";
                Debug.Log(result);
            }
                );

            yield return(WaitForExecution());
        }
    public void StartMatchmaking()
    {
        PlayfabUtils.OnSuccess(feedbackText, "Matchmaking in progress...");

        PlayFabMultiplayerAPI.ListQosServersForTitle(new ListQosServersForTitleRequest(), qosRes =>
        {
            var qosServer = qosRes.QosServers[0].ServerUrl;
            var qosRegion = qosRes.QosServers[0].Region;
            Debug.Log($"Pinging QoS Server {qosServer} at {qosRegion}");
            Debug.Log(qosRes.ToJson());

            var sw = System.Diagnostics.Stopwatch.StartNew();

            var udpPort = 5600;
            var done    = false;
            while (!done || udpPort > 5610)
            {
                try
                {
                    UdpClient client = new UdpClient(udpPort);
                    client.Connect(qosServer, 3075);
                    byte[] sendBytes = BitConverter.GetBytes(0xFFFF);
                    client.Send(sendBytes, sendBytes.Length);

                    IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 3075);
                    byte[] receiveBytes       = client.Receive(ref remoteEndPoint);
                    client.Close();
                    done = true;
                }
                catch (Exception e)
                {
                    Debug.LogError($"[QoS Ping Error]: {e.Message}");
                    udpPort++;
                    Debug.Log($"Retrying with port {udpPort}");
                }
            }
            var pingTime = sw.ElapsedMilliseconds;
            Debug.Log($"Ping success with {pingTime}ms");
            if (udpPort > 5610)
            {
                StartMatchmaking();
                return;
            }

            var request = new CreateMatchmakingTicketRequest
            {
                Creator = new MatchmakingPlayer
                {
                    Entity = new PlayFab.MultiplayerModels.EntityKey
                    {
                        Id   = loginManager.playerData.accountInfo.entityId,
                        Type = PlayfabUtils.ENTITY_TYPE
                    },
                    Attributes = new MatchmakingPlayerAttributes
                    {
                        DataObject = new LatenciesData
                        {
                            Latencies = new List <Latency>
                            {
                                { new Latency {
                                      region = qosRegion, latency = pingTime
                                  } }
                            }
                        }
                    }
                },
                GiveUpAfterSeconds = PlayfabUtils.MATCHMAKING_TIMEOUT,
                QueueName          = PlayfabUtils.MATCHMAKING_NAME
            };

            PlayFabMultiplayerAPI.CreateMatchmakingTicket(request, OnTicketCreated, OnError);
        }, OnError);
    }