forked from broderickhyman/albiondata-client
-
Notifications
You must be signed in to change notification settings - Fork 29
/
operation_read_mail.go
110 lines (86 loc) · 2.84 KB
/
operation_read_mail.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package client
import (
"strconv"
"strings"
"github.com/ao-data/albiondata-client/lib"
"github.com/ao-data/albiondata-client/log"
)
type operationReadMail struct {
ID int `mapstructure:"0"`
Body string `mapstructure:"1"`
}
func (op operationReadMail) Process(state *albionState) {
log.Debug("Got ReadMail operation...")
var notification lib.MarketNotification
// split the mail body
body := strings.Split(op.Body, "|")
mailInfo := MailInfos.getMailInfo(op.ID)
if mailInfo == nil {
log.Info("Mail Info is not valid. Please transition zones or click at notification, so the mails can be loaded.")
return
}
if mailInfo.OrderType == "MARKETPLACE_SELLORDER_FINISHED_SUMMARY" {
log.Debug("Read finished sell order.")
notification = decodeSellNotification(op, body)
} else if mailInfo.OrderType == "MARKETPLACE_SELLORDER_EXPIRED_SUMMARY" {
log.Debug("Read expired sell order.")
notification = decodeExpiryNotification(op, body)
}
if notification == nil {
return
}
upload := lib.MarketNotificationUpload{
Type: notification.Type(),
Notification: notification,
}
sendMsgToPrivateUploaders(&upload, lib.NatsMarketNotifications, state)
}
func decodeSellNotification(op operationReadMail, body []string) lib.MarketNotification {
notification := &lib.MarketSellNotification{}
notification.MailID = op.ID
amount, err := strconv.Atoi(body[0])
if err != nil {
log.Error("Could not parse amount in market sell notification ", err)
return nil
}
price, err := strconv.Atoi(body[3])
if err != nil {
log.Error("Could not parse price in market sell notification ", err)
return nil
}
notification.Amount = amount
notification.ItemID = body[1]
notification.Price = price / 10000
notification.TotalAfterTaxes = float32(float32(notification.Price) * float32(notification.Amount) * (1.0 - lib.SalesTax))
mailInfo := MailInfos.getMailInfo(op.ID)
notification.LocationID = mailInfo.LocationID
notification.Expires = mailInfo.StringExpires()
return notification
}
func decodeExpiryNotification(op operationReadMail, body []string) lib.MarketNotification {
notification := &lib.MarketExpiryNotification{}
notification.MailID = op.ID
sold, err := strconv.Atoi(body[0])
if err != nil {
log.Error("Could not parse amount in market sell notification ", err)
return nil
}
amount, err := strconv.Atoi(body[1])
if err != nil {
log.Error("Could not parse amount in market sell notification ", err)
return nil
}
price, err := strconv.Atoi(body[2])
if err != nil {
log.Error("Could not parse price in market sell notification ", err)
return nil
}
notification.Amount = amount
notification.ItemID = body[1]
notification.Price = price / 10000
notification.Sold = sold
mailInfo := MailInfos.getMailInfo(op.ID)
notification.LocationID = mailInfo.LocationID
notification.Expires = mailInfo.StringExpires()
return notification
}