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"
)
type session struct {
type userSession struct {
accountId string
sessionId string
lastUpdateTick int64
}
type sessionMgr struct {
idHash sync.Map
lock sync.Mutex
}
func (this *sessionMgr) UpdateSession(accountId string, sessionId string) {
@ -20,11 +22,25 @@ func (this *sessionMgr) UpdateSession(accountId string, sessionId string) {
session.lastUpdateTick = q5.GetTickCount()
return
}
this.lock.Lock()
session = this.getSession(accountId)
if session != nil {
session.lastUpdateTick = q5.GetTickCount()
this.lock.Unlock()
return
}
func (this *sessionMgr) getSession(accountId string) *session {
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) *userSession {
if p, ok := this.idHash.Load(accountId); ok {
return p.(*session)
return p.(*userSession)
} else {
return nil
}