diff options
Diffstat (limited to 'vendor/github.com/Philipp15b/go-steam/notifications.go')
-rw-r--r-- | vendor/github.com/Philipp15b/go-steam/notifications.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/vendor/github.com/Philipp15b/go-steam/notifications.go b/vendor/github.com/Philipp15b/go-steam/notifications.go new file mode 100644 index 00000000..09969055 --- /dev/null +++ b/vendor/github.com/Philipp15b/go-steam/notifications.go @@ -0,0 +1,62 @@ +package steam + +import ( + . "github.com/Philipp15b/go-steam/protocol" + . "github.com/Philipp15b/go-steam/protocol/protobuf" + . "github.com/Philipp15b/go-steam/protocol/steamlang" +) + +type Notifications struct { + // Maps notification types to their count. If a type is not present in the map, + // its count is zero. + notifications map[NotificationType]uint + client *Client +} + +func newNotifications(client *Client) *Notifications { + return &Notifications{ + make(map[NotificationType]uint), + client, + } +} + +func (n *Notifications) HandlePacket(packet *Packet) { + switch packet.EMsg { + case EMsg_ClientUserNotifications: + n.handleClientUserNotifications(packet) + } +} + +type NotificationType uint + +const ( + TradeOffer NotificationType = 1 +) + +func (n *Notifications) handleClientUserNotifications(packet *Packet) { + msg := new(CMsgClientUserNotifications) + packet.ReadProtoMsg(msg) + + for _, notification := range msg.GetNotifications() { + typ := NotificationType(*notification.UserNotificationType) + count := uint(*notification.Count) + n.notifications[typ] = count + n.client.Emit(&NotificationEvent{typ, count}) + } + + // check if there is a notification in our map that isn't in the current packet + for typ, _ := range n.notifications { + exists := false + for _, t := range msg.GetNotifications() { + if NotificationType(*t.UserNotificationType) == typ { + exists = true + break + } + } + + if !exists { + delete(n.notifications, typ) + n.client.Emit(&NotificationEvent{typ, 0}) + } + } +} |