From 5c223abe778dd10ab7c3dc3722e3dfab89e23025 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 22 Apr 2024 16:05:51 +0800 Subject: [PATCH] 1 --- server/imserver/player/player.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/imserver/player/player.go b/server/imserver/player/player.go index 71047ede..b32daf4e 100644 --- a/server/imserver/player/player.go +++ b/server/imserver/player/player.go @@ -16,12 +16,14 @@ type player struct { accountId string sessionId string battling bool + lastRefreshCacheTime int64 } func (this *player) init(req *pendingLoginRequest, rspObj *common.LoginRsp){ this.socket = req.hdr.GetSocket() this.accountId = req.msg.GetAccountId() this.sessionId = req.msg.GetSessionId() + this.refreshCache() } func (this *player) GetAccountId() string { @@ -51,6 +53,7 @@ func (this *player) reBind(socket f5.WspCliConn, sessionId string) { this.socket = socket this.sessionId = sessionId _playerMgr.socketHash[this.socket] = this + this.refreshCache() } func (this *player) CMPing(hdr *f5.MsgHdr, msg *cs.CMPing) { @@ -866,6 +869,19 @@ func (this *player) onOffline() { f5.GetSysLog().Info("onOffline %s", this.GetAccountId()) } +func (this *player) refreshCache() { + if f5.GetApp().GetNowSeconds() - this.lastRefreshCacheTime > 5 { + this.lastRefreshCacheTime = f5.GetApp().GetNowSeconds() + f5.GetTimer().SetTimeout( + 1000 * 5, + func(e int32, args *q5.Args) { + if e == q5.TIMER_EXEC_EVENT { + GetCacheMgr().PreLoadUsers([]string{this.GetAccountId()}) + } + }) + } +} + func newPlayer() *player { p := new(player) return p