diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index 253d47dc4..194a634cd 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -2317,13 +2317,25 @@ public sealed class Bot : IAsyncDisposable, IDisposable { } private async Task InitializeFamilySharing() { - HashSet? steamIDs = await ArchiWebHandler.GetFamilySharingSteamIDs().ConfigureAwait(false); + // TODO: Old call should be removed eventually when Steam stops supporting both systems at once + Task?> oldFamilySharingSteamIDsTask = ArchiWebHandler.GetFamilySharingSteamIDs(); - if (steamIDs == null) { + HashSet? steamIDs = await ArchiHandler.GetFamilyGroupSteamIDs().ConfigureAwait(false); + HashSet? oldSteamIDs = await oldFamilySharingSteamIDsTask.ConfigureAwait(false); + + if ((steamIDs == null) && (oldSteamIDs == null)) { return; } - SteamFamilySharingIDs.ReplaceWith(steamIDs); + SteamFamilySharingIDs.Clear(); + + if (steamIDs is { Count: > 0 }) { + SteamFamilySharingIDs.AddRange(steamIDs); + } + + if (oldSteamIDs is { Count: > 0 }) { + SteamFamilySharingIDs.AddRange(oldSteamIDs); + } } private async Task InitLoginAndPassword(bool requiresPassword) { diff --git a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs index 589da7dd1..b6c1a164a 100644 --- a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs +++ b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs @@ -60,6 +60,7 @@ public sealed class ArchiHandler : ClientMsgHandler { private readonly SteamUnifiedMessages.UnifiedService UnifiedClanChatRoomsService; private readonly SteamUnifiedMessages.UnifiedService UnifiedCredentialsService; private readonly SteamUnifiedMessages.UnifiedService UnifiedEconService; + private readonly SteamUnifiedMessages.UnifiedService UnifiedFamilyGroups; private readonly SteamUnifiedMessages.UnifiedService UnifiedFriendMessagesService; private readonly SteamUnifiedMessages.UnifiedService UnifiedPlayerService; private readonly SteamUnifiedMessages.UnifiedService UnifiedStoreService; @@ -78,6 +79,7 @@ public sealed class ArchiHandler : ClientMsgHandler { UnifiedClanChatRoomsService = steamUnifiedMessages.CreateService(); UnifiedCredentialsService = steamUnifiedMessages.CreateService(); UnifiedEconService = steamUnifiedMessages.CreateService(); + UnifiedFamilyGroups = steamUnifiedMessages.CreateService(); UnifiedFriendMessagesService = steamUnifiedMessages.CreateService(); UnifiedPlayerService = steamUnifiedMessages.CreateService(); UnifiedStoreService = steamUnifiedMessages.CreateService(); @@ -267,36 +269,6 @@ public sealed class ArchiHandler : ClientMsgHandler { } } - internal async Task?> GetPrivateAppIDs() { - if (Client == null) { - throw new InvalidOperationException(nameof(Client)); - } - - if (!Client.IsConnected) { - return null; - } - - CAccountPrivateApps_GetPrivateAppList_Request request = new(); - - SteamUnifiedMessages.ServiceMethodResponse response; - - try { - response = await UnifiedAccountPrivateApps.SendMessage(x => x.GetPrivateAppList(request)).ToLongRunningTask().ConfigureAwait(false); - } catch (Exception e) { - ArchiLogger.LogGenericWarningException(e); - - return null; - } - - if (response.Result != EResult.OK) { - return null; - } - - CAccountPrivateApps_GetPrivateAppList_Response body = response.GetDeserializedResponse(); - - return body.private_apps.appids.Select(static appID => (uint) appID).ToHashSet(); - } - [PublicAPI] public async Task?> GetOwnedGames(ulong steamID) { if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { @@ -578,6 +550,45 @@ public sealed class ArchiHandler : ClientMsgHandler { Client.Send(request); } + internal async Task?> GetFamilyGroupSteamIDs() { + if (Client == null) { + throw new InvalidOperationException(nameof(Client)); + } + + if (!Client.IsConnected) { + return null; + } + + if (Client.SteamID == null) { + throw new InvalidOperationException(nameof(Client.SteamID)); + } + + ulong steamID = Client.SteamID; + + CFamilyGroups_GetFamilyGroupForUser_Request request = new() { + include_family_group_response = true, + steamid = steamID + }; + + SteamUnifiedMessages.ServiceMethodResponse response; + + try { + response = await UnifiedFamilyGroups.SendMessage(x => x.GetFamilyGroupForUser(request)).ToLongRunningTask().ConfigureAwait(false); + } catch (Exception e) { + ArchiLogger.LogGenericWarningException(e); + + return null; + } + + if (response.Result != EResult.OK) { + return null; + } + + CFamilyGroups_GetFamilyGroupForUser_Response body = response.GetDeserializedResponse(); + + return body.family_group.members.Where(member => member.steamid != steamID).Select(static member => member.steamid).ToHashSet(); + } + internal async Task GetLevel() { if (Client == null) { throw new InvalidOperationException(nameof(Client)); @@ -667,6 +678,36 @@ public sealed class ArchiHandler : ClientMsgHandler { return body.privacy_settings; } + internal async Task?> GetPrivateAppIDs() { + if (Client == null) { + throw new InvalidOperationException(nameof(Client)); + } + + if (!Client.IsConnected) { + return null; + } + + CAccountPrivateApps_GetPrivateAppList_Request request = new(); + + SteamUnifiedMessages.ServiceMethodResponse response; + + try { + response = await UnifiedAccountPrivateApps.SendMessage(x => x.GetPrivateAppList(request)).ToLongRunningTask().ConfigureAwait(false); + } catch (Exception e) { + ArchiLogger.LogGenericWarningException(e); + + return null; + } + + if (response.Result != EResult.OK) { + return null; + } + + CAccountPrivateApps_GetPrivateAppList_Response body = response.GetDeserializedResponse(); + + return body.private_apps.appids.Select(static appID => (uint) appID).ToHashSet(); + } + internal async Task GetServerTime() { if (Client == null) { throw new InvalidOperationException(nameof(Client));