From b6da399c89ef99bc7000c57c21a7adf8a9d1666a Mon Sep 17 00:00:00 2001 From: JustArchi Date: Fri, 1 Dec 2017 01:36:58 +0100 Subject: [PATCH] Rename notifications body Try to stick with Valve's naming for this one. --- ArchiSteamFarm/ArchiHandler.cs | 138 ++++++++++++++++----------------- ArchiSteamFarm/Bot.cs | 78 +++++++++---------- 2 files changed, 108 insertions(+), 108 deletions(-) diff --git a/ArchiSteamFarm/ArchiHandler.cs b/ArchiSteamFarm/ArchiHandler.cs index 6777062a45440..48baa777b3c79 100644 --- a/ArchiSteamFarm/ArchiHandler.cs +++ b/ArchiSteamFarm/ArchiHandler.cs @@ -200,7 +200,7 @@ private void HandleItemAnnouncements(IPacketMsg packetMsg) { } ClientMsgProtobuf response = new ClientMsgProtobuf(packetMsg); - Client.PostCallback(new NotificationsCallback(packetMsg.TargetJobID, response.Body)); + Client.PostCallback(new UserNotificationsCallback(packetMsg.TargetJobID, response.Body)); } private void HandlePlayingSessionState(IPacketMsg packetMsg) { @@ -250,74 +250,7 @@ private void HandleUserNotifications(IPacketMsg packetMsg) { } ClientMsgProtobuf response = new ClientMsgProtobuf(packetMsg); - Client.PostCallback(new NotificationsCallback(packetMsg.TargetJobID, response.Body)); - } - - internal sealed class NotificationsCallback : CallbackMsg { - internal readonly Dictionary Notifications; - - internal NotificationsCallback(JobID jobID, CMsgClientUserNotifications msg) { - if ((jobID == null) || (msg == null)) { - throw new ArgumentNullException(nameof(jobID) + " || " + nameof(msg)); - } - - JobID = jobID; - - // We might get null body here, and that means there are no notifications related to trading - Notifications = new Dictionary(1) { { ENotification.Trading, 0 } }; - - if (msg.notifications == null) { - return; - } - - foreach (CMsgClientUserNotifications.Notification notification in msg.notifications) { - ENotification type = (ENotification) notification.user_notification_type; - - switch (type) { - case ENotification.AccountAlerts: - case ENotification.Chat: - case ENotification.Comments: - case ENotification.GameTurns: - case ENotification.Gifts: - case ENotification.HelpRequestReplies: - case ENotification.Invites: - case ENotification.Items: - case ENotification.ModeratorMessages: - case ENotification.Trading: - break; - default: - ASF.ArchiLogger.LogGenericWarning(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(type), type)); - continue; - } - - Notifications[type] = notification.count; - } - } - - internal NotificationsCallback(JobID jobID, CMsgClientItemAnnouncements msg) { - if ((jobID == null) || (msg == null)) { - throw new ArgumentNullException(nameof(jobID) + " || " + nameof(msg)); - } - - JobID = jobID; - Notifications = new Dictionary(1) { { ENotification.Items, msg.count_new_items } }; - } - - [SuppressMessage("ReSharper", "UnusedMember.Global")] - internal enum ENotification : byte { - Unknown, - Trading, - GameTurns, - ModeratorMessages, - Comments, - Items, - Invites, - Unknown7, // No clue what 7 stands for, and I doubt we can find out - Gifts, - Chat, - HelpRequestReplies, - AccountAlerts - } + Client.PostCallback(new UserNotificationsCallback(packetMsg.TargetJobID, response.Body)); } internal sealed class OfflineMessageCallback : CallbackMsg { @@ -442,5 +375,72 @@ internal SharedLibraryLockStatusCallback(JobID jobID, CMsgClientSharedLibraryLoc LibraryLockedBySteamID = new SteamID(msg.own_library_locked_by, EUniverse.Public, EAccountType.Individual); } } + + internal sealed class UserNotificationsCallback : CallbackMsg { + internal readonly Dictionary Notifications; + + internal UserNotificationsCallback(JobID jobID, CMsgClientUserNotifications msg) { + if ((jobID == null) || (msg == null)) { + throw new ArgumentNullException(nameof(jobID) + " || " + nameof(msg)); + } + + JobID = jobID; + + // We might get null body here, and that means there are no notifications related to trading + Notifications = new Dictionary(1) { { EUserNotification.Trading, 0 } }; + + if (msg.notifications == null) { + return; + } + + foreach (CMsgClientUserNotifications.Notification notification in msg.notifications) { + EUserNotification type = (EUserNotification) notification.user_notification_type; + + switch (type) { + case EUserNotification.AccountAlerts: + case EUserNotification.Chat: + case EUserNotification.Comments: + case EUserNotification.GameTurns: + case EUserNotification.Gifts: + case EUserNotification.HelpRequestReplies: + case EUserNotification.Invites: + case EUserNotification.Items: + case EUserNotification.ModeratorMessages: + case EUserNotification.Trading: + break; + default: + ASF.ArchiLogger.LogGenericWarning(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(type), type)); + continue; + } + + Notifications[type] = notification.count; + } + } + + internal UserNotificationsCallback(JobID jobID, CMsgClientItemAnnouncements msg) { + if ((jobID == null) || (msg == null)) { + throw new ArgumentNullException(nameof(jobID) + " || " + nameof(msg)); + } + + JobID = jobID; + Notifications = new Dictionary(1) { { EUserNotification.Items, msg.count_new_items } }; + } + + [SuppressMessage("ReSharper", "UnusedMember.Global")] + internal enum EUserNotification : byte { + Unknown, + Trading, + GameTurns, + ModeratorMessages, + Comments, + Items, + Invites, + Unknown7, // No clue what 7 stands for, and I doubt we can find out + Gifts, + Chat, + HelpRequestReplies, + AccountAlerts + } + } } } \ No newline at end of file diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 3549205a3db2f..fc71a408b5976 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -206,10 +206,10 @@ private Bot(string botName) { CallbackManager.Subscribe(OnLoginKey); CallbackManager.Subscribe(OnMachineAuth); - CallbackManager.Subscribe(OnNotifications); CallbackManager.Subscribe(OnOfflineMessage); CallbackManager.Subscribe(OnPlayingSessionState); CallbackManager.Subscribe(OnSharedLibraryLockStatus); + CallbackManager.Subscribe(OnUserNotifications); ArchiWebHandler = new ArchiWebHandler(this); CardsFarmer = new CardsFarmer(this); @@ -2037,44 +2037,6 @@ private void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback) { }); } - private void OnNotifications(ArchiHandler.NotificationsCallback callback) { - if (callback == null) { - ArchiLogger.LogNullError(nameof(callback)); - return; - } - - if ((callback.Notifications == null) || (callback.Notifications.Count == 0)) { - return; - } - - foreach (KeyValuePair notification in callback.Notifications) { - switch (notification.Key) { - case ArchiHandler.NotificationsCallback.ENotification.Items: - bool newItems = notification.Value > ItemsCount; - ItemsCount = notification.Value; - - if (newItems) { - CardsFarmer.OnNewItemsNotification().Forget(); - - if (BotConfig.DismissInventoryNotifications) { - ArchiWebHandler.MarkInventory().Forget(); - } - } - - break; - case ArchiHandler.NotificationsCallback.ENotification.Trading: - bool newTrades = notification.Value > TradesCount; - TradesCount = notification.Value; - - if (newTrades) { - Trading.OnNewTrade().Forget(); - } - - break; - } - } - } - private void OnOfflineMessage(ArchiHandler.OfflineMessageCallback callback) { if (callback?.Steam3IDs == null) { ArchiLogger.LogNullError(nameof(callback) + " || " + nameof(callback.Steam3IDs)); @@ -2146,6 +2108,44 @@ private async void OnSharedLibraryLockStatus(ArchiHandler.SharedLibraryLockStatu await CheckOccupationStatus().ConfigureAwait(false); } + private void OnUserNotifications(ArchiHandler.UserNotificationsCallback callback) { + if (callback == null) { + ArchiLogger.LogNullError(nameof(callback)); + return; + } + + if ((callback.Notifications == null) || (callback.Notifications.Count == 0)) { + return; + } + + foreach (KeyValuePair notification in callback.Notifications) { + switch (notification.Key) { + case ArchiHandler.UserNotificationsCallback.EUserNotification.Items: + bool newItems = notification.Value > ItemsCount; + ItemsCount = notification.Value; + + if (newItems) { + CardsFarmer.OnNewItemsNotification().Forget(); + + if (BotConfig.DismissInventoryNotifications) { + ArchiWebHandler.MarkInventory().Forget(); + } + } + + break; + case ArchiHandler.UserNotificationsCallback.EUserNotification.Trading: + bool newTrades = notification.Value > TradesCount; + TradesCount = notification.Value; + + if (newTrades) { + Trading.OnNewTrade().Forget(); + } + + break; + } + } + } + private async Task ResetGamesPlayed() { if (!IsPlayingPossible || (FamilySharingInactivityTimer != null) || CardsFarmer.NowFarming) { return;