This commit is contained in:
aozhiwei 2024-08-20 14:24:36 +08:00
commit 09f2d92207
6 changed files with 144 additions and 20 deletions

View File

@ -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"
}

View File

@ -49,6 +49,7 @@ type PlayerMgr interface {
type Mail interface {
GetMailId() int64
IsValid(Player) bool
HasAttachment() bool
GetExpireTime() int32
TraverseAttachment(cb func(int32, int32))
}

View File

@ -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
}

View File

@ -125,12 +125,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),
},
@ -142,16 +142,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())
@ -180,6 +180,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")
@ -189,10 +225,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 {

View File

@ -1,7 +1,13 @@
package activity
import (
"f5"
"fmt"
"main/constant"
"main/service"
"q5"
"strings"
"github.com/gin-gonic/gin"
)
@ -9,16 +15,47 @@ type BitGetApi struct {
}
func (this *BitGetApi) NewUserMission(c *gin.Context) {
email := strings.ToLower(c.DefaultQuery("email", ""))
rspObj := struct {
Missions []struct{
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
CP string `json:"contributionPoint"`
Missions []struct {
MissionId int32 `json:"mission_id"`
Current int32 `json:"current"`
Target int32 `json:"target"`
Current int32 `json:"current"`
Target int32 `json:"target"`
} `json:"missions"`
}{}
q5.NewSlice(&rspObj.Missions, 0, 10)
p := q5.NewSliceElement(&rspObj.Missions)
p.MissionId = 1
p.Target = 5
if email != "" {
mycp, accountid, _ := service.Contribution.GetEmailContributionAccountid(email)
rspObj.CP = fmt.Sprintf("%.2f", mycp)
if accountid != "" {
sql := `SELECT count(idx) FROM t_battle_settlement_single WHERE idx > 0 AND account_id = ?`
f5.GetGoStyleDb().RawQuery(
constant.GAME_DB,
sql,
[]string{accountid},
func(err error, ds *f5.DataSet) {
if err != nil {
return
}
if ds.Next() {
p.Current = q5.SafeToInt32(ds.GetByIndex(0))
if p.Current > p.Target {
p.Current = p.Target
}
}
})
}
}
c.JSON(200, rspObj)
}

View File

@ -8,7 +8,7 @@ import (
"time"
)
type accountContricution struct {
type accountContribution struct {
history float64
loadhistory bool
contribution float64
@ -23,11 +23,13 @@ type contribution struct {
globalContribution float64
gcTime int64
accountContricutionlist q5.ConcurrentMap[string, *accountContricution]
accountContributionlist q5.ConcurrentMap[string, *accountContribution]
emailContributionlist q5.ConcurrentMap[string, *accountContribution]
}
func (this *contribution) init() {
this.accountContricutionlist = q5.ConcurrentMap[string, *accountContricution]{}
this.accountContributionlist = q5.ConcurrentMap[string, *accountContribution]{}
this.emailContributionlist = q5.ConcurrentMap[string, *accountContribution]{}
go this.checkContributionList()
}
@ -35,8 +37,45 @@ func (this *contribution) unInit() {
}
func (this *contribution) GetEmailContributionAccountid(email string) (float64, string, error) {
info, exist := this.emailContributionlist.Load(email)
if exist {
return (*info).contribution, (*info).accountid, nil
}
accountid := ""
accountAddress := ""
sql := `SELECT account_id, address FROM t_immutable_account WHERE idx > 0 AND lower_case_email = ?`
f5.GetGoStyleDb().RawQuery(
constant.ACCOUNT_DB,
sql,
[]string{email},
func(err error, ds *f5.DataSet) {
if err != nil {
return
}
if ds.Next() {
accountid = ds.GetByIndex(0)
accountAddress = ds.GetByIndex(1)
}
})
if accountAddress != "" {
contrinfo := new(accountContribution)
contrinfo.loweremail = email
contrinfo.accountid = accountid
this.accountContributionlist.Store(accountAddress, contrinfo)
contri, _ := this.GetAddressContribution(accountAddress, false)
return contri, accountid, nil
}
return 0, accountid, nil
}
func (this *contribution) GetEmailAccountId(accountAddress string) (string, string) {
accinfo, exist := this.accountContricutionlist.Load(accountAddress)
accinfo, exist := this.accountContributionlist.Load(accountAddress)
if exist {
return (*accinfo).loweremail, (*accinfo).accountid
}
@ -45,12 +84,12 @@ func (this *contribution) GetEmailAccountId(accountAddress string) (string, stri
}
func (this *contribution) GetAddressContribution(accountAddress string, onlyrecharge bool) (float64, error) {
accinfo, exist := this.accountContricutionlist.Load(accountAddress)
accinfo, exist := this.accountContributionlist.Load(accountAddress)
var beforcontribution float64 = 0
if nowseconds := f5.GetApp().GetRealSeconds(); !exist || (*accinfo).gcTime+60 < nowseconds {
if !exist {
info := new(accountContricution)
this.accountContricutionlist.Store(accountAddress, info)
info := new(accountContribution)
this.accountContributionlist.Store(accountAddress, info)
accinfo = &info
}
beforcontribution = (*accinfo).contribution
@ -169,6 +208,9 @@ func (this *contribution) GetAddressContribution(accountAddress string, onlyrech
(*accinfo).contribution += (*accinfo).history
(*accinfo).gcTime = nowseconds
if (*accinfo).loweremail != "" {
this.emailContributionlist.Store((*accinfo).loweremail, *accinfo)
}
}
if beforcontribution != (*accinfo).contribution {
@ -260,7 +302,7 @@ func (this *contribution) checkContributionList() {
if time.Now().UTC().Hour() == 0 {
nowseconds := f5.GetApp().GetRealSeconds()
deletelist := []string{}
this.accountContricutionlist.Range(func(key string, value *accountContricution) bool {
this.accountContributionlist.Range(func(key string, value *accountContribution) bool {
if value.gcTime+86400 < nowseconds {
deletelist = append(deletelist, key)
}
@ -268,7 +310,11 @@ func (this *contribution) checkContributionList() {
})
for _, account := range deletelist {
this.accountContricutionlist.Delete(account)
v, _ := this.accountContributionlist.Load(account)
if (*v).loweremail != "" {
this.emailContributionlist.Delete((*v).loweremail)
}
this.accountContributionlist.Delete(account)
}
}
time.Sleep((time.Second * 1800))