save
This commit is contained in:
parent
e234527ac1
commit
292f6f87e7
@ -3,7 +3,7 @@ package mail
|
|||||||
import (
|
import (
|
||||||
"main/common"
|
"main/common"
|
||||||
"main/constant"
|
"main/constant"
|
||||||
"strconv"
|
"q5"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -14,7 +14,7 @@ type Attachments struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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"`
|
||||||
@ -24,7 +24,7 @@ type Mail struct {
|
|||||||
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"`
|
||||||
@ -55,17 +55,9 @@ func (m *Mail) ParseAttachments(attachmentsStr string) {
|
|||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
itemID, err := strconv.Atoi(parts[0])
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
itemNum, err := strconv.Atoi(parts[1])
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
attachment := &Attachments{
|
attachment := &Attachments{
|
||||||
ItemId: itemID,
|
ItemId: q5.ToInt(parts[0]),
|
||||||
ItemNum: itemNum,
|
ItemNum: q5.ToInt(parts[1]),
|
||||||
}
|
}
|
||||||
m.ATT = append(m.ATT, attachment)
|
m.ATT = append(m.ATT, attachment)
|
||||||
}
|
}
|
||||||
@ -93,8 +85,7 @@ func (m *Mail) IsReadableMail(accountObj common.Player) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
nowUnixSec := int32(time.Now().Unix())
|
nowUnixSec := int32(time.Now().Unix())
|
||||||
if m.ExpireTime > nowUnixSec &&
|
if m.ExpireTime > nowUnixSec && m.SendTime <= nowUnixSec && !accountObj.IsDeletedMail(m.MailId) {
|
||||||
m.SendTime <= nowUnixSec && !accountObj.IsDeletedMail(m.MailId) {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,14 +66,14 @@ func (mm *MailMgr) LoadFromDB() {
|
|||||||
empty = false
|
empty = false
|
||||||
|
|
||||||
m := newMail()
|
m := newMail()
|
||||||
m.Gameid = q5.ToInt(*rows.GetByName("gameid"))
|
m.GameId = q5.ToInt(*rows.GetByName("gameid"))
|
||||||
m.MailId = q5.ToInt64(*rows.GetByName("mailid"))
|
m.MailId = q5.ToInt64(*rows.GetByName("mailid"))
|
||||||
m.From = q5.ToString(*rows.GetByName("_from"))
|
m.From = q5.ToString(*rows.GetByName("_from"))
|
||||||
m.To = q5.ToString(*rows.GetByName("_to"))
|
m.To = q5.ToString(*rows.GetByName("_to"))
|
||||||
m.Subject = q5.ToString(*rows.GetByName("subject"))
|
m.Subject = q5.ToString(*rows.GetByName("subject"))
|
||||||
m.Content = q5.ToString(*rows.GetByName("content"))
|
m.Content = q5.ToString(*rows.GetByName("content"))
|
||||||
m.MailType = q5.ToInt(*rows.GetByName("mailtype"))
|
m.MailType = q5.ToInt(*rows.GetByName("mailtype"))
|
||||||
m.Mailsubtype = q5.ToInt(*rows.GetByName("mailsubtype"))
|
m.MailSubType = q5.ToInt(*rows.GetByName("mailsubtype"))
|
||||||
m.UserType = q5.ToInt(*rows.GetByName("usertype"))
|
m.UserType = q5.ToInt(*rows.GetByName("usertype"))
|
||||||
m.SendTime = q5.ToInt32(*rows.GetByName("sendtime"))
|
m.SendTime = q5.ToInt32(*rows.GetByName("sendtime"))
|
||||||
m.ExpireTime = q5.ToInt32(*rows.GetByName("expiretime"))
|
m.ExpireTime = q5.ToInt32(*rows.GetByName("expiretime"))
|
||||||
|
@ -17,10 +17,10 @@ func (mm *MailMgr) AddMail(m *Mail) {
|
|||||||
mailId := m.MailId
|
mailId := m.MailId
|
||||||
mm.allMailHash[mailId] = m
|
mm.allMailHash[mailId] = m
|
||||||
if m.MailType == constant.MAIL_TYPE_GROUP {
|
if m.MailType == constant.MAIL_TYPE_GROUP {
|
||||||
if mm.gameMailHash[m.Gameid] == nil {
|
if mm.gameMailHash[m.GameId] == nil {
|
||||||
mm.gameMailHash[m.Gameid] = make(map[int64]*Mail)
|
mm.gameMailHash[m.GameId] = make(map[int64]*Mail)
|
||||||
}
|
}
|
||||||
mm.gameMailHash[m.Gameid][mailId] = m
|
mm.gameMailHash[m.GameId][mailId] = m
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +61,6 @@ func (mm *MailMgr) GetMails(player common.Player) []*Mail {
|
|||||||
|
|
||||||
func (mm *MailMgr) GetUnreadMailCount(accountObj common.Player) int {
|
func (mm *MailMgr) GetUnreadMailCount(accountObj common.Player) int {
|
||||||
mailCnt := 0
|
mailCnt := 0
|
||||||
|
|
||||||
if gameMails, ok := mm.gameMailHash[constant.GAMEID]; ok {
|
if gameMails, ok := mm.gameMailHash[constant.GAMEID]; ok {
|
||||||
for _, mailObj := range gameMails {
|
for _, mailObj := range gameMails {
|
||||||
if mailObj.IsReadableMail(accountObj) {
|
if mailObj.IsReadableMail(accountObj) {
|
||||||
@ -69,7 +68,6 @@ func (mm *MailMgr) GetUnreadMailCount(accountObj common.Player) int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if playerMails, ok := mm.playerMailHash[accountObj.GetAccountId()]; ok {
|
if playerMails, ok := mm.playerMailHash[accountObj.GetAccountId()]; ok {
|
||||||
for _, mailObj := range playerMails {
|
for _, mailObj := range playerMails {
|
||||||
if mailObj.IsReadableMail(accountObj) {
|
if mailObj.IsReadableMail(accountObj) {
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package player
|
package player
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"f5"
|
||||||
|
"fmt"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
"main/constant"
|
||||||
"main/global"
|
"main/global"
|
||||||
"main/mail"
|
"main/mail"
|
||||||
"main/ss"
|
"main/ss"
|
||||||
@ -188,6 +192,40 @@ func (p *Player) Serialize(accountPB *ss.MFAccountData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) SaveToDB() {}
|
func (p *Player) SaveToDB() {
|
||||||
|
accountPB := ss.MFAccountData{}
|
||||||
|
p.Serialize(&accountPB)
|
||||||
|
blobData, err := proto.Marshal(&accountPB)
|
||||||
|
if err != nil {
|
||||||
|
f5.GetSysLog().Info("SaveToDB proto.Marshal Error:%v \n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
blobDataStr := string(blobData)
|
||||||
|
nowUnixSec := time.Now().Unix()
|
||||||
|
sql := fmt.Sprintf("INSERT INTO account_data (accountid, blobdata, createtime, modifytime) VALUES ('%s', '%s', %d, %d) ON DUPLICATE KEY UPDATE blobdata = '%s', modifytime = %d",
|
||||||
|
p.GetAccountId(), blobDataStr, nowUnixSec, nowUnixSec, blobDataStr, nowUnixSec)
|
||||||
|
|
||||||
func (p *Player) MarkDirty() {}
|
f5.GetGoStyleDb().SyncSelectCustomQuery(
|
||||||
|
constant.MAIL_DB,
|
||||||
|
sql,
|
||||||
|
func(err error, rows *f5.DataSet) {
|
||||||
|
if err != nil {
|
||||||
|
f5.GetSysLog().Info("SaveToDB Error:%v\n", err)
|
||||||
|
} else {
|
||||||
|
f5.GetSysLog().Info("SaveToDB OK\n")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) MarkDirty() {
|
||||||
|
timer := f5.GetTimer()
|
||||||
|
timer.SetTimeout(
|
||||||
|
1000*10,
|
||||||
|
func(e int32, args *q5.Args) {
|
||||||
|
if e == q5.TIMER_EXEC_EVENT {
|
||||||
|
p.SaveToDB()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user