diff --git a/server/statserver/session/sessionmgr.go b/server/statserver/session/sessionmgr.go index a8974e99..2d6dc199 100644 --- a/server/statserver/session/sessionmgr.go +++ b/server/statserver/session/sessionmgr.go @@ -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 }