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