diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index dde40039c..b35d08725 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -38,9 +38,11 @@ using ArchiSteamFarm.JSON; namespace ArchiSteamFarm { internal sealed class ArchiWebHandler : IDisposable { private const string SteamCommunityHost = "steamcommunity.com"; + private const string SteamStoreHost = "store.steampowered.com"; private const byte MinSessionTTL = GlobalConfig.DefaultHttpTimeout / 4; // Assume session is valid for at least that amount of seconds private static string SteamCommunityURL = "https://" + SteamCommunityHost; + private static string SteamStoreURL = "https://" + SteamStoreHost; private static int Timeout = GlobalConfig.DefaultHttpTimeout * 1000; // This must be int type private readonly Bot Bot; @@ -55,6 +57,7 @@ namespace ArchiSteamFarm { internal static void Init() { Timeout = Program.GlobalConfig.HttpTimeout * 1000; SteamCommunityURL = (Program.GlobalConfig.ForceHttp ? "http://" : "https://") + SteamCommunityHost; + SteamStoreURL = (Program.GlobalConfig.ForceHttp ? "http://" : "https://") + SteamStoreHost; } private static uint GetAppIDFromMarketHashName(string hashName) { @@ -230,8 +233,13 @@ namespace ArchiSteamFarm { } WebBrowser.CookieContainer.Add(new Cookie("sessionid", sessionID, "/", "." + SteamCommunityHost)); + WebBrowser.CookieContainer.Add(new Cookie("sessionid", sessionID, "/", "." + SteamStoreHost)); + WebBrowser.CookieContainer.Add(new Cookie("steamLogin", steamLogin, "/", "." + SteamCommunityHost)); + WebBrowser.CookieContainer.Add(new Cookie("steamLogin", steamLogin, "/", "." + SteamStoreHost)); + WebBrowser.CookieContainer.Add(new Cookie("steamLoginSecure", steamLoginSecure, "/", "." + SteamCommunityHost)); + WebBrowser.CookieContainer.Add(new Cookie("steamLoginSecure", steamLoginSecure, "/", "." + SteamStoreHost)); Logging.LogGenericInfo("Success!", Bot.BotName); @@ -247,6 +255,41 @@ namespace ArchiSteamFarm { return true; } + internal async Task> GetFamilySharingSteamIDs() { + if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) { + return null; + } + + string request = SteamStoreURL + "/account/managedevices"; + HtmlDocument htmlDocument = await WebBrowser.UrlGetToHtmlDocumentRetry(request).ConfigureAwait(false); + + HtmlNodeCollection htmlNodes = htmlDocument?.DocumentNode.SelectNodes("(//table[@class='accountTable'])[last()]//a/@data-miniprofile"); + if (htmlNodes == null) { + return null; // OK, no authorized steamIDs + } + + HashSet result = new HashSet(); + + foreach (HtmlNode htmlNode in htmlNodes) { + string miniProfile = htmlNode.GetAttributeValue("data-miniprofile", null); + if (string.IsNullOrEmpty(miniProfile)) { + Logging.LogNullError(nameof(miniProfile), Bot.BotName); + return null; + } + + uint steamID3; + if (!uint.TryParse(miniProfile, out steamID3) || steamID3 == 0) { + Logging.LogNullError(nameof(steamID3), Bot.BotName); + return null; + } + + ulong steamID = new SteamID(steamID3, EUniverse.Public, EAccountType.Individual); + result.Add(steamID); + } + + return result; + } + internal async Task JoinGroup(ulong groupID) { if (groupID == 0) { Logging.LogNullError(nameof(groupID), Bot.BotName); diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 941946194..c5198751e 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -62,6 +62,7 @@ namespace ArchiSteamFarm { private readonly CardsFarmer CardsFarmer; private readonly ConcurrentHashSet HandledGifts = new ConcurrentHashSet(); + private readonly ConcurrentHashSet SteamFamilySharingIDs = new ConcurrentHashSet(); private readonly ConcurrentHashSet OwnedPackageIDs = new ConcurrentHashSet(); private readonly SteamApps SteamApps; private readonly SteamClient SteamClient; @@ -279,6 +280,7 @@ namespace ArchiSteamFarm { CardsFarmer.Dispose(); HeartBeatTimer.Dispose(); HandledGifts.Dispose(); + SteamFamilySharingIDs.Dispose(); OwnedPackageIDs.Dispose(); Trading.Dispose(); @@ -593,6 +595,18 @@ namespace ArchiSteamFarm { } } + private async Task InitializeFamilySharing() { + HashSet steamIDs = await ArchiWebHandler.GetFamilySharingSteamIDs().ConfigureAwait(false); + if (steamIDs == null || steamIDs.Count == 0) { + return; + } + + SteamFamilySharingIDs.ClearAndTrim(); + foreach (ulong steamID in steamIDs) { + SteamFamilySharingIDs.Add(steamID); + } + } + private void ImportAuthenticator(string maFilePath) { if ((BotDatabase.MobileAuthenticator != null) || !File.Exists(maFilePath)) { return; @@ -673,7 +687,7 @@ namespace ArchiSteamFarm { return null; } - if (!IsMaster(steamID)) { + if (!IsMaster(steamID) && !SteamFamilySharingIDs.Contains(steamID)) { return null; } @@ -2000,6 +2014,8 @@ namespace ArchiSteamFarm { } } + InitializeFamilySharing().Forget(); + if (BotConfig.DismissInventoryNotifications) { ArchiWebHandler.MarkInventory().Forget(); }