コード例 #1
0
        public static PlayerUserList GetList(SteamUserDetailResponse response, string[] ids)
        {
            var result = new PlayerUserList();

            if (ids != null)
            {
                foreach (var id in ids)
                {
                    result.Add(new PlayerUserItem()
                    {
                        PlayerId   = id,
                        PlayerName = "<not available>",
                    });
                }
            }

            if (response?.players != null)
            {
                foreach (var detail in response.players)
                {
                    var item = result.FirstOrDefault(i => i.PlayerId == detail.steamid);
                    if (item == null)
                    {
                        var newItem = PlayerUserItem.GetItem(detail);
                        if (!string.IsNullOrWhiteSpace(newItem?.PlayerId))
                        {
                            result.Add(newItem);
                        }
                    }
                    else
                    {
                        item.PlayerId   = detail.steamid;
                        item.PlayerName = detail.personaname ?? string.Empty;
                    }
                }
            }

            // remove all NULL records.
            for (int index = result.Count - 1; index >= 0; index--)
            {
                if (result[index] == null)
                {
                    result.RemoveAt(index);
                }
            }

            return(result);
        }