Ejemplo n.º 1
0
        public async Task <ResGetXboxLiveIdentity> GetXboxLiveIdentity(XboxLiveIdentityType type, string value)
        {
            var identity = await identityMapper.GetIdentity(type, value);

            return(new ResGetXboxLiveIdentity
            {
                CacheInfo = new CacheInfo(identity),
                Gamertag = identity.Gamertag,
                XUID = identity.XUID,
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the profile settings of a player. If no settings are given, it is assumed
        /// all are wanted.
        /// </summary>
        public async Task <ProfileSettings> GetProfileSettings(XboxLiveIdentityType type, string value, params ProfileSetting[] settings)
        {
            string[] strs = settings?.Any() == false
                                ? Enum.GetNames(typeof(ProfileSetting))
                                : settings.Select(ps => Enum.GetName(typeof(ProfileSetting), ps)).ToArray();

            var path  = string.Format(profileSettingsUrl, type.ToString(), value);
            var query = new Dictionary <string, string> {
                { "settings", string.Join(",", strs) }
            };

            return(await requestXboxLiveData <ProfileSettings>(_profileClient, 2, path, query, null));
        }
Ejemplo n.º 3
0
        public async Task <XboxLiveIdentity> GetIdentity(XboxLiveIdentityType type, string value)
        {
            var key = $"{type.ToString().ToLower()}-{value.ToSlug()}";
            Task <XboxLiveIdentity> task = null;

            lock (_inProgressLookups)
            {
                _inProgressLookups.TryGetValue(key, out task);

                // There should never be a task in it's completed state in the dictionary,
                // but if there is it won't be good - so we double check.
                if (task == null || task.IsCompleted)
                {
                    _inProgressLookups.TryAdd(key, (task = getIdentity(type, value)));
                }
            }

            return(await task);
        }
Ejemplo n.º 4
0
        private async Task <XboxLiveIdentity> getIdentity(XboxLiveIdentityType type, string value)
        {
            var sanitizedInput        = value.ToSlug();
            var now                   = DateTime.UtcNow;
            XboxLiveIdentity identity = null;

            if (type == XboxLiveIdentityType.Gamertag)
            {
                _gamertagMap.TryGetValue(sanitizedInput, out identity);
            }
            else if (type == XboxLiveIdentityType.Xuid)
            {
                _xuidMap.TryGetValue(long.Parse(value), out identity);
            }

            if (identity != null && identity.ExpiresAt > now)
            {
                return(identity);
            }

            var resp = await _xblClient.GetProfileSettings(type, value, ProfileSetting.Gamertag);

            var user = resp.ProfileUsers[0];

            identity = new XboxLiveIdentity
            {
                XUID      = user.ID,
                Gamertag  = user.Settings.First(s => s.ID == "Gamertag").Value,
                CachedAt  = now,
                ExpiresAt = now.Add(_cacheExpiry),
            };

            _gamertagMap[identity.Gamertag.ToSlug()] = identity;
            _xuidMap[identity.XUID] = identity;

            // Remove from pending list
            _inProgressLookups.Remove(sanitizedInput);

            return(identity);
        }