save
This commit is contained in:
parent
cd30872b4a
commit
ba7a99d362
@ -31,9 +31,6 @@ func (api *MailApi) GetMailList(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, errorResponse(400, err))
|
c.JSON(http.StatusBadRequest, errorResponse(400, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accountObj.Mutex.Lock()
|
|
||||||
defer accountObj.Mutex.Unlock()
|
|
||||||
|
|
||||||
commonPlayer := (common.Player)(accountObj)
|
commonPlayer := (common.Player)(accountObj)
|
||||||
mails := GetMailMgr().GetMails(commonPlayer)
|
mails := GetMailMgr().GetMails(commonPlayer)
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
@ -68,8 +65,6 @@ func (api *MailApi) MarkMail(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, errorResponse(400, err))
|
c.JSON(http.StatusBadRequest, errorResponse(400, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accountObj.Mutex.Lock()
|
|
||||||
defer accountObj.Mutex.Unlock()
|
|
||||||
accountObj.MarkMail(req.MailIds)
|
accountObj.MarkMail(req.MailIds)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
@ -97,9 +92,6 @@ func (api *MailApi) GetUnreadMailCount(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, errorResponse(400, err))
|
c.JSON(http.StatusBadRequest, errorResponse(400, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accountObj.Mutex.Lock()
|
|
||||||
defer accountObj.Mutex.Unlock()
|
|
||||||
|
|
||||||
commonPlayer := (common.Player)(accountObj)
|
commonPlayer := (common.Player)(accountObj)
|
||||||
mailCount := GetMailMgr().GetUnreadMailCount(commonPlayer)
|
mailCount := GetMailMgr().GetUnreadMailCount(commonPlayer)
|
||||||
|
|
||||||
@ -130,8 +122,6 @@ func (api *MailApi) GetMailAttachment(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, errorResponse(400, err))
|
c.JSON(http.StatusBadRequest, errorResponse(400, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accountObj.Mutex.Lock()
|
|
||||||
defer accountObj.Mutex.Unlock()
|
|
||||||
att := accountObj.GetAttachment(req.MailIds)
|
att := accountObj.GetAttachment(req.MailIds)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
@ -161,8 +151,6 @@ func (api *MailApi) DeleteMails(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, errorResponse(400, err))
|
c.JSON(http.StatusBadRequest, errorResponse(400, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accountObj.Mutex.Lock()
|
|
||||||
defer accountObj.Mutex.Unlock()
|
|
||||||
accountObj.DeleteMails(req.MailIds)
|
accountObj.DeleteMails(req.MailIds)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
@ -8,27 +8,27 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Attachments struct {
|
type Attachment struct {
|
||||||
ItemId int `json:"itemid"`
|
ItemId int `json:"itemid"`
|
||||||
ItemNum int `json:"itemnum"`
|
ItemNum int `json:"itemnum"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mail struct {
|
type Mail struct {
|
||||||
GameId int `json:"-"`
|
GameId int `json:"-"`
|
||||||
MailId int64 `json:"mailid"`
|
MailId int64 `json:"mailid"`
|
||||||
From string `json:"from"`
|
From string `json:"from"`
|
||||||
To string `json:"to"`
|
To string `json:"to"`
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Flag int `json:"flags"`
|
Flag int `json:"flags"`
|
||||||
SendTime int32 `json:"sendtime"`
|
SendTime int32 `json:"sendtime"`
|
||||||
ExpireTime int32 `json:"expiretime"`
|
ExpireTime int32 `json:"expiretime"`
|
||||||
MailType int `json:"mailtype"`
|
MailType int `json:"mailtype"`
|
||||||
MailSubType int `json:"mailsubtype"`
|
MailSubType int `json:"mailsubtype"`
|
||||||
UserType int `json:"-"`
|
UserType int `json:"-"`
|
||||||
CreateTime int32 `json:"-"`
|
CreateTime int32 `json:"-"`
|
||||||
Ext string `json:"ext"`
|
Ext string `json:"ext"`
|
||||||
ATT []*Attachments `json:"attachments"`
|
ATT []*Attachment `json:"attachments"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mail) Init() {
|
func (m *Mail) Init() {
|
||||||
@ -46,7 +46,7 @@ func (m *Mail) ParseAttachments(attachmentsStr string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
attachmentStrList := strings.Split(attachmentsStr, "|")
|
attachmentStrList := strings.Split(attachmentsStr, "|")
|
||||||
m.ATT = make([]*Attachments, 0, len(attachmentStrList))
|
m.ATT = make([]*Attachment, 0, len(attachmentStrList))
|
||||||
for _, attachmentStr := range attachmentStrList {
|
for _, attachmentStr := range attachmentStrList {
|
||||||
if len(attachmentStr) <= 0 {
|
if len(attachmentStr) <= 0 {
|
||||||
continue
|
continue
|
||||||
@ -55,7 +55,7 @@ func (m *Mail) ParseAttachments(attachmentsStr string) {
|
|||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
attachment := &Attachments{
|
attachment := &Attachment{
|
||||||
ItemId: q5.ToInt(parts[0]),
|
ItemId: q5.ToInt(parts[0]),
|
||||||
ItemNum: q5.ToInt(parts[1]),
|
ItemNum: q5.ToInt(parts[1]),
|
||||||
}
|
}
|
||||||
|
@ -49,10 +49,20 @@ func (mm *MailMgr) GetMails(player common.Player) []*Mail {
|
|||||||
|
|
||||||
resMailList := make([]*Mail, 0, resMailsSize)
|
resMailList := make([]*Mail, 0, resMailsSize)
|
||||||
for _, gMail := range gameMails {
|
for _, gMail := range gameMails {
|
||||||
|
if player.IsUnreadMail(gMail.MailId) {
|
||||||
|
gMail.Flag = 0
|
||||||
|
} else {
|
||||||
|
gMail.Flag = 1 << 0
|
||||||
|
}
|
||||||
resMailList = append(resMailList, gMail)
|
resMailList = append(resMailList, gMail)
|
||||||
}
|
}
|
||||||
if playerMailSize > 0 {
|
if playerMailSize > 0 {
|
||||||
for _, pMail := range playerMails {
|
for _, pMail := range playerMails {
|
||||||
|
if player.IsUnreadMail(pMail.MailId) {
|
||||||
|
pMail.Flag = 0
|
||||||
|
} else {
|
||||||
|
pMail.Flag = 1 << 0
|
||||||
|
}
|
||||||
resMailList = append(resMailList, pMail)
|
resMailList = append(resMailList, pMail)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,6 @@ func (p *Player) IsDeletedMail(mailId int64) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) MarkMail(mailIds string) {
|
func (p *Player) MarkMail(mailIds string) {
|
||||||
p.Lock()
|
|
||||||
defer p.Unlock()
|
|
||||||
|
|
||||||
nowUnixSec := time.Now().Unix()
|
|
||||||
mailMgrPtr := global.GetMailMgr().(*mail.MailMgr)
|
mailMgrPtr := global.GetMailMgr().(*mail.MailMgr)
|
||||||
mailIdStrings := strings.Split(mailIds, ",")
|
mailIdStrings := strings.Split(mailIds, ",")
|
||||||
for _, mailId := range mailIdStrings {
|
for _, mailId := range mailIdStrings {
|
||||||
@ -66,23 +62,20 @@ func (p *Player) MarkMail(mailIds string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mailObj := mailMgrPtr.GetMail(q5.ToInt64(mailId))
|
mailObj := mailMgrPtr.GetMail(q5.ToInt64(mailId))
|
||||||
if mailObj == nil {
|
if mailObj != nil {
|
||||||
continue
|
m := &ReadMail{
|
||||||
|
mailId: mailObj.MailId,
|
||||||
|
readTime: int32(time.Now().Unix()),
|
||||||
|
expireTime: mailObj.ExpireTime,
|
||||||
|
}
|
||||||
|
p.ReadMailHash[mailObj.MailId] = m
|
||||||
}
|
}
|
||||||
m := &ReadMail{
|
|
||||||
mailId: mailObj.MailId,
|
|
||||||
readTime: int32(nowUnixSec),
|
|
||||||
expireTime: mailObj.ExpireTime,
|
|
||||||
}
|
|
||||||
p.ReadMailHash[mailObj.MailId] = m
|
|
||||||
p.MarkDirty()
|
|
||||||
}
|
}
|
||||||
|
p.MarkDirty()
|
||||||
|
// p.SaveToDB()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) DeleteMails(mailIds string) {
|
func (p *Player) DeleteMails(mailIds string) {
|
||||||
p.Lock()
|
|
||||||
defer p.Unlock()
|
|
||||||
|
|
||||||
nowUnixSec := time.Now().Unix()
|
nowUnixSec := time.Now().Unix()
|
||||||
mailMgrPtr := global.GetMailMgr().(*mail.MailMgr)
|
mailMgrPtr := global.GetMailMgr().(*mail.MailMgr)
|
||||||
mailIdStrings := strings.Split(mailIds, ",")
|
mailIdStrings := strings.Split(mailIds, ",")
|
||||||
@ -100,16 +93,13 @@ func (p *Player) DeleteMails(mailIds string) {
|
|||||||
expireTime: mailObj.ExpireTime,
|
expireTime: mailObj.ExpireTime,
|
||||||
}
|
}
|
||||||
p.DeletedMailHash[mailObj.MailId] = m
|
p.DeletedMailHash[mailObj.MailId] = m
|
||||||
p.MarkDirty()
|
|
||||||
}
|
}
|
||||||
|
p.MarkDirty()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) AddToReadList(mailIds string) {}
|
func (p *Player) AddToReadList(mailIds string) {}
|
||||||
|
|
||||||
func (p *Player) GetAttachment(mailIds string) []interface{} {
|
func (p *Player) GetAttachment(mailIds string) []interface{} {
|
||||||
p.Lock()
|
|
||||||
defer p.Unlock()
|
|
||||||
|
|
||||||
attachments := make([]interface{}, 0)
|
attachments := make([]interface{}, 0)
|
||||||
mailMgrPtr := global.GetMailMgr().(*mail.MailMgr)
|
mailMgrPtr := global.GetMailMgr().(*mail.MailMgr)
|
||||||
mailIdStrings := strings.Split(mailIds, ",")
|
mailIdStrings := strings.Split(mailIds, ",")
|
||||||
@ -133,9 +123,6 @@ func (p *Player) GetAttachment(mailIds string) []interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) Deserialize(accountPB *ss.MFAccountData) {
|
func (p *Player) Deserialize(accountPB *ss.MFAccountData) {
|
||||||
p.Lock()
|
|
||||||
defer p.Unlock()
|
|
||||||
|
|
||||||
var nextDaySec int32 = 3600 * 24
|
var nextDaySec int32 = 3600 * 24
|
||||||
nowUnixSec := int32(time.Now().Unix())
|
nowUnixSec := int32(time.Now().Unix())
|
||||||
for _, MFReadMail := range accountPB.GetReadMailList() {
|
for _, MFReadMail := range accountPB.GetReadMailList() {
|
||||||
@ -173,9 +160,6 @@ func (p *Player) Deserialize(accountPB *ss.MFAccountData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) Serialize(accountPB *ss.MFAccountData) {
|
func (p *Player) Serialize(accountPB *ss.MFAccountData) {
|
||||||
p.Lock()
|
|
||||||
defer p.Unlock()
|
|
||||||
|
|
||||||
var nextDaySec int32 = 3600 * 24
|
var nextDaySec int32 = 3600 * 24
|
||||||
nowUnixSec := time.Now().Unix()
|
nowUnixSec := time.Now().Unix()
|
||||||
for _, readMail := range p.ReadMailHash {
|
for _, readMail := range p.ReadMailHash {
|
||||||
@ -202,8 +186,6 @@ func (p *Player) Serialize(accountPB *ss.MFAccountData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) UpdateExpire() {
|
func (p *Player) UpdateExpire() {
|
||||||
p.Lock()
|
|
||||||
defer p.Unlock()
|
|
||||||
p.CacheExpiration = time.Now().Add(10 * time.Second)
|
p.CacheExpiration = time.Now().Add(10 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,11 +39,12 @@ func (pm *PlayerMgr) AsyncGetPlayer(accountId string) *Player {
|
|||||||
go func(accountId string) {
|
go func(accountId string) {
|
||||||
pm.LoadPlayer(accountId, func(err error, p *Player) {
|
pm.LoadPlayer(accountId, func(err error, p *Player) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
player = p
|
if err != nil && p != nil {
|
||||||
pm.accountIdHash[p.GetAccountId()] = p
|
player = p
|
||||||
|
pm.accountIdHash[p.GetAccountId()] = p
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}(accountId)
|
}(accountId)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
return player
|
return player
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user