public void ThreeTeamsTwoRoomsJoin() { //first player var player1 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> { { FakePropertyCodes.PlayerProperties.GameMode, 1 } }, 6); //second player var player2 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> { { FakePropertyCodes.PlayerProperties.GameMode, 1 } }, 6); //third player var player3 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> { { FakePropertyCodes.PlayerProperties.GameMode, 1 } }, 6); _playersManager.Add(player1, new List <Guid> { _group.Id }); _playersManager.Add(player2, new List <Guid> { _group.Id }); _playersManager.Add(player3, new List <Guid> { _group.Id }); emptyTask.Wait(1500); var rooms = _roomManager.GetRooms(_group.Id, false); Assert.AreEqual(2, rooms.Count()); }
public void Add(MatchMakingPlayer player, List <Guid> groups) { lock (_syncCollection) { if (_players.ContainsKey(player.Id)) { _players.Remove(player.Id); _logger.Error($"Player {player.Id} already added. Deleting previous"); } _players.Add(player.Id, player); _mmMetrics.TrackPlayerAdded(); foreach (var group in groups) { if (!_mmGroupToPlayer.ContainsKey(group)) { _mmGroupToPlayer.Add(group, new List <MatchMakingPlayer>()); } _mmGroupToPlayer[group].Add(player); if (!_playerToMmGroup.ContainsKey(player.Id)) { _playerToMmGroup.Add(player.Id, new List <Guid>()); } _playerToMmGroup[player.Id].Add(group); } } }
private void ProcessJoinResult(JoinRoomResult result, MatchMakingPlayer oldestPlayer) { switch (result.Result) { case RoomOperationResult.OK: foreach (var player in _matchmakingPlayers) { ProcessSuccess(player, result); } break; default: foreach (var player in _matchmakingPlayers) { ProcessFailed(player, result.Result.ToString()); } break; } _matchmakingPlayers.Clear(); if (oldestPlayer != null) { TrackMmTime(oldestPlayer); } _isGroupWorking = false; }
public void TwoTeamsMmJoin() { //first player var player1 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> { { FakePropertyCodes.PlayerProperties.GameMode, 1 } }, 6); //second player var player2 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> { { FakePropertyCodes.PlayerProperties.GameMode, 1 } }, 6); _playersManager.Add(player1, new List <Guid> { _group.Id }); _playersManager.Add(player2, new List <Guid> { _group.Id }); emptyTask.Wait(1500); var rooms = _roomManager.GetRooms(_group.Id); Assert.AreEqual(0, rooms.Count()); rooms = _roomManager.GetRooms(_group.Id, false); Assert.AreEqual(1, rooms.Count()); var room = rooms.First(); Assert.AreEqual(RoomState.Closed, room.State); Assert.AreEqual(0, room.MaxWeightToJoin); Assert.AreEqual(2, room.CurrentWeight); Assert.AreEqual(12, room.TotalWeightNeeded); }
public void TwoPlayers2MatchMakingTest() { //one player two bots var player1 = new MatchMakingPlayer(new FakePeer(), _playerProperties); var player2 = new MatchMakingPlayer(new FakePeer(), _playerProperties); _matchMakingGroupManager.AddPlayerToMatchMaking(player1); emptyTask.Wait(1500); var rooms = _matchMakingGroupManager.GetRooms(_playerProperties); Assert.AreEqual(0, rooms.Count()); rooms = _roomManager.GetAllRooms(); _roomManager.UpdateRoomState(rooms.First().Id, 1, RoomState.Open, 1); rooms = _matchMakingGroupManager.GetRooms(_playerProperties); Assert.AreEqual(1, rooms.Count()); var room = rooms.FirstOrDefault(); Assert.AreEqual(1, room.CurrentWeight); Assert.AreEqual(true, room.IsOpen()); Assert.AreEqual(true, room.CanJoin(1, 1)); //join second _roomManager.UpdateRoomState(room.Id, 1, RoomState.Open, 1); _matchMakingGroupManager.AddPlayerToMatchMaking(player2); emptyTask.Wait(500); //open again - it was closed after adding a player _roomManager.UpdateRoomState(room.Id, 2, RoomState.Open, 1); rooms = _matchMakingGroupManager.GetRooms(_playerProperties); Assert.AreEqual(1, rooms.Count()); room = rooms.FirstOrDefault(); Assert.AreEqual(2, room.CurrentWeight); Assert.AreEqual(true, room.IsOpen()); Assert.AreEqual(true, room.CanJoin(1, 1)); }
public void OnePlayerMatchMakingTest() { //one player two bots var player = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> { { FakePropertyCodes.PlayerProperties.GameMode, 1 } }); _playersManager.Add(player, new List <Guid> { _group.Id }); emptyTask.Wait(1500); var rooms = _roomManager.GetRooms(_group.Id); Assert.AreEqual(0, rooms.Count()); rooms = _roomManager.GetRooms(_group.Id, false); Assert.AreEqual(1, rooms.Count()); _roomManager.UpdateRoomState(rooms.First().Id, 1, RoomState.Open, 1); rooms = _roomManager.GetRooms(_group.Id); Assert.AreEqual(1, rooms.Count()); var room = rooms.FirstOrDefault(); Assert.AreEqual(1, room.CurrentWeight); Assert.AreEqual(true, room.IsOpen()); Assert.AreEqual(true, room.CanJoin(2, 1)); }
private void AddPlayer(MatchMakingPlayer player) { lock (_queueSync) { player.AddedToMmGroupOn = DateTime.UtcNow; _matchmakingPlayers.Enqueue(player); } }
private bool EnoughWaiting(MatchMakingPlayer oldestPlayer) { if (oldestPlayer?.AddedToMmGroupOn == null) { return(false); } return((DateTime.UtcNow - oldestPlayer.AddedToMmGroupOn.Value).TotalMilliseconds >= _maximumMmTime); }
private void ProcessSuccess(MatchMakingPlayer player, JoinRoomResult result) { _logger.Debug($"Sending join info to {player.Id}"); var joinInfo = new JoinInfo(result.Address, result.Port, result.RoomId, JoinStatus.RoomIsReady, GetCurrentPlayersWeight(), _totalPlayersNeeded, true); _messageSender.Send(new JoinInfoEvent(joinInfo), player.Peer); _playersManager.Remove(player.Id); }
private void ProcessFailed(MatchMakingPlayer player, string message) { _logger.Error($"Sending matchmaking failed info to {player.Id}: {message}"); _playersManager.SetOnMatchmaking(player.Id, false); var joinInfo = new JoinInfo("", 0, Guid.Empty, JoinStatus.MatchMakingFailed, 0, 0); _messageSender.Send(new JoinInfoEvent(joinInfo), player.Peer); _playersManager.Remove(player.Id); }
private void TrackMmTime(MatchMakingPlayer oldestPlayer) { if (oldestPlayer != null && oldestPlayer.AddedToMmGroupOn.HasValue) { _mmMetrics.TrackMmCompleted((long)(DateTime.UtcNow - oldestPlayer.AddedToMmGroupOn.Value).TotalMilliseconds); } else { _logger.Error($"Oldest player not found when tracking MM time"); } }
public void AddPlayer(MmPeer peer, Dictionary <byte, object> properties, int mmmWeight) { var player = new MatchMakingPlayer(peer, properties, mmmWeight); _groupManager.AddPlayerToMatchMaking(player); // var groups = _groupManager.GetMatchmakingGroupIds(properties); // if (groups == null || groups.Count == 0) // _logger.Error($"MatchMaker.AddPlayer error: no groups for player"); // else // _playersManager.Add(player, groups); }
public void SetOnMatchMakingTest() { var player1 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object>()); var player2 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object>()); _playersManager.Add(player2, groupList1); _playersManager.Add(player1, groupList1); Assert.AreEqual(2, _playersManager.GetPlayers(groupList1[0], 2, 1).Count()); _playersManager.SetOnMatchmaking(player2.Id, true); Assert.AreEqual(1, _playersManager.GetPlayers(groupList1[0], 2, 1).Count()); _playersManager.SetOnMatchmaking(player2.Id, false); Assert.AreEqual(2, _playersManager.GetPlayers(groupList1[0], 2, 1).Count()); }
public void AddRemoveTest() { var player = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object>()); var playerId = player.Id; _playersManager.Add(player, groupList1); var newPlayer = _playersManager.GetPlayer(playerId); Assert.AreEqual(player, newPlayer); Assert.AreEqual(1, _playersManager.Count()); _playersManager.Remove(playerId); Assert.AreEqual(0, _playersManager.Count()); Assert.IsNull(_playersManager.GetPlayer(Guid.NewGuid())); }
public void AddPlayerToMatchMaking(MatchMakingPlayer player) { lock (_mutex) { var groups = GetMatchmakingGroupIds(player.Properties); if (groups == null || groups.Count == 0) { _logger.Info($"AddPlayerToMatchMaking error: no groups for player"); groups = new List <Guid>(); groups.Add(AddMatchMakingGroup(player.Properties)); } _playersManager.Add(player, groups); } }
public void GetPlayerByGroup() { var player1 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object>()); var player2 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object>()); var player3 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object>()); _playersManager.Add(player2, groupList1); _playersManager.Add(player1, groupList1); _playersManager.Add(player3, groupList2); Assert.AreEqual(0, _playersManager.GetPlayers(groupList1[0], 0, 1).Count()); Assert.AreEqual(0, _playersManager.GetPlayers(Guid.NewGuid(), 1, 1).Count()); Assert.AreEqual(1, _playersManager.GetPlayers(groupList1[0], 1, 1).Count()); Assert.AreEqual(2, _playersManager.GetPlayers(groupList1[0], 2, 1).Count()); Assert.AreEqual(1, _playersManager.GetPlayers(groupList2[0], 1, 1).Count()); Assert.AreEqual(3, _playersManager.Count()); _playersManager.Clear(); Assert.AreEqual(0, _playersManager.Count()); }
public void GetOldestPlayerTest() { Assert.IsNull(_playersManager.GetOldestPlayer()); var player1 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object>()); var player2 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object>()); var player3 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object>()); _playersManager.Add(player2, groupList1); emptyTask.Wait(100); _playersManager.Add(player1, groupList1); _playersManager.Add(player3, groupList2); var oldestPlayer = _playersManager.GetOldestPlayer(); Assert.AreEqual(player2, oldestPlayer); _playersManager.Remove(Guid.NewGuid()); _playersManager.Remove(player1.Id); _playersManager.Remove(player2.Id); oldestPlayer = _playersManager.GetOldestPlayer(); Assert.AreEqual(player3, oldestPlayer); Assert.AreEqual(1, _playersManager.Count()); }
public void OnePlayerMatchMakingTest() { //one player two bots var player = new MatchMakingPlayer(new FakePeer(), _playerProperties); _matchMakingGroupManager.AddPlayerToMatchMaking(player); emptyTask.Wait(1500); var rooms = _matchMakingGroupManager.GetRooms(_playerProperties); Assert.AreEqual(0, rooms.Count()); rooms = _roomManager.GetAllRooms(); _roomManager.UpdateRoomState(rooms.First().Id, 1, RoomState.Open, 1); rooms = _matchMakingGroupManager.GetRooms(_playerProperties); Assert.AreEqual(1, rooms.Count()); var room = rooms.FirstOrDefault(); Assert.AreEqual(1, room.CurrentWeight); Assert.AreEqual(true, room.IsOpen()); Assert.AreEqual(true, room.CanJoin(2, 1)); }
public void WeightJoinTest() { //first player var player1 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> { { FakePropertyCodes.PlayerProperties.GameMode, 1 } }, 1); //second player with weight > 1 (team probably) var player2 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> { { FakePropertyCodes.PlayerProperties.GameMode, 1 } }, 6); _playersManager.Add(player1, new List <Guid> { _group.Id }); _playersManager.Add(player2, new List <Guid> { _group.Id }); emptyTask.Wait(1500); var rooms = _roomManager.GetRooms(_group.Id); Assert.AreEqual(0, rooms.Count()); rooms = _roomManager.GetRooms(_group.Id, false); Assert.AreEqual(1, rooms.Count()); var room = rooms.First(); Assert.AreEqual(RoomState.Closed, room.State); Assert.AreEqual(0, room.MaxWeightToJoin); Assert.AreEqual(2, room.CurrentWeight); Assert.AreEqual(12, room.TotalWeightNeeded); //update state _roomManager.UpdateRoomState(rooms.First().Id, 2, RoomState.Open, 5); rooms = _roomManager.GetRooms(_group.Id); Assert.AreEqual(1, rooms.Count()); room = rooms.FirstOrDefault(); Assert.AreEqual(2, room.CurrentWeight); Assert.AreEqual(true, room.IsOpen()); Assert.AreEqual(true, room.CanJoin(5, 5)); //third player var player3 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> { { FakePropertyCodes.PlayerProperties.GameMode, 1 } }, 1); _playersManager.Add(player3, new List <Guid> { _group.Id }); emptyTask.Wait(1500); rooms = _roomManager.GetRooms(_group.Id, false); _roomManager.UpdateRoomState(rooms.First().Id, 2, RoomState.Open, 5); //forth player var player4 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> { { FakePropertyCodes.PlayerProperties.GameMode, 1 } }, 4); _playersManager.Add(player4, new List <Guid> { _group.Id }); emptyTask.Wait(1500); rooms = _roomManager.GetRooms(_group.Id, false); //player 4 has weight > 1 - so he will go to new room Assert.AreEqual(2, rooms.Count()); }