From d35fb38e12d8b5b24a1fbdf5ce73852b7d5c9881 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 13 Apr 2024 09:12:58 +0800 Subject: [PATCH] 1 --- database/maildb.sql | 11 +- server/mailserver/mail/mailmgr.go | 210 ----------------------------- server/mailserver/player/player.go | 45 ------- 3 files changed, 6 insertions(+), 260 deletions(-) diff --git a/database/maildb.sql b/database/maildb.sql index 6e65de25..0e7a8587 100644 --- a/database/maildb.sql +++ b/database/maildb.sql @@ -83,6 +83,7 @@ CREATE TABLE `t_group` ( `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', `group_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '分组id', `group_name` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '分组名', + `deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否已删除', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`) @@ -101,6 +102,7 @@ CREATE TABLE `t_member` ( `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', `group_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '分组id', `mebmer_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '账号id', + `deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否已删除', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`) @@ -109,17 +111,16 @@ CREATE TABLE `t_member` ( /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; -- --- Table structure for table `t_account_data` +-- Table structure for table `t_user` -- -DROP TABLE IF EXISTS `t_account_data`; +DROP TABLE IF EXISTS `t_user`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `t_account_data` ( +CREATE TABLE `t_user` ( `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', - `mailid` bigint NOT NULL COMMENT '邮件id', `account_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '账号id', - `blobdata` mediumblob COMMENT '账号', + `maildata` text COMMENT '账号', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), diff --git a/server/mailserver/mail/mailmgr.go b/server/mailserver/mail/mailmgr.go index f5163757..39518176 100644 --- a/server/mailserver/mail/mailmgr.go +++ b/server/mailserver/mail/mailmgr.go @@ -1,234 +1,24 @@ package mail import ( - "f5" - //"fmt" - "main/common" - "main/constant" - "q5" - "time" ) type MailMgr struct { - Player common.Player allMailHash map[int64]*Mail - gameMailHash map[int]map[int64]*Mail - playerMailHash map[string]map[int64]*Mail currReqId int64 lastFetchMailTick int64 - accountHash map[string]*common.Player } -/* - 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 (this *MailMgr) UnInit() { } -func (this *MailMgr) GetMail(mailId int64) *Mail { - if m, exists := this.allMailHash[mailId]; exists { - return m - } - return nil -} - func (this *MailMgr) FetchMailFromDB() { - timer := f5.GetTimer() - timer.SetInterval(6000, func(e int32, args *q5.Args) { - if e == q5.TIMER_EXEC_EVENT { - this.LoadFromDB() - } - }) } -var lastIdx int64 = 0 - func (this *MailMgr) LoadFromDB() { - /* - unixSec := time.Now().Unix() - limit := 1000 - - done := false - for !done { - sql := fmt.Sprintf("SELECT idx, gameid, mailid, _from, _to, subject, content, mailtype, mailsubtype, sendtime, expiretime, attachments, createtime, ext, usertype FROM mailbox WHERE idx > %d AND deleted=0 AND expiretime > %d limit %d", lastIdx, unixSec, limit) - f5.GetGoStyleDb().SyncSelectCustomQuery( - constant.MAIL_DB, - sql, - func(err error, rows *f5.DataSet) { - if err != nil { - f5.GetSysLog().Info("LoadFromDB Error:%v \n", err) - done = true - } - empty := true - for rows.Next() { - empty = false - - m := NewMail() - m.GameId = q5.ToInt(*rows.GetByName("gameid")) - m.MailId = q5.ToInt64(*rows.GetByName("mailid")) - m.From = q5.ToString(*rows.GetByName("_from")) - m.To = q5.ToString(*rows.GetByName("_to")) - m.Subject = q5.ToString(*rows.GetByName("subject")) - m.Content = q5.ToString(*rows.GetByName("content")) - m.MailType = q5.ToInt(*rows.GetByName("mailtype")) - m.MailSubType = q5.ToInt(*rows.GetByName("mailsubtype")) - m.UserType = q5.ToInt(*rows.GetByName("usertype")) - m.SendTime = q5.ToInt32(*rows.GetByName("sendtime")) - m.ExpireTime = q5.ToInt32(*rows.GetByName("expiretime")) - m.CreateTime = q5.ToInt32(*rows.GetByName("createtime")) - // parse ATT - attachmentsStr := q5.ToString(*rows.GetByName("attachments")) - m.ParseAttachments(attachmentsStr) - - this.AddMail(m) - lastIdx = q5.ToInt64(*rows.GetByName("idx")) - } - if empty { - done = true - } - }, - ) - } - */ } - -func (this *MailMgr) InternalGMDeleteMail(mailId int64) { - mailObj := this.GetMail(mailId) - if mailObj == nil { - return - } - - if mailObj.MailType == constant.MAIL_TYPE_PLAYER { - if _, exists := this.playerMailHash[mailObj.To]; exists { - for _, mail := range this.playerMailHash[mailObj.To] { - if mail.MailId == mailId { - delete(this.playerMailHash[mailObj.To], mailId) - break - } - } - } - } else if mailObj.MailType == constant.MAIL_TYPE_GROUP { - for gameID, groupMails := range this.gameMailHash { - for _, mail := range groupMails { - if mail.MailId == mailId { - delete(this.gameMailHash[gameID], mailId) - break - } - } - } - } - delete(this.allMailHash, mailId) -} - -func (this *MailMgr) AddMail(m *Mail) { - unixSec := int32(time.Now().Unix()) - if m.ExpireTime < unixSec { - return - } - if _, exists := this.allMailHash[m.MailId]; exists { - return - } - - mailId := m.MailId - this.allMailHash[mailId] = m - if m.MailType == constant.MAIL_TYPE_GROUP { - if this.gameMailHash[m.GameId] == nil { - this.gameMailHash[m.GameId] = make(map[int64]*Mail) - } - this.gameMailHash[m.GameId][mailId] = m - return - } - - if m.MailType == constant.MAIL_TYPE_PLAYER { - if this.playerMailHash[m.To] == nil { - this.playerMailHash[m.To] = make(map[int64]*Mail) - } - this.playerMailHash[m.To][mailId] = m - return - } -} - -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, - MailId: mail.MailId, - From: mail.From, - To: mail.To, - Subject: mail.Subject, - Content: mail.Content, - SendTime: mail.SendTime, - ExpireTime: mail.ExpireTime, - MailType: mail.MailType, - MailSubType: mail.MailSubType, - Ext: mail.Ext, - ATT: mail.ATT, - } - resMailList = append(resMailList, newMail) - } - } - - return resMailList -} - -/* -func (this *MailMgr) GetMailList(player common.Player) []*Mail { - gameMailList := this.gameMailHash[constant.GAMEID] - playerMailList := this.playerMailHash[player.GetAccountId()] - - gameMailSize := len(gameMailList) - playerMailSize := len(playerMailList) - totalSize := gameMailSize + playerMailSize - resMailList := make([]*Mail, 0, totalSize) - - if totalSize == 0 { - return resMailList - } - for _, gMail := range gameMailList { - newMail := &Mail{ - MailId: gMail.MailId, - From: gMail.From, - To: gMail.To, - Subject: gMail.Subject, - Content: gMail.Content, - SendTime: gMail.SendTime, - ExpireTime: gMail.ExpireTime, - MailType: gMail.MailType, - MailSubType: gMail.MailSubType, - Ext: gMail.Ext, - ATT: gMail.ATT, - } - if player.IsUnreadMail(gMail.MailId) { - newMail.Flag = 0 - } else { - newMail.Flag = 1 << 0 - } - resMailList = append(resMailList, newMail) - } - - if playerMailSize > 0 { - for _, pMail := range playerMailList { - if player.IsUnreadMail(pMail.MailId) { - pMail.Flag = 0 - } else { - pMail.Flag = 1 << 0 - } - resMailList = append(resMailList, pMail) - } - } - return resMailList -} -*/ diff --git a/server/mailserver/player/player.go b/server/mailserver/player/player.go index ffdeb6c7..28ea3b28 100644 --- a/server/mailserver/player/player.go +++ b/server/mailserver/player/player.go @@ -5,11 +5,8 @@ import ( //"fmt" //"google.golang.org/protobuf/proto" //"main/constant" - "main/global" - "main/mail" //"main/ss" "q5" - "strings" "sync" "time" ) @@ -67,48 +64,6 @@ func (p *Player) IsDeletedMail(mailId int64) bool { return m != nil } -func (p *Player) MarkMail(mailIds string) { - mailMgrPtr := global.GetMailMgr().(*mail.MailMgr) - mailIdStrings := strings.Split(mailIds, ",") - for _, mailId := range mailIdStrings { - if len(mailId) <= 0 { - continue - } - mailObj := mailMgrPtr.GetMail(q5.ToInt64(mailId)) - if mailObj != nil { - m := &ReadMail{ - mailId: mailObj.MailId, - readTime: int32(time.Now().Unix()), - expireTime: mailObj.ExpireTime, - } - p.ReadMailHash[mailObj.MailId] = m - } - } - p.MarkDirty() -} - -func (p *Player) DeleteMails(mailIds string) { - nowUnixSec := time.Now().Unix() - mailMgrPtr := global.GetMailMgr().(*mail.MailMgr) - mailIdStrings := strings.Split(mailIds, ",") - for _, mailId := range mailIdStrings { - if len(mailId) <= 0 { - continue - } - mailObj := mailMgrPtr.GetMail(q5.ToInt64(mailId)) - if mailObj == nil { - continue - } - m := &DeletedMail{ - mailId: mailObj.MailId, - deleteTime: int32(nowUnixSec), - expireTime: mailObj.ExpireTime, - } - p.DeletedMailHash[mailObj.MailId] = m - } - p.MarkDirty() -} - /* func (p *Player) Deserialize(accountPB *ss.MFAccountData) { var nextDaySec int32 = 3600 * 24