This commit is contained in:
Archi
2024-03-19 13:24:24 +01:00
parent 6f2fd4eccc
commit 0894eaee28
2 changed files with 86 additions and 33 deletions

View File

@@ -2317,13 +2317,25 @@ public sealed class Bot : IAsyncDisposable, IDisposable {
}
private async Task InitializeFamilySharing() {
HashSet<ulong>? steamIDs = await ArchiWebHandler.GetFamilySharingSteamIDs().ConfigureAwait(false);
// TODO: Old call should be removed eventually when Steam stops supporting both systems at once
Task<HashSet<ulong>?> oldFamilySharingSteamIDsTask = ArchiWebHandler.GetFamilySharingSteamIDs();
if (steamIDs == null) {
HashSet<ulong>? steamIDs = await ArchiHandler.GetFamilyGroupSteamIDs().ConfigureAwait(false);
HashSet<ulong>? 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<bool> InitLoginAndPassword(bool requiresPassword) {

View File

@@ -60,6 +60,7 @@ public sealed class ArchiHandler : ClientMsgHandler {
private readonly SteamUnifiedMessages.UnifiedService<IClanChatRooms> UnifiedClanChatRoomsService;
private readonly SteamUnifiedMessages.UnifiedService<ICredentials> UnifiedCredentialsService;
private readonly SteamUnifiedMessages.UnifiedService<IEcon> UnifiedEconService;
private readonly SteamUnifiedMessages.UnifiedService<IFamilyGroups> UnifiedFamilyGroups;
private readonly SteamUnifiedMessages.UnifiedService<IFriendMessages> UnifiedFriendMessagesService;
private readonly SteamUnifiedMessages.UnifiedService<IPlayer> UnifiedPlayerService;
private readonly SteamUnifiedMessages.UnifiedService<IStore> UnifiedStoreService;
@@ -78,6 +79,7 @@ public sealed class ArchiHandler : ClientMsgHandler {
UnifiedClanChatRoomsService = steamUnifiedMessages.CreateService<IClanChatRooms>();
UnifiedCredentialsService = steamUnifiedMessages.CreateService<ICredentials>();
UnifiedEconService = steamUnifiedMessages.CreateService<IEcon>();
UnifiedFamilyGroups = steamUnifiedMessages.CreateService<IFamilyGroups>();
UnifiedFriendMessagesService = steamUnifiedMessages.CreateService<IFriendMessages>();
UnifiedPlayerService = steamUnifiedMessages.CreateService<IPlayer>();
UnifiedStoreService = steamUnifiedMessages.CreateService<IStore>();
@@ -267,36 +269,6 @@ public sealed class ArchiHandler : ClientMsgHandler {
}
}
internal async Task<HashSet<uint>?> 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<CAccountPrivateApps_GetPrivateAppList_Response>();
return body.private_apps.appids.Select(static appID => (uint) appID).ToHashSet();
}
[PublicAPI]
public async Task<Dictionary<uint, string>?> 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<HashSet<ulong>?> 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<CFamilyGroups_GetFamilyGroupForUser_Response>();
return body.family_group.members.Where(member => member.steamid != steamID).Select(static member => member.steamid).ToHashSet();
}
internal async Task<uint?> 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<HashSet<uint>?> 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<CAccountPrivateApps_GetPrivateAppList_Response>();
return body.private_apps.appids.Select(static appID => (uint) appID).ToHashSet();
}
internal async Task<ulong> GetServerTime() {
if (Client == null) {
throw new InvalidOperationException(nameof(Client));