From 17cb4ac14417b2f94469a1d409486f59364fad69 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 5 Apr 2024 21:01:47 +0800 Subject: [PATCH] 1 --- server/imserver_new/cache/cachemgr.go | 36 +++++++++++++++++++++++ server/imserver_new/cache/user_profile.go | 9 +++++- server/imserver_new/player/player.go | 5 ++-- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/server/imserver_new/cache/cachemgr.go b/server/imserver_new/cache/cachemgr.go index 6a78988f..47ced52e 100644 --- a/server/imserver_new/cache/cachemgr.go +++ b/server/imserver_new/cache/cachemgr.go @@ -1,8 +1,12 @@ package cache import ( + "f5" + "q5" "sync" + "fmt" "main/common" + "main/constant" ) type cacheMgr struct { @@ -33,5 +37,37 @@ func (this *cacheMgr) PreLoadUsers(accountIds []string) { func (this *cacheMgr) AsyncSearch(sinceId int64, q string, cb func(int32, string, int64, []string)) { + f5.GetJsStyleDb().PageQuery( + constant.GAME_DB, + 50, + 0, + "SELECT * FROM t_user WHERE 1=1", + []string{}, + f5.GetDbFilter().Comp( + f5.GetDbFilter().GT("idx", q5.ToString(sinceId)).And(), + f5.GetDbFilter().Like("name", q5.ToString(q)).And(), + ), + "", + func (err error, pg *f5.Pagination) { + var lastSinceId int64 + if err != nil { + cb(500, "", lastSinceId, []string{}) + } + users := []string{} + for pg.Rows.Next() { + idx := q5.ToInt64(pg.Rows.GetByName("idx")) + if idx > lastSinceId { + lastSinceId = idx + } else { + panic(fmt.Sprintf("AsyncGetApply idx error:%s %s", idx, lastSinceId)) + } + u := newUserProfile() + u.accountId = pg.Rows.GetByName("account_id") + u.name = pg.Rows.GetByName("name") + this.userHash[u.accountId] = u + *q5.NewSliceElement(&users) = u.accountId + } + cb(0, "", lastSinceId, users) + }) } diff --git a/server/imserver_new/cache/user_profile.go b/server/imserver_new/cache/user_profile.go index 1b17b57c..b9e63d48 100644 --- a/server/imserver_new/cache/user_profile.go +++ b/server/imserver_new/cache/user_profile.go @@ -2,6 +2,7 @@ package cache import ( "cs" + "github.com/golang/protobuf/proto" ) type userProfile struct { @@ -40,7 +41,6 @@ func (this *userProfile)GetTotalKills() int32 { return this.totalKills } - func (this *userProfile) GetTotalWinTimes() int32 { return this.totalWinTimes } @@ -58,4 +58,11 @@ func (this *userProfile) GetLastLoginTime() int32 { } func (this *userProfile) FillMFUser(pbUser *cs.MFUser) { + pbUser.AccountId = proto.String(this.accountId) + pbUser.Username = proto.String(this.name) +} + +func newUserProfile() *userProfile { + p := new(userProfile) + return p } diff --git a/server/imserver_new/player/player.go b/server/imserver_new/player/player.go index 1c4fa8f2..8674afcd 100644 --- a/server/imserver_new/player/player.go +++ b/server/imserver_new/player/player.go @@ -66,8 +66,9 @@ func (this *player) CMSearchUser(hdr *f5.MsgHdr, msg *cs.CMSearchUser) { for _, accountId := range(accountIds) { userProfile := GetCacheMgr().GetUserProfile(accountId) if userProfile != nil { - ele := q5.NewSliceElement(&rspMsg.Users) - userProfile.FillMFUser(*ele) + ele := new(cs.MFUser) + q5.AppendSlice(&rspMsg.Users, ele) + userProfile.FillMFUser(ele) } } this.SendMsg(rspMsg)