private void HandleMatchmakeResult(MatchmakeResult result)
        {
            var responses = new List <QueuedMatchResponseModel>();

            foreach (var match in result.Matches)
            {
                foreach (var request in match.Requests)
                {
                    var queuedRequest = _requestBuffer[request.Id];
                    var response      = new QueuedMatchResponseModel
                    {
                        RequestId = queuedRequest.Id,
                        WebSocket = queuedRequest.WebSocket,
                        WebSocketCompletionSource = queuedRequest.WebSocketCompletionSource,
                        Players = queuedRequest.Players,
                        Match   = match
                    };
                    responses.Add(response);
                    _requestBuffer.Remove(request.Id, out _);
                }
            }

            _outQueue.EnqueueRange(responses);
            _matchCount += result.Matches.Count();
        }
Beispiel #2
0
    private void MatchMakeCallBack(MatchmakeResult obj)
    {
        socket          = new TcpClient(obj.ServerHostname, (int)obj.ServerPort);
        stream          = socket.GetStream();
        writer          = new StreamWriter(stream);
        reader          = new StreamReader(stream);
        matchMakeTicket = obj.Ticket;

        socketReady = true;
    }
        public MatchmakeResult Matchmake(GameFormat format, IEnumerable <MatchRequest> requests)
        {
            var matchSize = GameSetup.GameFormatsToPlayersRequired[format];
            var matches   = new List <Match>();

            var preferenceScores   = _scoreCalculator.GetScores(requests);
            var orderedPreferences = preferenceScores
                                     .OrderByDescending(x => x.Value)
                                     .Select(x => x.Key)
                                     .ToList();

            var orderedRequests = requests.OrderByDescending(x => x.QueuedOn).ToList();

            foreach (var preference in orderedPreferences)
            {
                if (orderedRequests.Sum(x => x.Players.Count()) < matchSize)
                {
                    break;
                }

                var requestGroup = new List <MatchRequest>(matchSize);
                for (var i = orderedRequests.Count - 1; i >= 0; i--)
                {
                    var request = orderedRequests[i];
                    if (HasPreference(request, preference))
                    {
                        var playerCount = requestGroup.Sum(x => x.Players.Count()) + request.Players.Count();
                        if (playerCount <= matchSize)
                        {
                            requestGroup.Add(request);
                        }
                        if (playerCount == matchSize)
                        {
                            requestGroup.ForEach(x => orderedRequests.Remove(x));

                            var match = new Match(requestGroup, format, preference.Title, preference.Mode);
                            matches.Add(match);

                            requestGroup = new List <MatchRequest>(matchSize);
                        }
                    }
                }
            }

            var result = new MatchmakeResult(matches, orderedRequests);

            return(result);
        }
 private void PlayFab_OnMatchmakeSuccess(MatchmakeResult result)
 {
     isJoining = false;
     if (result.Status == MatchmakeStatus.Complete)
     {
         clientNetworkManager.JoinServer(result.ServerHostname, result.Ticket);
     }
     else if (result.Status == MatchmakeStatus.GameNotFound || result.Status == MatchmakeStatus.NoAvailableSlots)
     {
         clientNetworkManager.OnJoinServerFailed("PlayFab: No servers with available slots were found.");
     }
     else
     {
         clientNetworkManager.OnJoinServerFailed("PlayFab: Returned unknown matchmaking status: " + result.Status);
     }
 }