This commit is contained in:
殷勇 2023-10-31 13:23:09 +08:00
parent 14223c4f96
commit c834b49870
4 changed files with 20 additions and 23 deletions

View File

@ -82,6 +82,8 @@ func (mm *MailMgr) LoadFromDB() {
attachmentsStr := q5.ToString(*rows.GetByName("attachments")) attachmentsStr := q5.ToString(*rows.GetByName("attachments"))
if len(attachmentsStr) > 0 { if len(attachmentsStr) > 0 {
m.ParseAttachments(attachmentsStr) m.ParseAttachments(attachmentsStr)
} else {
m.ATT = make([]*Attachment, 0)
} }
mm.AddMail(m) mm.AddMail(m)

View File

@ -35,20 +35,18 @@ func (mm *MailMgr) AddMail(m *Mail) {
} }
func (mm *MailMgr) GetMails(player common.Player) []*Mail { func (mm *MailMgr) GetMails(player common.Player) []*Mail {
gameMails := mm.gameMailHash[constant.GAMEID] gameMailList := mm.gameMailHash[constant.GAMEID]
playerMails := mm.playerMailHash[player.GetAccountId()] playerMailList := mm.playerMailHash[player.GetAccountId()]
playerMailSize := len(playerMails)
if len(gameMails)+playerMailSize == 0 {
return nil
}
resMailsSize := len(gameMails) gameMailSize := len(gameMailList)
if playerMailSize > 0 { playerMailSize := len(playerMailList)
resMailsSize += playerMailSize totalSize := gameMailSize + playerMailSize
} resMailList := make([]*Mail, 0, totalSize)
resMailList := make([]*Mail, 0, resMailsSize) if totalSize == 0 {
for _, gMail := range gameMails { return resMailList
}
for _, gMail := range gameMailList {
newMail := &Mail{ newMail := &Mail{
GameId: gMail.GameId, GameId: gMail.GameId,
MailId: gMail.MailId, MailId: gMail.MailId,
@ -74,7 +72,7 @@ func (mm *MailMgr) GetMails(player common.Player) []*Mail {
} }
if playerMailSize > 0 { if playerMailSize > 0 {
for _, pMail := range playerMails { for _, pMail := range playerMailList {
if player.IsUnreadMail(pMail.MailId) { if player.IsUnreadMail(pMail.MailId) {
pMail.Flag = 0 pMail.Flag = 0
} else { } else {

View File

@ -11,21 +11,19 @@ func Auth() gin.HandlerFunc {
accountID := c.Query("account_id") accountID := c.Query("account_id")
sessionID := c.Query("session_id") sessionID := c.Query("session_id")
if accountID == "" || sessionID == "" { if accountID == "" || sessionID == "" {
c.JSON(http.StatusBadRequest, gin.H{ c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
"errcode": http.StatusBadRequest, "errcode": http.StatusUnauthorized,
"errmsg": "Bad Request: Missing account_id or session_id", "errmsg": "Bad Request: authorization account_id or session_id is not provided",
}) })
f5.GetSysLog().Info("logUnauthorizedAccess, clientIP:%s, requestURL:%s", c.ClientIP(), c.Request.URL.String())
c.Abort()
return return
} }
if !isValidSession(accountID, sessionID) { if !isValidSession(accountID, sessionID) {
c.JSON(http.StatusUnauthorized, gin.H{ f5.GetSysLog().Info("logUnauthorizedAccess, clientIP:%s, requestURL:%s", c.ClientIP(), c.Request.URL.String())
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
"errcode": http.StatusUnauthorized, "errcode": http.StatusUnauthorized,
"errmsg": "Unauthorized", "errmsg": "Bad Request: token is invalid",
}) })
c.Abort()
return return
} }

View File

@ -1,7 +1,6 @@
package player package player
import ( import (
"f5"
"sync" "sync"
) )
@ -30,7 +29,7 @@ func (pm *PlayerMgr) GetPlayer(accountId string) *Player {
func (pm *PlayerMgr) AsyncGetPlayer(accountId string) *Player { func (pm *PlayerMgr) AsyncGetPlayer(accountId string) *Player {
p := pm.GetPlayer(accountId) p := pm.GetPlayer(accountId)
if p != nil && !p.IsCacheExpired() { if p != nil && !p.IsCacheExpired() {
f5.GetSysLog().Info("GetPlayer(%s) from cache", accountId) // f5.GetSysLog().Info("GetPlayer(%s) from cache", accountId)
return p return p
} }