summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/Philipp15b/go-steam/notifications.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-06-22 01:00:27 +0200
committerWim <wim@42.be>2017-06-22 01:00:27 +0200
commit1f914618538920db4bfec7b106ee97038b157c9b (patch)
tree6bd0ab107fe1673dbacdf9dfd10004289cd7bfab /vendor/github.com/Philipp15b/go-steam/notifications.go
parent1f9874102aaca09ce5e0289beff376c307b8c57b (diff)
downloadmatterbridge-msglm-1f914618538920db4bfec7b106ee97038b157c9b.tar.gz
matterbridge-msglm-1f914618538920db4bfec7b106ee97038b157c9b.tar.bz2
matterbridge-msglm-1f914618538920db4bfec7b106ee97038b157c9b.zip
Add vendor (steam)
Diffstat (limited to 'vendor/github.com/Philipp15b/go-steam/notifications.go')
-rw-r--r--vendor/github.com/Philipp15b/go-steam/notifications.go62
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})
+ }
+ }
+}