diff --git a/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MobileAuthenticatorHandler.cs b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MobileAuthenticatorHandler.cs index 54c860146..aa7dfdf97 100644 --- a/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MobileAuthenticatorHandler.cs +++ b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MobileAuthenticatorHandler.cs @@ -32,14 +32,14 @@ namespace ArchiSteamFarm.OfficialPlugins.MobileAuthenticator; internal sealed class MobileAuthenticatorHandler : ClientMsgHandler { private readonly ArchiLogger ArchiLogger; - private readonly SteamUnifiedMessages.UnifiedService UnifiedTwoFactorService; + private readonly TwoFactor UnifiedTwoFactorService; internal MobileAuthenticatorHandler(ArchiLogger archiLogger, SteamUnifiedMessages steamUnifiedMessages) { ArgumentNullException.ThrowIfNull(archiLogger); ArgumentNullException.ThrowIfNull(steamUnifiedMessages); ArchiLogger = archiLogger; - UnifiedTwoFactorService = steamUnifiedMessages.CreateService(); + UnifiedTwoFactorService = steamUnifiedMessages.CreateService(); } public override void HandleMsg(IPacketMsg packetMsg) => ArgumentNullException.ThrowIfNull(packetMsg); @@ -66,23 +66,17 @@ internal sealed class MobileAuthenticatorHandler : ClientMsgHandler { steamid = steamID }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedTwoFactorService.SendMessage(x => x.AddAuthenticator(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedTwoFactorService.AddAuthenticator(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); return null; } - if (response.Result != EResult.OK) { - return null; - } - - CTwoFactor_AddAuthenticator_Response body = response.GetDeserializedResponse(); - - return body; + return response.Result == EResult.OK ? response.Body : null; } internal async Task FinalizeAuthenticator(ulong steamID, string activationCode, string authenticatorCode, ulong authenticatorTime) { @@ -109,22 +103,16 @@ internal sealed class MobileAuthenticatorHandler : ClientMsgHandler { steamid = steamID }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedTwoFactorService.SendMessage(x => x.FinalizeAddAuthenticator(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedTwoFactorService.FinalizeAddAuthenticator(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); return null; } - if (response.Result != EResult.OK) { - return null; - } - - CTwoFactor_FinalizeAddAuthenticator_Response body = response.GetDeserializedResponse(); - - return body; + return response.Result == EResult.OK ? response.Body : null; } } diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index 687eae0b9..4efb3e6f0 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -383,8 +383,6 @@ public sealed class Bot : IAsyncDisposable, IDisposable { CallbackManager.Subscribe(OnFriendsList); CallbackManager.Subscribe(OnPersonaState); - CallbackManager.Subscribe(OnServiceMethod); - SteamUser = SteamClient.GetHandler() ?? throw new InvalidOperationException(nameof(SteamUser)); CallbackManager.Subscribe(OnLoggedOff); CallbackManager.Subscribe(OnLoggedOn); @@ -395,6 +393,9 @@ public sealed class Bot : IAsyncDisposable, IDisposable { CallbackManager.Subscribe(OnSharedLibraryLockStatus); CallbackManager.Subscribe(OnUserNotifications); + CallbackManager.SubscribeServiceNotification(OnIncomingChatMessage); + CallbackManager.SubscribeServiceNotification(OnIncomingMessage); + Actions = new Actions(this); CardsFarmer = new CardsFarmer(this); Commands = new Commands(this); @@ -3041,100 +3042,100 @@ public sealed class Bot : IAsyncDisposable, IDisposable { await Actions.AcceptGuestPasses(guestPassIDs).ConfigureAwait(false); } - private async Task OnIncomingChatMessage(CChatRoom_IncomingChatMessage_Notification notification) { + private async void OnIncomingChatMessage(SteamUnifiedMessages.ServiceMethodNotification notification) { ArgumentNullException.ThrowIfNull(notification); - if (notification.chat_group_id == 0) { - ArchiLogger.LogNullError(notification.chat_group_id); + if (notification.Body.chat_group_id == 0) { + ArchiLogger.LogNullError(notification.Body.chat_group_id); return; } - if (notification.chat_id == 0) { - ArchiLogger.LogNullError(notification.chat_id); + if (notification.Body.chat_id == 0) { + ArchiLogger.LogNullError(notification.Body.chat_id); return; } - if (notification.steamid_sender == 0) { - ArchiLogger.LogNullError(notification.steamid_sender); + if (notification.Body.steamid_sender == 0) { + ArchiLogger.LogNullError(notification.Body.steamid_sender); return; } // Under normal circumstances, timestamp must always be greater than 0, but Steam already proved that it's capable of going against the logic - if ((notification.steamid_sender != SteamID) && (notification.timestamp > 0)) { - if (ShouldAckChatMessage(notification.steamid_sender)) { - Utilities.InBackground(() => ArchiHandler.AckChatMessage(notification.chat_group_id, notification.chat_id, notification.timestamp)); + if ((notification.Body.steamid_sender != SteamID) && (notification.Body.timestamp > 0)) { + if (ShouldAckChatMessage(notification.Body.steamid_sender)) { + Utilities.InBackground(() => ArchiHandler.AckChatMessage(notification.Body.chat_group_id, notification.Body.chat_id, notification.Body.timestamp)); } } string message; // Prefer to use message without bbcode, but only if it's available - if (!string.IsNullOrEmpty(notification.message_no_bbcode)) { - message = notification.message_no_bbcode; - } else if (!string.IsNullOrEmpty(notification.message)) { - message = SteamChatMessage.Unescape(notification.message); + if (!string.IsNullOrEmpty(notification.Body.message_no_bbcode)) { + message = notification.Body.message_no_bbcode; + } else if (!string.IsNullOrEmpty(notification.Body.message)) { + message = SteamChatMessage.Unescape(notification.Body.message); } else { return; } - ArchiLogger.LogChatMessage(false, message, notification.chat_group_id, notification.chat_id, notification.steamid_sender); + ArchiLogger.LogChatMessage(false, message, notification.Body.chat_group_id, notification.Body.chat_id, notification.Body.steamid_sender); // Steam network broadcasts chat events also when we don't explicitly sign into Steam community // We'll explicitly ignore those messages when using offline mode, as it was done in the first version of Steam chat when no messages were broadcasted at all before signing in // Handling messages will still work correctly in invisible mode, which is how it should work in the first place // This goes in addition to usual logic that ignores irrelevant messages from being parsed further - if ((notification.chat_group_id != MasterChatGroupID) || (BotConfig.OnlineStatus == EPersonaState.Offline)) { + if ((notification.Body.chat_group_id != MasterChatGroupID) || (BotConfig.OnlineStatus == EPersonaState.Offline)) { return; } - await Commands.HandleMessage(notification.chat_group_id, notification.chat_id, notification.steamid_sender, message).ConfigureAwait(false); + await Commands.HandleMessage(notification.Body.chat_group_id, notification.Body.chat_id, notification.Body.steamid_sender, message).ConfigureAwait(false); } - private async Task OnIncomingMessage(CFriendMessages_IncomingMessage_Notification notification) { + private async void OnIncomingMessage(SteamUnifiedMessages.ServiceMethodNotification notification) { ArgumentNullException.ThrowIfNull(notification); - if (notification.steamid_friend == 0) { - ArchiLogger.LogNullError(notification.steamid_friend); + if (notification.Body.steamid_friend == 0) { + ArchiLogger.LogNullError(notification.Body.steamid_friend); return; } - if ((EChatEntryType) notification.chat_entry_type != EChatEntryType.ChatMsg) { + if ((EChatEntryType) notification.Body.chat_entry_type != EChatEntryType.ChatMsg) { return; } // Under normal circumstances, timestamp must always be greater than 0, but Steam already proved that it's capable of going against the logic - if (notification is { local_echo: false, rtime32_server_timestamp: > 0 }) { - if (ShouldAckChatMessage(notification.steamid_friend)) { - Utilities.InBackground(() => ArchiHandler.AckMessage(notification.steamid_friend, notification.rtime32_server_timestamp)); + if (notification.Body is { local_echo: false, rtime32_server_timestamp: > 0 }) { + if (ShouldAckChatMessage(notification.Body.steamid_friend)) { + Utilities.InBackground(() => ArchiHandler.AckMessage(notification.Body.steamid_friend, notification.Body.rtime32_server_timestamp)); } } string message; // Prefer to use message without bbcode, but only if it's available - if (!string.IsNullOrEmpty(notification.message_no_bbcode)) { - message = notification.message_no_bbcode; - } else if (!string.IsNullOrEmpty(notification.message)) { - message = SteamChatMessage.Unescape(notification.message); + if (!string.IsNullOrEmpty(notification.Body.message_no_bbcode)) { + message = notification.Body.message_no_bbcode; + } else if (!string.IsNullOrEmpty(notification.Body.message)) { + message = SteamChatMessage.Unescape(notification.Body.message); } else { return; } - ArchiLogger.LogChatMessage(notification.local_echo, message, steamID: notification.steamid_friend); + ArchiLogger.LogChatMessage(notification.Body.local_echo, message, steamID: notification.Body.steamid_friend); // Steam network broadcasts chat events also when we don't explicitly sign into Steam community // We'll explicitly ignore those messages when using offline mode, as it was done in the first version of Steam chat when no messages were broadcasted at all before signing in // Handling messages will still work correctly in invisible mode, which is how it should work in the first place // This goes in addition to usual logic that ignores irrelevant messages from being parsed further - if (notification.local_echo || (BotConfig.OnlineStatus == EPersonaState.Offline)) { + if (notification.Body.local_echo || (BotConfig.OnlineStatus == EPersonaState.Offline)) { return; } - await Commands.HandleMessage(notification.steamid_friend, message).ConfigureAwait(false); + await Commands.HandleMessage(notification.Body.steamid_friend, message).ConfigureAwait(false); } private void OnInventoryChanged() { @@ -3466,21 +3467,6 @@ public sealed class Bot : IAsyncDisposable, IDisposable { private async void OnSendItemsTimer(object? state = null) => await Actions.SendInventory(filterFunction: item => BotConfig.LootableTypes.Contains(item.Type)).ConfigureAwait(false); - private async void OnServiceMethod(SteamUnifiedMessages.ServiceMethodNotification notification) { - ArgumentNullException.ThrowIfNull(notification); - - switch (notification.MethodName) { - case "ChatRoomClient.NotifyIncomingChatMessage#1": - await OnIncomingChatMessage((CChatRoom_IncomingChatMessage_Notification) notification.Body).ConfigureAwait(false); - - break; - case "FriendMessagesClient.IncomingMessage#1": - await OnIncomingMessage((CFriendMessages_IncomingMessage_Notification) notification.Body).ConfigureAwait(false); - - break; - } - } - private async void OnSharedLibraryLockStatus(SharedLibraryLockStatusCallback callback) { ArgumentNullException.ThrowIfNull(callback); diff --git a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs index f4787fba8..de50f36f8 100644 --- a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs +++ b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs @@ -54,17 +54,17 @@ public sealed class ArchiHandler : ClientMsgHandler { private readonly ArchiLogger ArchiLogger; - private readonly SteamUnifiedMessages.UnifiedService UnifiedAccountPrivateApps; - private readonly SteamUnifiedMessages.UnifiedService UnifiedChatRoomService; - 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 UnifiedLoyaltyRewards; - private readonly SteamUnifiedMessages.UnifiedService UnifiedPlayerService; - private readonly SteamUnifiedMessages.UnifiedService UnifiedStoreService; - private readonly SteamUnifiedMessages.UnifiedService UnifiedTwoFactorService; + private readonly AccountPrivateApps UnifiedAccountPrivateApps; + private readonly ChatRoom UnifiedChatRoomService; + private readonly ClanChatRooms UnifiedClanChatRoomsService; + private readonly Credentials UnifiedCredentialsService; + private readonly Econ UnifiedEconService; + private readonly FamilyGroups UnifiedFamilyGroups; + private readonly FriendMessages UnifiedFriendMessagesService; + private readonly LoyaltyRewards UnifiedLoyaltyRewards; + private readonly Player UnifiedPlayerService; + private readonly Store UnifiedStoreService; + private readonly TwoFactor UnifiedTwoFactorService; internal DateTime LastPacketReceived { get; private set; } @@ -74,17 +74,17 @@ public sealed class ArchiHandler : ClientMsgHandler { ArchiLogger = archiLogger; - UnifiedAccountPrivateApps = steamUnifiedMessages.CreateService(); - UnifiedChatRoomService = steamUnifiedMessages.CreateService(); - UnifiedClanChatRoomsService = steamUnifiedMessages.CreateService(); - UnifiedCredentialsService = steamUnifiedMessages.CreateService(); - UnifiedEconService = steamUnifiedMessages.CreateService(); - UnifiedFamilyGroups = steamUnifiedMessages.CreateService(); - UnifiedFriendMessagesService = steamUnifiedMessages.CreateService(); - UnifiedLoyaltyRewards = steamUnifiedMessages.CreateService(); - UnifiedPlayerService = steamUnifiedMessages.CreateService(); - UnifiedStoreService = steamUnifiedMessages.CreateService(); - UnifiedTwoFactorService = steamUnifiedMessages.CreateService(); + UnifiedAccountPrivateApps = steamUnifiedMessages.CreateService(); + UnifiedChatRoomService = steamUnifiedMessages.CreateService(); + UnifiedClanChatRoomsService = steamUnifiedMessages.CreateService(); + UnifiedCredentialsService = steamUnifiedMessages.CreateService(); + UnifiedEconService = steamUnifiedMessages.CreateService(); + UnifiedFamilyGroups = steamUnifiedMessages.CreateService(); + UnifiedFriendMessagesService = steamUnifiedMessages.CreateService(); + UnifiedLoyaltyRewards = steamUnifiedMessages.CreateService(); + UnifiedPlayerService = steamUnifiedMessages.CreateService(); + UnifiedStoreService = steamUnifiedMessages.CreateService(); + UnifiedTwoFactorService = steamUnifiedMessages.CreateService(); } [PublicAPI] @@ -103,10 +103,10 @@ public sealed class ArchiHandler : ClientMsgHandler { CPlayer_AddFriend_Request request = new() { steamid = steamID }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedPlayerService.SendMessage(x => x.AddFriend(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedPlayerService.AddFriend(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); @@ -135,17 +135,17 @@ public sealed class ArchiHandler : ClientMsgHandler { steamid = steamID }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedClanChatRoomsService.SendMessage(x => x.GetClanChatRoomInfo(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedClanChatRoomsService.GetClanChatRoomInfo(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); return null; } - return response.Result == EResult.OK ? response.GetDeserializedResponse() : null; + return response.Result == EResult.OK ? response.Body : null; } [PublicAPI] @@ -160,17 +160,17 @@ public sealed class ArchiHandler : ClientMsgHandler { CCredentials_LastCredentialChangeTime_Request request = new(); - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedCredentialsService.SendMessage(x => x.GetCredentialChangeTimeDetails(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedCredentialsService.GetCredentialChangeTimeDetails(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); return null; } - return response.Result == EResult.OK ? response.GetDeserializedResponse() : null; + return response.Result == EResult.OK ? response.Body : null; } [PublicAPI] @@ -209,16 +209,16 @@ public sealed class ArchiHandler : ClientMsgHandler { Dictionary<(ulong ClassID, ulong InstanceID), InventoryDescription>? descriptions = null; while (true) { - SteamUnifiedMessages.ServiceMethodResponse? serviceMethodResponse = null; + SteamUnifiedMessages.ServiceMethodResponse? response = null; - for (byte i = 0; (i < WebBrowser.MaxTries) && (serviceMethodResponse?.Result != EResult.OK) && Client.IsConnected && (Client.SteamID != null); i++) { + for (byte i = 0; (i < WebBrowser.MaxTries) && (response?.Result != EResult.OK) && Client.IsConnected && (Client.SteamID != null); i++) { if (i > 0) { // It seems 2 seconds is enough to win over DuplicateRequest, so we'll use that for this and also other network-related failures await Task.Delay(2000).ConfigureAwait(false); } try { - serviceMethodResponse = await UnifiedEconService.SendMessage(x => x.GetInventoryItemsWithDescriptions(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedEconService.GetInventoryItemsWithDescriptions(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); @@ -226,7 +226,7 @@ public sealed class ArchiHandler : ClientMsgHandler { } // Interpret the result and see what we should do about it - switch (serviceMethodResponse.Result) { + switch (response.Result) { case EResult.OK: // Success, we can continue break; @@ -240,39 +240,37 @@ public sealed class ArchiHandler : ClientMsgHandler { continue; case EResult.NoMatch: // Expected failures that we're not going to retry - throw new TimeoutException(Strings.FormatWarningFailedWithError(serviceMethodResponse.Result)); + throw new TimeoutException(Strings.FormatWarningFailedWithError(response.Result)); default: // Unknown failures, report them and do not retry since we're unsure if we should - ArchiLogger.LogGenericError(Strings.FormatWarningUnknownValuePleaseReport(nameof(serviceMethodResponse.Result), serviceMethodResponse.Result)); + ArchiLogger.LogGenericError(Strings.FormatWarningUnknownValuePleaseReport(nameof(response.Result), response.Result)); - throw new TimeoutException(Strings.FormatWarningFailedWithError(serviceMethodResponse.Result)); + throw new TimeoutException(Strings.FormatWarningFailedWithError(response.Result)); } } - if (serviceMethodResponse == null) { - throw new TimeoutException(Strings.FormatErrorObjectIsNull(nameof(serviceMethodResponse))); + if (response == null) { + throw new TimeoutException(Strings.FormatErrorObjectIsNull(nameof(response))); } - if (serviceMethodResponse.Result != EResult.OK) { - throw new TimeoutException(Strings.FormatWarningFailedWithError(serviceMethodResponse.Result)); + if (response.Result != EResult.OK) { + throw new TimeoutException(Strings.FormatWarningFailedWithError(response.Result)); } - CEcon_GetInventoryItemsWithDescriptions_Response response = serviceMethodResponse.GetDeserializedResponse(); - - if ((response.total_inventory_count == 0) || (response.assets.Count == 0)) { + if ((response.Body.total_inventory_count == 0) || (response.Body.assets.Count == 0)) { // Empty inventory yield break; } - if (response.descriptions.Count == 0) { - throw new InvalidOperationException(nameof(response.descriptions)); + if (response.Body.descriptions.Count == 0) { + throw new InvalidOperationException(nameof(response.Body.descriptions)); } - if (response.total_inventory_count > Array.MaxLength) { - throw new InvalidOperationException(nameof(response.total_inventory_count)); + if (response.Body.total_inventory_count > Array.MaxLength) { + throw new InvalidOperationException(nameof(response.Body.total_inventory_count)); } - assetIDs ??= new HashSet((int) response.total_inventory_count); + assetIDs ??= new HashSet((int) response.Body.total_inventory_count); if (descriptions == null) { descriptions = new Dictionary<(ulong ClassID, ulong InstanceID), InventoryDescription>(); @@ -281,7 +279,7 @@ public sealed class ArchiHandler : ClientMsgHandler { descriptions.Clear(); } - foreach (CEconItem_Description? description in response.descriptions) { + foreach (CEconItem_Description? description in response.Body.descriptions) { if (description.classid == 0) { throw new NotSupportedException(Strings.FormatErrorObjectIsNull(nameof(description.classid))); } @@ -295,7 +293,7 @@ public sealed class ArchiHandler : ClientMsgHandler { descriptions.Add(key, new InventoryDescription(description)); } - foreach (CEcon_Asset? asset in response.assets.Where(asset => assetIDs.Add(asset.assetid))) { + foreach (CEcon_Asset? asset in response.Body.assets.Where(asset => assetIDs.Add(asset.assetid))) { InventoryDescription? description = descriptions.GetValueOrDefault((asset.classid, asset.instanceid)); // Extra bulletproofing against Steam showing us middle finger @@ -306,15 +304,15 @@ public sealed class ArchiHandler : ClientMsgHandler { yield return new Asset(asset, description); } - if (!response.more_items) { + if (!response.Body.more_items) { yield break; } - if (response.last_assetid == 0) { - throw new NotSupportedException(Strings.FormatErrorObjectIsNull(nameof(response.last_assetid))); + if (response.Body.last_assetid == 0) { + throw new NotSupportedException(Strings.FormatErrorObjectIsNull(nameof(response.Body.last_assetid))); } - request.start_assetid = response.last_assetid; + request.start_assetid = response.Body.last_assetid; } } @@ -340,23 +338,17 @@ public sealed class ArchiHandler : ClientMsgHandler { skip_unvetted_apps = false }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedPlayerService.SendMessage(x => x.GetOwnedGames(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedPlayerService.GetOwnedGames(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); return null; } - if (response.Result != EResult.OK) { - return null; - } - - CPlayer_GetOwnedGames_Response body = response.GetDeserializedResponse(); - - return body.games.ToDictionary(static game => (uint) game.appid, static game => game.name); + return response.Result == EResult.OK ? response.Body.games.ToDictionary(static game => (uint) game.appid, static game => game.name) : null; } [PublicAPI] @@ -381,23 +373,17 @@ public sealed class ArchiHandler : ClientMsgHandler { CLoyaltyRewards_GetSummary_Request request = new() { steamid = steamID }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedLoyaltyRewards.SendMessage(x => x.GetSummary(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedLoyaltyRewards.GetSummary(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); return null; } - if (response.Result != EResult.OK) { - return null; - } - - CLoyaltyRewards_GetSummary_Response body = response.GetDeserializedResponse(); - - return body.summary?.points; + return response.Result == EResult.OK ? response.Body.summary?.points : null; } [PublicAPI] @@ -412,17 +398,17 @@ public sealed class ArchiHandler : ClientMsgHandler { CCredentials_GetSteamGuardDetails_Request request = new(); - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedCredentialsService.SendMessage(x => x.GetSteamGuardDetails(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedCredentialsService.GetSteamGuardDetails(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); return null; } - return response.Result == EResult.OK ? response.GetDeserializedResponse() : null; + return response.Result == EResult.OK ? response.Body : null; } [PublicAPI] @@ -437,23 +423,17 @@ public sealed class ArchiHandler : ClientMsgHandler { CEcon_GetTradeOfferAccessToken_Request request = new(); - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedEconService.SendMessage(x => x.GetTradeOfferAccessToken(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedEconService.GetTradeOfferAccessToken(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); return null; } - if (response.Result != EResult.OK) { - return null; - } - - CEcon_GetTradeOfferAccessToken_Response body = response.GetDeserializedResponse(); - - return body.trade_offer_access_token; + return response.Result == EResult.OK ? response.Body.trade_offer_access_token : null; } public override void HandleMsg(IPacketMsg packetMsg) { @@ -503,10 +483,10 @@ public sealed class ArchiHandler : ClientMsgHandler { CChatRoom_JoinChatRoomGroup_Request request = new() { chat_group_id = chatGroupID }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedChatRoomService.SendMessage(x => x.JoinChatRoomGroup(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedChatRoomService.JoinChatRoomGroup(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); @@ -530,10 +510,10 @@ public sealed class ArchiHandler : ClientMsgHandler { CChatRoom_LeaveChatRoomGroup_Request request = new() { chat_group_id = chatGroupID }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedChatRoomService.SendMessage(x => x.LeaveChatRoomGroup(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedChatRoomService.LeaveChatRoomGroup(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); @@ -559,10 +539,10 @@ public sealed class ArchiHandler : ClientMsgHandler { defid = definitionID }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedLoyaltyRewards.SendMessage(x => x.RedeemPoints(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedLoyaltyRewards.RedeemPoints(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); @@ -588,10 +568,10 @@ public sealed class ArchiHandler : ClientMsgHandler { CPlayer_RemoveFriend_Request request = new() { steamid = steamID }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedPlayerService.SendMessage(x => x.RemoveFriend(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedPlayerService.RemoveFriend(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); @@ -620,7 +600,7 @@ public sealed class ArchiHandler : ClientMsgHandler { timestamp = timestamp }; - UnifiedChatRoomService.SendNotification(x => x.AckChatMessage(request)); + UnifiedChatRoomService.AckChatMessage(request); } internal void AckMessage(ulong steamID, uint timestamp) { @@ -643,7 +623,7 @@ public sealed class ArchiHandler : ClientMsgHandler { timestamp = timestamp }; - UnifiedFriendMessagesService.SendNotification(x => x.AckMessage(request)); + UnifiedFriendMessagesService.AckMessage(request); } internal void AcknowledgeClanInvite(ulong steamID, bool acceptInvite) { @@ -689,10 +669,10 @@ public sealed class ArchiHandler : ClientMsgHandler { steamid = steamID }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedFamilyGroups.SendMessage(x => x.GetFamilyGroupForUser(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedFamilyGroups.GetFamilyGroupForUser(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); @@ -703,9 +683,7 @@ public sealed class ArchiHandler : ClientMsgHandler { return null; } - CFamilyGroups_GetFamilyGroupForUser_Response body = response.GetDeserializedResponse(); - - return body.family_group?.members.Where(member => member.steamid != steamID).Select(static member => member.steamid).ToHashSet() ?? []; + return response.Body.family_group?.members.Where(member => member.steamid != steamID).Select(static member => member.steamid).ToHashSet() ?? []; } internal async Task GetLevel() { @@ -718,10 +696,11 @@ public sealed class ArchiHandler : ClientMsgHandler { } CPlayer_GetGameBadgeLevels_Request request = new(); - SteamUnifiedMessages.ServiceMethodResponse response; + + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedPlayerService.SendMessage(x => x.GetGameBadgeLevels(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedPlayerService.GetGameBadgeLevels(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); @@ -732,9 +711,7 @@ public sealed class ArchiHandler : ClientMsgHandler { return null; } - CPlayer_GetGameBadgeLevels_Response body = response.GetDeserializedResponse(); - - return body.player_level; + return response.Body.player_level; } internal async Task?> GetMyChatGroupIDs() { @@ -748,23 +725,17 @@ public sealed class ArchiHandler : ClientMsgHandler { CChatRoom_GetMyChatRoomGroups_Request request = new(); - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedChatRoomService.SendMessage(x => x.GetMyChatRoomGroups(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedChatRoomService.GetMyChatRoomGroups(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); return null; } - if (response.Result != EResult.OK) { - return null; - } - - CChatRoom_GetMyChatRoomGroups_Response body = response.GetDeserializedResponse(); - - return body.chat_room_groups.Select(static chatRoom => chatRoom.group_summary.chat_group_id).ToHashSet(); + return response.Result == EResult.OK ? response.Body.chat_room_groups.Select(static chatRoom => chatRoom.group_summary.chat_group_id).ToHashSet() : null; } internal async Task GetPrivacySettings() { @@ -778,23 +749,17 @@ public sealed class ArchiHandler : ClientMsgHandler { CPlayer_GetPrivacySettings_Request request = new(); - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedPlayerService.SendMessage(x => x.GetPrivacySettings(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedPlayerService.GetPrivacySettings(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); return null; } - if (response.Result != EResult.OK) { - return null; - } - - CPlayer_GetPrivacySettings_Response body = response.GetDeserializedResponse(); - - return body.privacy_settings; + return response.Result == EResult.OK ? response.Body.privacy_settings : null; } internal async Task?> GetPrivateAppIDs() { @@ -808,23 +773,17 @@ public sealed class ArchiHandler : ClientMsgHandler { CAccountPrivateApps_GetPrivateAppList_Request request = new(); - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedAccountPrivateApps.SendMessage(x => x.GetPrivateAppList(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedAccountPrivateApps.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(); + return response.Result == EResult.OK ? response.Body.private_apps.appids.Select(static appID => (uint) appID).ToHashSet() : null; } internal async Task GetServerTime() { @@ -838,23 +797,17 @@ public sealed class ArchiHandler : ClientMsgHandler { CTwoFactor_Time_Request request = new(); - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedTwoFactorService.SendMessage(x => x.QueryTime(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedTwoFactorService.QueryTime(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); return 0; } - if (response.Result != EResult.OK) { - return 0; - } - - CTwoFactor_Time_Response body = response.GetDeserializedResponse(); - - return body.server_time; + return response.Result == EResult.OK ? response.Body.server_time : 0; } internal async Task GetTwoFactorDeviceIdentifier(ulong steamID) { @@ -874,23 +827,17 @@ public sealed class ArchiHandler : ClientMsgHandler { steamid = steamID }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedTwoFactorService.SendMessage(x => x.QueryStatus(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedTwoFactorService.QueryStatus(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); return null; } - if (response.Result != EResult.OK) { - return null; - } - - CTwoFactor_Status_Response body = response.GetDeserializedResponse(); - - return body.device_identifier; + return response.Result == EResult.OK ? response.Body.device_identifier : null; } internal async Task PlayGames(IReadOnlyCollection gameIDs, string? gameName = null) { @@ -994,18 +941,18 @@ public sealed class ArchiHandler : ClientMsgHandler { is_request_from_client = true }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedStoreService.SendMessage(x => x.RegisterCDKey(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedStoreService.RegisterCDKey(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); return null; } - // We want to deserialize the response even with failed EResult - return response.GetDeserializedResponse(); + // We want to return the response even with failed EResult + return response.Body; } internal void RequestItemAnnouncements() { @@ -1043,10 +990,10 @@ public sealed class ArchiHandler : ClientMsgHandler { steamid = steamID }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedFriendMessagesService.SendMessage(x => x.SendMessage(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedFriendMessagesService.SendMessage(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); @@ -1075,10 +1022,10 @@ public sealed class ArchiHandler : ClientMsgHandler { message = message }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedChatRoomService.SendMessage(x => x.SendChatMessage(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedChatRoomService.SendChatMessage(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); @@ -1106,10 +1053,10 @@ public sealed class ArchiHandler : ClientMsgHandler { steamid = steamID }; - SteamUnifiedMessages.ServiceMethodResponse response; + SteamUnifiedMessages.ServiceMethodResponse response; try { - response = await UnifiedFriendMessagesService.SendMessage(x => x.SendMessage(request)).ToLongRunningTask().ConfigureAwait(false); + response = await UnifiedFriendMessagesService.SendMessage(request).ToLongRunningTask().ConfigureAwait(false); } catch (Exception e) { ArchiLogger.LogGenericWarningException(e); diff --git a/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs b/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs index 6d9cf0604..e67b0fc30 100644 --- a/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs +++ b/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs @@ -34,6 +34,9 @@ using SteamKit2.Discovery; namespace ArchiSteamFarm.Steam.SteamKit2; internal sealed class InMemoryServerListProvider : IServerListProvider { + // TODO + public DateTime LastServerListRefresh => DateTime.MinValue; + [JsonDisallowNull] [JsonInclude] private ConcurrentHashSet ServerRecords { get; init; } = []; diff --git a/Directory.Packages.props b/Directory.Packages.props index eddb6a904..845f39b82 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -15,7 +15,7 @@ - +