示例#1
0
        public Guid AddMatchMakingGroup(Dictionary <byte, object> measures)
        {
            lock (_mutex)
            {
                var roomProperties = new Dictionary <byte, object>();
                roomProperties.Add(PropertyCode.RoomProperties.MatchMakingTick,
                                   _roomPropertiesProvider.GetMatchMakingTick(measures));
                roomProperties.Add(PropertyCode.RoomProperties.MaximumMmTime,
                                   _roomPropertiesProvider.GetMaximumMatchMakingTime(measures));
                roomProperties.Add(PropertyCode.RoomProperties.MaximumMatchMakingWeight,
                                   _roomPropertiesProvider.GetMaximumMatchMakingWeight(measures));
                roomProperties.Add(PropertyCode.RoomProperties.TotalPlayersNeeded,
                                   _roomPropertiesProvider.GetMaximumPlayers(measures));
                roomProperties.Add(PropertyCode.RoomProperties.MatchMakerUrl,
                                   UrlHelper.GetUrl(_config.BindToPortHttp, 0, _config.PublicDomainNameOrAddress));

                foreach (var add in _roomPropertiesProvider.GetAdditionalRoomProperties(measures))
                {
                    roomProperties.Add(add.Key, add.Value);
                }

                var group = new MatchMakingGroup(roomProperties, _logger, _taskSchedulerFactory, _playersManager,
                                                 _messageSender, _mmMetrics, _roomManager);
                _groups.Add(group.Id, group);
                _groupsToProperties.Add(group.Id, measures);
                if (_isStarted)
                {
                    group.Start();
                }

                var str = new StringBuilder();
                str.Append($"New MM group added (total {_groups.Count}): properties: \n");
                foreach (var item in roomProperties)
                {
                    str.Append($"[{item.Key}]: {item.Value} \n");
                }

                _logger.Error(str.ToString());

                return(group.Id);
            }
        }
        public void Setup()
        {
            _logger = new ConsoleLogger();
            _taskSchedulerFactory = new TaskSchedulerFactory(_logger);
            _playersManager       = new PlayersManager(Mock.Of <IMmMetrics>(), _logger);
            _packetSender         = Mock.Of <IShamanMessageSender>();
            _serverProvider       = new FakeServerProvider();
            _requestSender        = new FakeSender();
            _roomApiProvider      = new DefaultRoomApiProvider(_requestSender, _logger);
            _roomManager          = new RoomManager(_serverProvider, _logger, _taskSchedulerFactory, _roomApiProvider);

            _measures.Add(FakePropertyCodes.PlayerProperties.GameMode, 1);
            _roomProperties.Add(FakePropertyCodes.RoomProperties.MatchMakingTick, 250);
            _roomProperties.Add(FakePropertyCodes.RoomProperties.TotalPlayersNeeded, 3);
            _roomProperties.Add(FakePropertyCodes.RoomProperties.MaximumMmTime, 500);
            _roomProperties.Add(FakePropertyCodes.RoomProperties.MaximumMatchMakingWeight, 1);


            _group = new MatchMakingGroup(_roomProperties, _logger, _taskSchedulerFactory, _playersManager,
                                          _packetSender, Mock.Of <IMmMetrics>(), _roomManager);
            _roomManager.Start(10000);
            _group.Start();
        }