Example #1
0
        public void CancelFindingMatchFor(PlayerData player)
        {
            QueuedPlayer queuedPlayer = GetQueueEntryFor(player);

            if (queuedPlayer != null)
            {
                queuedPlayer.matchFoundTaskCompletionSource?.SetResult(MatchMakingResult.GetCancelledResult(player));
            }

            RemoveQueueEntry(queuedPlayer);
        }
Example #2
0
        private void QueuePlayer(Identity identity, string playerName, ulong group, Vector3 pos, Vector3 rotation, int channel, bool mainplayer)
        {
            QueuedPlayer player = new QueuedPlayer
            {
                Identity     = identity,
                Name         = playerName,
                Group        = @group,
                Pos          = pos,
                Rotation     = rotation,
                Channel      = channel,
                IsMainPlayer = mainplayer
            };

            _players.Add(player);
        }
Example #3
0
            public bool IsValidMatchFor(QueuedPlayer otherPlayer)
            {
                if (otherPlayer == this)
                {
                    return(false);
                }
                if (matchMakingData.IsValidMatchFor(otherPlayer.matchMakingData) == false)
                {
                    return(false);
                }
                if (otherPlayer.matchMakingData.IsValidMatchFor(matchMakingData) == false)
                {
                    return(false);
                }

                return(true);
            }
Example #4
0
        private bool TryMatchingWithCurrentQueue(QueuedPlayer newQueueEntry, out MatchMakingResult result)
        {
            QueuedPlayer matchingPlayer = queue.Find(qp => qp.IsValidMatchFor(newQueueEntry));

            if (matchingPlayer != null)
            {
                SetMatchFoundFor(matchingPlayer);

                var battleId = BBServer.Instance.Systems.BattleManager.CreateBattleFor(matchingPlayer.player, newQueueEntry.player, new BattleCreationData());
                result = new MatchMakingResult(newQueueEntry.player, matchingPlayer.player, battleId, MatchMakingResult.Status.MatchFound);

                matchingPlayer.matchFoundTaskCompletionSource.SetResult(result);
                return(true);
            }

            result = null;
            return(false);
        }
Example #5
0
        public async Task <MatchMakingResult> FindAMatch(PlayerData player, MatchMakingSettings matchMakingData)
        {
            QueuedPlayer newQueueEntry = CreatePlayerQueueEntryFor(player, matchMakingData);

            if (IsPlayerInQueue(player))
            {
                return(new MatchMakingResult(player, null, null, MatchMakingResult.Status.Error));
            }

            if (TryMatchingWithCurrentQueue(newQueueEntry, out MatchMakingResult result))
            {
                return(result);
            }
            else
            {
                AddPlayerToQueue(newQueueEntry);

                return(await newQueueEntry.matchFoundTaskCompletionSource.Task);
            }
        }
Example #6
0
 private void RemoveQueueEntry(QueuedPlayer matchingPlayer)
 {
     queue.Remove(matchingPlayer);
 }
Example #7
0
 private void TimeoutQueuedPlayer(QueuedPlayer queuedPlayer)
 {
     RemoveQueueEntry(queuedPlayer);
     queuedPlayer.matchFoundTaskCompletionSource.SetResult(MatchMakingResult.GetTimeoutResult(queuedPlayer.player));
 }
Example #8
0
 private void AddPlayerToQueue(QueuedPlayer player)
 {
     player.SetTimeout(matchMakerSettings.queueTimeoutLimit, TimeoutQueuedPlayer);
     queue.Add(player);
 }
Example #9
0
        private void SetMatchFoundFor(QueuedPlayer player)
        {
            player.MatchFound();

            RemoveQueueEntry(player);
        }