This commit is contained in:
aozhiwei 2024-02-11 10:03:38 +08:00
parent 0991d3274d
commit 864c67475a

View File

@ -19,35 +19,42 @@ type MailMgr struct {
accountHash map[string]*common.Player accountHash map[string]*common.Player
} }
func (mm *MailMgr) Init() { /*
mm.allMailHash = make(map[int64]*Mail) c=Mail&a=getMailList
mm.gameMailHash = make(map[int]map[int64]*Mail) c=Mail&a=markMail
mm.playerMailHash = make(map[string]map[int64]*Mail) c=Mail&a=getUnreadMailCnt
mm.FetchMailFromDB() c=Mail&a=getAttachment
c=Mail&a=deleteMails
*/
func (this *MailMgr) Init() {
this.allMailHash = make(map[int64]*Mail)
this.gameMailHash = make(map[int]map[int64]*Mail)
this.playerMailHash = make(map[string]map[int64]*Mail)
this.FetchMailFromDB()
} }
func (mm *MailMgr) UnInit() { func (this *MailMgr) UnInit() {
} }
func (mm *MailMgr) GetMail(mailId int64) *Mail { func (this *MailMgr) GetMail(mailId int64) *Mail {
if m, exists := mm.allMailHash[mailId]; exists { if m, exists := this.allMailHash[mailId]; exists {
return m return m
} }
return nil return nil
} }
func (mm *MailMgr) FetchMailFromDB() { func (this *MailMgr) FetchMailFromDB() {
timer := f5.GetTimer() timer := f5.GetTimer()
timer.SetInterval(6000, func(e int32, args *q5.Args) { timer.SetInterval(6000, func(e int32, args *q5.Args) {
if e == q5.TIMER_EXEC_EVENT { if e == q5.TIMER_EXEC_EVENT {
mm.LoadFromDB() this.LoadFromDB()
} }
}) })
} }
var lastIdx int64 = 0 var lastIdx int64 = 0
func (mm *MailMgr) LoadFromDB() { func (this *MailMgr) LoadFromDB() {
/* /*
unixSec := time.Now().Unix() unixSec := time.Now().Unix()
limit := 1000 limit := 1000
@ -84,7 +91,7 @@ func (mm *MailMgr) LoadFromDB() {
attachmentsStr := q5.ToString(*rows.GetByName("attachments")) attachmentsStr := q5.ToString(*rows.GetByName("attachments"))
m.ParseAttachments(attachmentsStr) m.ParseAttachments(attachmentsStr)
mm.AddMail(m) this.AddMail(m)
lastIdx = q5.ToInt64(*rows.GetByName("idx")) lastIdx = q5.ToInt64(*rows.GetByName("idx"))
} }
if empty { if empty {
@ -96,65 +103,65 @@ func (mm *MailMgr) LoadFromDB() {
*/ */
} }
func (mm *MailMgr) InternalGMDeleteMail(mailId int64) { func (this *MailMgr) InternalGMDeleteMail(mailId int64) {
mailObj := mm.GetMail(mailId) mailObj := this.GetMail(mailId)
if mailObj == nil { if mailObj == nil {
return return
} }
if mailObj.MailType == constant.MAIL_TYPE_PLAYER { if mailObj.MailType == constant.MAIL_TYPE_PLAYER {
if _, exists := mm.playerMailHash[mailObj.To]; exists { if _, exists := this.playerMailHash[mailObj.To]; exists {
for _, mail := range mm.playerMailHash[mailObj.To] { for _, mail := range this.playerMailHash[mailObj.To] {
if mail.MailId == mailId { if mail.MailId == mailId {
delete(mm.playerMailHash[mailObj.To], mailId) delete(this.playerMailHash[mailObj.To], mailId)
break break
} }
} }
} }
} else if mailObj.MailType == constant.MAIL_TYPE_GROUP { } else if mailObj.MailType == constant.MAIL_TYPE_GROUP {
for gameID, groupMails := range mm.gameMailHash { for gameID, groupMails := range this.gameMailHash {
for _, mail := range groupMails { for _, mail := range groupMails {
if mail.MailId == mailId { if mail.MailId == mailId {
delete(mm.gameMailHash[gameID], mailId) delete(this.gameMailHash[gameID], mailId)
break break
} }
} }
} }
} }
delete(mm.allMailHash, mailId) delete(this.allMailHash, mailId)
} }
func (mm *MailMgr) AddMail(m *Mail) { func (this *MailMgr) AddMail(m *Mail) {
unixSec := int32(time.Now().Unix()) unixSec := int32(time.Now().Unix())
if m.ExpireTime < unixSec { if m.ExpireTime < unixSec {
return return
} }
if _, exists := mm.allMailHash[m.MailId]; exists { if _, exists := this.allMailHash[m.MailId]; exists {
return return
} }
mailId := m.MailId mailId := m.MailId
mm.allMailHash[mailId] = m this.allMailHash[mailId] = m
if m.MailType == constant.MAIL_TYPE_GROUP { if m.MailType == constant.MAIL_TYPE_GROUP {
if mm.gameMailHash[m.GameId] == nil { if this.gameMailHash[m.GameId] == nil {
mm.gameMailHash[m.GameId] = make(map[int64]*Mail) this.gameMailHash[m.GameId] = make(map[int64]*Mail)
} }
mm.gameMailHash[m.GameId][mailId] = m this.gameMailHash[m.GameId][mailId] = m
return return
} }
if m.MailType == constant.MAIL_TYPE_PLAYER { if m.MailType == constant.MAIL_TYPE_PLAYER {
if mm.playerMailHash[m.To] == nil { if this.playerMailHash[m.To] == nil {
mm.playerMailHash[m.To] = make(map[int64]*Mail) this.playerMailHash[m.To] = make(map[int64]*Mail)
} }
mm.playerMailHash[m.To][mailId] = m this.playerMailHash[m.To][mailId] = m
return return
} }
} }
func (mm *MailMgr) GetGMMailList(gameId int) []*GMMail { func (this *MailMgr) GetGMMailList(gameId int) []*GMMail {
resMailList := make([]*GMMail, 0, len(mm.allMailHash)) resMailList := make([]*GMMail, 0, len(this.allMailHash))
for _, mail := range mm.allMailHash { for _, mail := range this.allMailHash {
if mail.GameId == gameId { if mail.GameId == gameId {
newMail := &GMMail{ newMail := &GMMail{
GameId: mail.GameId, GameId: mail.GameId,
@ -177,9 +184,9 @@ func (mm *MailMgr) GetGMMailList(gameId int) []*GMMail {
return resMailList return resMailList
} }
func (mm *MailMgr) GetMailList(player common.Player) []*Mail { func (this *MailMgr) GetMailList(player common.Player) []*Mail {
gameMailList := mm.gameMailHash[constant.GAMEID] gameMailList := this.gameMailHash[constant.GAMEID]
playerMailList := mm.playerMailHash[player.GetAccountId()] playerMailList := this.playerMailHash[player.GetAccountId()]
gameMailSize := len(gameMailList) gameMailSize := len(gameMailList)
playerMailSize := len(playerMailList) playerMailSize := len(playerMailList)
@ -224,16 +231,19 @@ func (mm *MailMgr) GetMailList(player common.Player) []*Mail {
return resMailList return resMailList
} }
func (mm *MailMgr) GetUnreadMailCount(accountObj common.Player) int { func (this *MailMgr) markMail(accountObj common.Player) {
}
func (this *MailMgr) GetUnreadMailCount(accountObj common.Player) int {
mailCnt := 0 mailCnt := 0
if gameMails, ok := mm.gameMailHash[constant.GAMEID]; ok { if gameMails, ok := this.gameMailHash[constant.GAMEID]; ok {
for _, mailObj := range gameMails { for _, mailObj := range gameMails {
if mailObj.IsReadableMail(accountObj) { if mailObj.IsReadableMail(accountObj) {
mailCnt++ mailCnt++
} }
} }
} }
if playerMails, ok := mm.playerMailHash[accountObj.GetAccountId()]; ok { if playerMails, ok := this.playerMailHash[accountObj.GetAccountId()]; ok {
for _, mailObj := range playerMails { for _, mailObj := range playerMails {
if mailObj.IsReadableMail(accountObj) { if mailObj.IsReadableMail(accountObj) {
mailCnt++ mailCnt++
@ -243,3 +253,9 @@ func (mm *MailMgr) GetUnreadMailCount(accountObj common.Player) int {
return mailCnt return mailCnt
} }
func (this *MailMgr) getAttachment(accountObj common.Player) {
}
func (this *MailMgr) deleteMails(accountObj common.Player) {
}