Skip to content

Commit

Permalink
Rename notifications body
Browse files Browse the repository at this point in the history
Try to stick with Valve's naming for this one.
  • Loading branch information
JustArchi committed Dec 1, 2017
1 parent 97c1a7a commit b6da399
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 108 deletions.
138 changes: 69 additions & 69 deletions ArchiSteamFarm/ArchiHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private void HandleItemAnnouncements(IPacketMsg packetMsg) {
}

ClientMsgProtobuf<CMsgClientItemAnnouncements> response = new ClientMsgProtobuf<CMsgClientItemAnnouncements>(packetMsg);
Client.PostCallback(new NotificationsCallback(packetMsg.TargetJobID, response.Body));
Client.PostCallback(new UserNotificationsCallback(packetMsg.TargetJobID, response.Body));
}

private void HandlePlayingSessionState(IPacketMsg packetMsg) {
Expand Down Expand Up @@ -250,74 +250,7 @@ private void HandleUserNotifications(IPacketMsg packetMsg) {
}

ClientMsgProtobuf<CMsgClientUserNotifications> response = new ClientMsgProtobuf<CMsgClientUserNotifications>(packetMsg);
Client.PostCallback(new NotificationsCallback(packetMsg.TargetJobID, response.Body));
}

internal sealed class NotificationsCallback : CallbackMsg {
internal readonly Dictionary<ENotification, uint> 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<ENotification, uint>(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<ENotification, uint>(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 {
Expand Down Expand Up @@ -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<EUserNotification, uint> 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<EUserNotification, uint>(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<EUserNotification, uint>(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
}
}
}
}
78 changes: 39 additions & 39 deletions ArchiSteamFarm/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ private Bot(string botName) {
CallbackManager.Subscribe<SteamUser.LoginKeyCallback>(OnLoginKey);
CallbackManager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);

CallbackManager.Subscribe<ArchiHandler.NotificationsCallback>(OnNotifications);
CallbackManager.Subscribe<ArchiHandler.OfflineMessageCallback>(OnOfflineMessage);
CallbackManager.Subscribe<ArchiHandler.PlayingSessionStateCallback>(OnPlayingSessionState);
CallbackManager.Subscribe<ArchiHandler.SharedLibraryLockStatusCallback>(OnSharedLibraryLockStatus);
CallbackManager.Subscribe<ArchiHandler.UserNotificationsCallback>(OnUserNotifications);

ArchiWebHandler = new ArchiWebHandler(this);
CardsFarmer = new CardsFarmer(this);
Expand Down Expand Up @@ -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<ArchiHandler.NotificationsCallback.ENotification, uint> 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));
Expand Down Expand Up @@ -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<ArchiHandler.UserNotificationsCallback.EUserNotification, uint> 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;
Expand Down

0 comments on commit b6da399

Please sign in to comment.