public List <Guid> GetMatchmakingGroupIds(Dictionary <byte, object> playerProperties) { lock (_mutex) { var result = new List <Guid>(); foreach (var group in _groupsToProperties) { if (DictionaryHelpers.AreDictionariesEqual(group.Value, playerProperties)) { result.Add(group.Key); } } return(result); } }
private IRoom GetRandomRoomOrCreateOne(Guid sessionId, Dictionary <byte, object> roomProperties) { IRoom result = null; var openRooms = _rooms.Where(r => r.Value.IsOpen() && DictionaryHelpers.AreDictionariesEqual(roomProperties, r.Value.GetPropertiesContainer().GetRoomProperties())).Select(i => i.Value).ToList(); var players = new Dictionary <Guid, Dictionary <byte, object> > { { sessionId, new Dictionary <byte, object>() } }; if (!openRooms.Any()) { var roomId = CreateRoom(roomProperties, players, null); result = GetRoomById(roomId); } else { result = openRooms[_rnd.Next(0, openRooms.Count)]; UpdateRoom(result.GetRoomId(), players); } return(result); }