public void CancelFindingMatchFor(PlayerData player) { QueuedPlayer queuedPlayer = GetQueueEntryFor(player); if (queuedPlayer != null) { queuedPlayer.matchFoundTaskCompletionSource?.SetResult(MatchMakingResult.GetCancelledResult(player)); } RemoveQueueEntry(queuedPlayer); }
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); }
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); }
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); }
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); } }
private void RemoveQueueEntry(QueuedPlayer matchingPlayer) { queue.Remove(matchingPlayer); }
private void TimeoutQueuedPlayer(QueuedPlayer queuedPlayer) { RemoveQueueEntry(queuedPlayer); queuedPlayer.matchFoundTaskCompletionSource.SetResult(MatchMakingResult.GetTimeoutResult(queuedPlayer.player)); }
private void AddPlayerToQueue(QueuedPlayer player) { player.SetTimeout(matchMakerSettings.queueTimeoutLimit, TimeoutQueuedPlayer); queue.Add(player); }
private void SetMatchFoundFor(QueuedPlayer player) { player.MatchFound(); RemoveQueueEntry(player); }