Merge branch 'market' of git.kingsome.cn:server/game2006go into market
This commit is contained in:
commit
5653e4e27d
@ -1,6 +1,6 @@
|
||||
{
|
||||
"secret_key": "520d8eAbB(8cf1^#$^&!@d833a42c820432PDAFE^^)",
|
||||
"gameapi_url": "https://game2006api-test.kingsome.cn",
|
||||
"gameapi_url": "https://game2006sapi-test.kingsome.cn",
|
||||
"gm_open": 1,
|
||||
"gm_secret_key": "Pu6bxRKiS^@pUQdAC!RHMTY^srV5V^4&fqgUs1HjM*LI1sABQDQemU^Mh!55"
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ type PlayerMgr interface {
|
||||
type Mail interface {
|
||||
GetMailId() int64
|
||||
IsValid(Player) bool
|
||||
HasAttachment() bool
|
||||
GetExpireTime() int32
|
||||
TraverseAttachment(cb func(int32, int32))
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ const (
|
||||
INBOX_STATE_NONE = 0
|
||||
INBOX_STATE_READ = 1
|
||||
INBOX_STATE_DELETED = 2
|
||||
INBOX_STATE_RECEIVED = 3
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -77,6 +77,10 @@ func (this *mail) IsValid(hum common.Player) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *mail) HasAttachment() bool {
|
||||
return len(this.attachments) > 0
|
||||
}
|
||||
|
||||
func (this *mail) GetMailId() int64 {
|
||||
return this.mailId
|
||||
}
|
||||
|
@ -3,9 +3,7 @@ package mail
|
||||
import (
|
||||
"q5"
|
||||
"f5"
|
||||
"jccommon"
|
||||
"main/common"
|
||||
"main/mt"
|
||||
"main/constant"
|
||||
"sync"
|
||||
"fmt"
|
||||
@ -48,7 +46,6 @@ func (this *mailMgr) Init() {
|
||||
f5.GetApp().RegisterCaHandle("Mail", "getUnreadMailCnt", this.CaGetUnreadMailCnt)
|
||||
f5.GetApp().RegisterCaHandle("Mail", "getAttachment", this.CaGetAttachment)
|
||||
f5.GetApp().RegisterCaHandle("Mail", "deleteMails", this.CaDeleteMails)
|
||||
f5.GetApp().RegisterCaHandle("MailMgr", "sendMail", this.CaSendMail)
|
||||
this.timerWp = f5.GetTimer().SetIntervalWp(
|
||||
300,
|
||||
func (e int32, args* q5.Args) {
|
||||
@ -218,156 +215,6 @@ func (this *mailMgr) CaDeleteMails(c *gin.Context) {
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
||||
func (this *mailMgr) CaSendMail(c *gin.Context) {
|
||||
rspObj := struct {
|
||||
ErrCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
}{}
|
||||
|
||||
key := c.DefaultQuery("key", "")
|
||||
if mt.Table.Config.GetById(0).GetGmSecretKey() != key {
|
||||
rspObj.ErrCode = 2
|
||||
rspObj.ErrMsg = "is not gm error"
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}
|
||||
if mt.Table.Config.GetById(0).GetGmOpen() == 0 {
|
||||
rspObj.ErrCode = 3
|
||||
rspObj.ErrMsg = "is not gm open"
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}
|
||||
reqJson := struct {
|
||||
UniKey string `json:"unikey"`
|
||||
Subject string `json:"subject"`
|
||||
Content string `json:"content"`
|
||||
Recipients []string`json:"recipients"`
|
||||
SendTime int32 `json:"sendtime"`
|
||||
ExpireTime int32 `json:"expiretime"`
|
||||
Attachments []*common.AttachmentDto `json:"attachments"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&reqJson); err != nil {
|
||||
c.JSON(200, gin.H{
|
||||
"code": 1,
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if reqJson.UniKey == "" {
|
||||
rspObj.ErrCode = 500
|
||||
rspObj.ErrMsg = "unikey param error"
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}
|
||||
/*
|
||||
if reqJson.Subject == "" {
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}*/
|
||||
if reqJson.Content == "" {
|
||||
rspObj.ErrCode = 500
|
||||
rspObj.ErrMsg = "unikey param error"
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}
|
||||
if len(reqJson.Recipients) <= 0 {
|
||||
rspObj.ErrCode = 500
|
||||
rspObj.ErrMsg = "recipients param error"
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}
|
||||
if f5.GetApp().GetRealSeconds() >= q5.ToInt64(reqJson.ExpireTime) {
|
||||
rspObj.ErrCode = 500
|
||||
rspObj.ErrMsg = "expiretime param error"
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}
|
||||
for _, val := range reqJson.Attachments {
|
||||
if val.ItemId == 0 {
|
||||
rspObj.ErrCode = 500
|
||||
rspObj.ErrMsg = "Attachments param error"
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}
|
||||
if val.ItemNum <= 0 || val.ItemNum > 10000 * 100 {
|
||||
rspObj.ErrCode = 500
|
||||
rspObj.ErrMsg = "Attachments param error"
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}
|
||||
}
|
||||
{
|
||||
var dbErr error
|
||||
found := false
|
||||
f5.GetGoStyleDb().OrmSelectOne(
|
||||
constant.MAIL_DB,
|
||||
"t_mail",
|
||||
[][]string{
|
||||
{"unikey", reqJson.UniKey},
|
||||
},
|
||||
func (err error, ds *f5.DataSet) {
|
||||
dbErr = err
|
||||
if err == nil {
|
||||
if ds.Next() {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
});
|
||||
if dbErr != nil {
|
||||
rspObj.ErrCode = 500
|
||||
rspObj.ErrMsg = dbErr.Error()
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}
|
||||
if found {
|
||||
rspObj.ErrCode = 3
|
||||
rspObj.ErrMsg = "mail already exists"
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}
|
||||
}
|
||||
mailId := f5.GetApp().NewLockNodeUuid()
|
||||
nowTime := f5.GetApp().GetRealSeconds()
|
||||
f5.GetGoStyleDb().Insert(
|
||||
constant.MAIL_DB,
|
||||
"t_mail",
|
||||
[][]string{
|
||||
{"mail_id", q5.ToString(mailId)},
|
||||
{"mail_type", q5.ToString(jccommon.MAIL_TYPE_GROUP)},
|
||||
{"unikey", reqJson.UniKey},
|
||||
{"subject", reqJson.Subject},
|
||||
{"content", reqJson.Content},
|
||||
{"recipients", q5.EncodeJson(reqJson.Recipients)},
|
||||
{"attachments", q5.EncodeJson(reqJson.Attachments)},
|
||||
{"sendtime", q5.ToString(reqJson.SendTime)},
|
||||
{"expiretime", q5.ToString(reqJson.ExpireTime)},
|
||||
{"user_reg_start_time", q5.ToString(0)},
|
||||
{"user_reg_end_time", q5.ToString(nowTime + 3600 * 24 * 365 * 10)},
|
||||
{"createtime", q5.ToString(nowTime)},
|
||||
{"modifytime", q5.ToString(nowTime)},
|
||||
},
|
||||
func (err error, lastInsertId int64, rowsAffected int64) {
|
||||
if err != nil {
|
||||
rspObj.ErrCode = 500
|
||||
rspObj.ErrMsg = err.Error()
|
||||
return
|
||||
}
|
||||
f5.GetGoStyleDb().Insert(
|
||||
constant.MAIL_DB,
|
||||
"t_event",
|
||||
[][]string{
|
||||
{"event_name", constant.EVENT_MAIL_UPDATE},
|
||||
{"param1", q5.ToString(mailId)},
|
||||
{"createtime", q5.ToString(nowTime)},
|
||||
{"modifytime", q5.ToString(nowTime)},
|
||||
},
|
||||
func (err error, lastInsertId int64, rowsAffected int64) {
|
||||
c.JSON(200, rspObj)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (this *mailMgr) traversePlayerMail(hum common.Player, cb func(*mail) bool) {
|
||||
stop := false
|
||||
traversedMails := make(map[int64]*mail, 10)
|
||||
|
@ -9,12 +9,6 @@ import (
|
||||
func CaAuth(c *gin.Context) {
|
||||
accountId := c.DefaultQuery("account_id", "")
|
||||
sessionId := c.DefaultQuery("session_id", "")
|
||||
class := c.DefaultQuery("c", "")
|
||||
action := c.DefaultQuery("a", "")
|
||||
if class == "MailMgr" && action == "sendMail" {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
hum := GetPlayerMgr().GetPlayerByAccountId(accountId)
|
||||
if hum == nil {
|
||||
hum = GetPlayerMgr().ForceCreatePlayer(accountId, sessionId)
|
||||
|
@ -122,12 +122,12 @@ func (this *player) GetAttachment(mails []common.Mail, c *gin.Context) {
|
||||
cbParamsStr := q5.EncodeJson(&cbParams)
|
||||
signStr := q5.Md5Str(cbParamsStr + mt.Table.Config.GetSecretKey() + q5.ToString(nowTime))
|
||||
f5.GetHttpCliMgr().SendGoStyleJsonRspPost(
|
||||
mt.Table.Config.GetGameApiUrl() + "/webapp/index.php?",
|
||||
mt.Table.Config.GetGameApiUrl() + "/sapi/webapp/index.php?",
|
||||
map[string]string{
|
||||
"account_id": accountId,
|
||||
"session_id": sessionId,
|
||||
"c": "Mail",
|
||||
"a": "getAttachmentCb",
|
||||
"a": "getAttachmentCbS",
|
||||
"sign": signStr,
|
||||
"timestamp": q5.ToString(nowTime),
|
||||
},
|
||||
@ -139,16 +139,16 @@ func (this *player) GetAttachment(mails []common.Mail, c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if errCode, err := q5.ToInt64Ex(rspObj.ErrCode); err == nil && errCode == 0 {
|
||||
this.DeleteMails(mails)
|
||||
this.ReceivedMails(mails)
|
||||
}
|
||||
c.String(200, rsp.GetRawData())
|
||||
})
|
||||
}
|
||||
|
||||
func (this *player) DeleteMails(mails []common.Mail) error {
|
||||
func (this *player) ReceivedMails(mails []common.Mail) error {
|
||||
this.checkLock()
|
||||
var resultErr error
|
||||
var nowTime int64
|
||||
var nowTime int64 = int64(f5.GetApp().GetRealSeconds())
|
||||
for _, m := range(mails) {
|
||||
if m.IsValid(this) {
|
||||
mi := this.getInbox(m.GetMailId())
|
||||
@ -177,6 +177,42 @@ func (this *player) DeleteMails(mails []common.Mail) error {
|
||||
return resultErr
|
||||
}
|
||||
|
||||
func (this *player) DeleteMails(mails []common.Mail) error {
|
||||
this.checkLock()
|
||||
var resultErr error
|
||||
var nowTime int64 = int64(f5.GetApp().GetRealSeconds())
|
||||
for _, m := range(mails) {
|
||||
if m.IsValid(this) {
|
||||
mi := this.getInbox(m.GetMailId())
|
||||
if mi == nil {
|
||||
if !m.HasAttachment() {
|
||||
err := model.Inbox.Delete(this.GetAccountId(), m.GetMailId(), nowTime, m.GetExpireTime())
|
||||
if err != nil {
|
||||
resultErr = err
|
||||
break
|
||||
}
|
||||
mi = new(inbox)
|
||||
mi.mailId = m.GetMailId()
|
||||
mi.state = constant.INBOX_STATE_DELETED
|
||||
mi.expireTime = m.GetExpireTime()
|
||||
this.inboxHash[mi.mailId] = mi
|
||||
}
|
||||
} else if mi.state != constant.INBOX_STATE_DELETED {
|
||||
if !m.HasAttachment() || mi.state == constant.INBOX_STATE_RECEIVED {
|
||||
err := model.Inbox.Delete(this.GetAccountId(), m.GetMailId(), nowTime, m.GetExpireTime())
|
||||
if err != nil {
|
||||
resultErr = err
|
||||
break
|
||||
}
|
||||
mi.state = constant.INBOX_STATE_DELETED
|
||||
mi.expireTime = m.GetExpireTime()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultErr
|
||||
}
|
||||
|
||||
func (this *player) checkLock() {
|
||||
if this.lock.TryLock() {
|
||||
panic("player checkLock error")
|
||||
@ -186,10 +222,10 @@ func (this *player) checkLock() {
|
||||
func (this *player) load() {
|
||||
f5.GetGoStyleDb().RawQuery(
|
||||
constant.MAIL_DB,
|
||||
"SELECT * FROM t_inbox WHERE account_id=? AND expiretime<?",
|
||||
"SELECT * FROM t_inbox WHERE account_id=? AND expiretime>?",
|
||||
[]string{
|
||||
this.GetAccountId(),
|
||||
q5.ToString(f5.GetApp().GetRealSeconds() + 3600 * 24 * 7),
|
||||
q5.ToString(f5.GetApp().GetRealSeconds() - 3600 * 24 * 7),
|
||||
},
|
||||
func (err error, ds *f5.DataSet) {
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user