From 9329fae43ea5c6dc920c5a15d4107f72b8a720db Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 25 May 2024 11:27:23 +0800 Subject: [PATCH] 1 --- server/statserver/session/sessionmgr.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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 }