1
This commit is contained in:
parent
53ebf98467
commit
9329fae43e
@ -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
|
||||
}
|
||||
|
||||
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 {
|
||||
return p.(*session)
|
||||
return p.(*userSession)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user