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