This commit is contained in:
aozhiwei 2024-05-25 11:27:23 +08:00
parent 53ebf98467
commit 9329fae43e

View File

@ -5,13 +5,15 @@ import (
"sync" "sync"
) )
type session struct { type userSession struct {
accountId string accountId string
sessionId string
lastUpdateTick int64 lastUpdateTick int64
} }
type sessionMgr struct { type sessionMgr struct {
idHash sync.Map idHash sync.Map
lock sync.Mutex
} }
func (this *sessionMgr) UpdateSession(accountId string, sessionId string) { func (this *sessionMgr) UpdateSession(accountId string, sessionId string) {
@ -20,11 +22,25 @@ func (this *sessionMgr) UpdateSession(accountId string, sessionId string) {
session.lastUpdateTick = q5.GetTickCount() session.lastUpdateTick = q5.GetTickCount()
return return
} }
this.lock.Lock()
session = this.getSession(accountId)
if session != nil {
session.lastUpdateTick = q5.GetTickCount()
this.lock.Unlock()
return
}
session = new(userSession)
session.accountId = accountId
session.sessionId = sessionId
session.lastUpdateTick = q5.GetTickCount()
this.idHash.Store(accountId, session)
this.lock.Unlock()
} }
func (this *sessionMgr) getSession(accountId string) *session { func (this *sessionMgr) getSession(accountId string) *userSession {
if p, ok := this.idHash.Load(accountId); ok { if p, ok := this.idHash.Load(accountId); ok {
return p.(*session) return p.(*userSession)
} else { } else {
return nil return nil
} }