This commit is contained in:
aozhiwei 2024-05-10 10:52:37 +08:00
parent 1b9e9459e1
commit e1e1596ac6
3 changed files with 18 additions and 5 deletions

View File

@ -29,7 +29,7 @@ type App interface {
} }
type Player interface { type Player interface {
Lock() Lock() bool
UnLock() UnLock()
GetAccountId() string GetAccountId() string
GetRegisterTime() int32 GetRegisterTime() int32

View File

@ -3,6 +3,7 @@ package middleware
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
. "main/global" . "main/global"
"net/http"
) )
func CaAuth(c *gin.Context) { func CaAuth(c *gin.Context) {
@ -12,7 +13,14 @@ func CaAuth(c *gin.Context) {
if hum == nil { if hum == nil {
hum = GetPlayerMgr().ForceCreatePlayer(accountId, sessionId) hum = GetPlayerMgr().ForceCreatePlayer(accountId, sessionId)
} }
hum.Lock() if !hum.Lock() {
c.JSON(http.StatusOK, gin.H{
"errcode": 500,
"errmsg": "server internal error",
})
c.Abort()
return
}
c.Set("hum", hum) c.Set("hum", hum)
c.Next() c.Next()
hum.UnLock() hum.UnLock()

View File

@ -28,11 +28,16 @@ func (this *player) init() {
this.inboxHash = make(map[int64]*inbox) this.inboxHash = make(map[int64]*inbox)
} }
func (this *player) Lock() { func (this *player) Lock() bool {
this.lock.Lock() this.lock.Lock()
if !this.loaded { if !this.loaded {
this.load() this.load()
} }
ok := this.loaded
if !ok {
this.UnLock()
}
return ok
} }
func (this *player) UnLock() { func (this *player) UnLock() {
@ -112,10 +117,10 @@ func (this *player) checkLock() {
func (this *player) load() { func (this *player) load() {
f5.GetGoStyleDb().RawQuery( f5.GetGoStyleDb().RawQuery(
constant.MAIL_DB, constant.MAIL_DB,
"SELECT * FROM t_inbox WHERE account_id=? AND expiretime>?", "SELECT * FROM t_inbox WHERE account_id=? AND expiretime<?",
[]string{ []string{
this.GetAccountId(), this.GetAccountId(),
q5.ToString(f5.GetApp().GetNowSeconds() - 3600 * 24 * 1), q5.ToString(f5.GetApp().GetRealSeconds() + 3600 * 24 * 7),
}, },
func (err error, ds *f5.DataSet) { func (err error, ds *f5.DataSet) {
if err != nil { if err != nil {