internal void OnStateUpdated(SteamFriends.PersonaStateCallback callback) { if (callback == null) { Bot.ArchiLogger.LogNullError(nameof(callback)); return; } if ((callback.AvatarHash == null) || (callback.AvatarHash.Length == 0)) { return; } string avatarHash = BitConverter.ToString(callback.AvatarHash).Replace("-", "").ToLowerInvariant(); if (string.IsNullOrEmpty(avatarHash)) { return; } string avatarURL = "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/" + avatarHash.Substring(0, 2) + "/" + avatarHash + "_full.jpg"; AvatarPictureBox.ImageLocation = avatarURL; AvatarPictureBox.LoadAsync(); }
//------------------------------------------------------------------------ async private void GetProfileInfo() { CookieContainer cookies = new CookieContainer(); cookies.Add(Program.BaseAddress, new Cookie("PHPSESSID", Program.settings.PHPSESSID)); using (var handler = new HttpClientHandler() { CookieContainer = cookies }) using (var client = new HttpClient(handler) { BaseAddress = Program.BaseAddress }) { HttpResponseMessage result; try { result = await client.GetAsync(""); result.EnsureSuccessStatusCode(); } catch { MainForm.ShowLoadErrorMessage("Failed to get profile info"); return; } var responseString = await result.Content.ReadAsStringAsync(); HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument(); document.LoadHtml(responseString); //Get profile avatar HtmlNode avatar_node = document.DocumentNode.SelectSingleNode("//*[@class=\"nav__avatar-inner-wrap\"]"); if (CheckNode(avatar_node)) { string avatar_link = avatar_node.GetAttributeValue("style", ""); avatar_link = avatar_link.Substring(21); avatar_link = avatar_link.Remove(avatar_link.Length - 2); Regex rx = new Regex(@"_medium"); avatar_link = rx.Replace(avatar_link, "_full"); AvatarPictureBox.LoadAsync(avatar_link); } //Get profile link and name HtmlNode profile_link_node = document.DocumentNode.SelectSingleNode("//*[@class=\"nav__avatar-outer-wrap\"]"); if (CheckNode(profile_link_node)) { ProfileLink = profile_link_node.GetAttributeValue("href", ""); ProfileNameTextEdit.Text = ProfileLink.Remove(0, ProfileLink.LastIndexOf("/") + 1); } //Get points HtmlNode points_node = document.DocumentNode.SelectSingleNode("//*[@class=\"nav__points\"]"); if (CheckNode(points_node)) { PointsLabel.Text = "Points: " + points_node.InnerText; } //Get level HtmlNode level_node = document.DocumentNode.SelectSingleNode("//*[@title=\"1.34\"]"); if (CheckNode(points_node)) { LevelLabel.Text = level_node.InnerText; } } }