diff --git a/comm/imodule.go b/comm/imodule.go index c217f7ba7..141f165f0 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -33,6 +33,11 @@ type ( IPayDelivery interface { Delivery(session IUserSession, pId int32) (errdata *pb.ErrorData, items []*pb.UserAtno) } + + // 修改玩家基本数据 + IUpdateUserBaseInfo interface { + UpdateUserBaseInfo(session IUserSession, info *pb.BaseUserInfo) (err error) + } ) /* @@ -274,6 +279,7 @@ type ( QiecuoFinishNotify(redUid, matchId string) error // 红点 IGetReddot + IUpdateUserBaseInfo } //聊天系统 diff --git a/modules/friend/api_cross_getassist.go b/modules/friend/api_cross_getassist.go index ec564f26d..20d467378 100644 --- a/modules/friend/api_cross_getassist.go +++ b/modules/friend/api_cross_getassist.go @@ -48,9 +48,9 @@ func (this *apiComp) GetAssistHero(session comm.IUserSession, req *pb.FriendGetA } } leftCount = int32(comm.AssistHeroCount - len(list.Data)) - localNum, _ := this.module.modelFriend.DB.CountDocuments(core.SqlTable(this.module.modelFriend.TableName), bson.M{}) - randomIndex := comm.GetRandNum(0, int32(localNum)) - cur, err := this.module.modelFriend.DB.Find(core.SqlTable(this.module.modelFriend.TableName), bson.M{"assistHeroId": bson.M{"$ne": ""}}, options.Find().SetSkip(int64(randomIndex)).SetLimit(int64(leftCount))) //.skip(1).limit(1) + // localNum, _ := this.module.modelFriend.DB.CountDocuments(core.SqlTable(this.module.modelFriend.TableName), bson.M{}) + // randomIndex := comm.GetRandNum(0, int32(localNum)) + cur, err := this.module.modelFriend.DB.Find(core.SqlTable(this.module.modelFriend.TableName), bson.M{"assistHeroId": bson.M{"$ne": ""}}, options.Find().SetSkip(int64(0)).SetLimit(int64(leftCount))) //.skip(1).limit(1) for cur.Next(context.TODO()) { tmp := &pb.DBFriend{} if err = cur.Decode(tmp); err == nil { @@ -75,21 +75,40 @@ func (this *apiComp) GetAssistHero(session comm.IUserSession, req *pb.FriendGetA return } - for k := range list.Data { - uids = append(uids, k) - } - // 批量查 - friends, err = this.module.modelFriend.GetFriends(uids) - if err != nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_FriendSelfNoData, - Title: pb.ErrorCode_FriendSelfNoData.ToString(), + if len(list.Data) == 0 { // 异常处理 + leftCount = int32(comm.AssistHeroCount - len(list.Data)) + // localNum, _ := this.module.modelFriend.DB.CountDocuments(core.SqlTable(this.module.modelFriend.TableName), bson.M{}) + // randomIndex := comm.GetRandNum(0, int32(localNum)) + cur, err := this.module.modelFriend.DB.Find(core.SqlTable(this.module.modelFriend.TableName), bson.M{"assistHeroId": bson.M{"$ne": ""}}, options.Find().SetSkip(int64(0)).SetLimit(int64(leftCount))) //.skip(1).limit(1) + for cur.Next(context.TODO()) { + tmp := &pb.DBFriend{} + if err = cur.Decode(tmp); err == nil { + list.Data[tmp.Uid] = tmp.Info.Name + heros = append(heros, tmp.Hero) + } + } + + err = this.module.modelAssist.modifyAssistData(session.GetUserId(), map[string]interface{}{ + "data": list.Data, + }) + } else { + for k := range list.Data { + uids = append(uids, k) + } + // 批量查 + friends, err = this.module.modelFriend.GetFriends(uids) + if err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_FriendSelfNoData, + Title: pb.ErrorCode_FriendSelfNoData.ToString(), + } + return + } + for _, v := range friends { + heros = append(heros, v.Hero) } - return - } - for _, v := range friends { - heros = append(heros, v.Hero) } + session.SendMsg(string(this.module.GetType()), "getassisthero", &pb.FriendGetAssistHeroResp{ Data: list, Hero: heros, diff --git a/modules/friend/module.go b/modules/friend/module.go index 74991cd67..6d9116479 100644 --- a/modules/friend/module.go +++ b/modules/friend/module.go @@ -6,10 +6,12 @@ package friend import ( "context" "errors" + "fmt" "go_dreamfactory/comm" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" + "go_dreamfactory/sys/db" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" @@ -252,3 +254,31 @@ func (this *Friend) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (r return } + +func (this *Friend) UpdateUserBaseInfo(session comm.IUserSession, info *pb.BaseUserInfo) (err error) { + + if db.IsCross() { + err = this.modelFriend.Change(session.GetUserId(), map[string]interface{}{ + "info": info, + }) + } else { + var ( + model *db.DBModel + conn_ *db.DBConn + ) + // 跨服 + conn_, err = db.Cross() // 获取跨服数据库对象 + if err != nil { + return + } + if model = db.NewDBModelByExpired(comm.TableFriend, conn_); model == nil { + err = fmt.Errorf("cand found table :%s,%v", comm.TableFriend, conn_) + return + } + err = model.Change(session.GetUserId(), map[string]interface{}{ + "info": info, + }) + } + + return +} diff --git a/modules/user/api_create.go b/modules/user/api_create.go index 926ebf64d..c2c557832 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -2,6 +2,7 @@ package user import ( "go_dreamfactory/comm" + "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" @@ -92,6 +93,9 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (e update["avatar"] = globalConf.GirlHeadPortrait } user.Gender = req.Gender + user.Name = req.NickName + user.CurSkin = req.Skin + user.Gender = req.Gender session.SetMate(comm.Session_User, user) if err := this.module.modelUser.Change(session.GetUserId(), update); err != nil { errdata = &pb.ErrorData{ @@ -124,7 +128,27 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (e //异步逻辑 go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + baseInfo := &pb.BaseUserInfo{ + Uid: user.Uid, + Sid: user.Sid, + Name: user.Name, + Gender: user.Gender, + Skin: user.CurSkin, + Aframe: user.Curaframe, + Title: user.Curtitle, + Lv: user.Lv, + } + for _, m := range this.module.notifyUserinfo { + i, err := this.service.GetModule(core.M_Modules(m)) + if err != nil { + this.module.Errorln(err) + continue + } + if ic, ok := i.(comm.IUpdateUserBaseInfo); ok { + ic.UpdateUserBaseInfo(session, baseInfo) + } + } this.mail.SendMailByCid(session, comm.Welcomemail, nil) if len(tasks) > 0 { this.module.ModuleBuried.TriggerBuried(session, tasks...) diff --git a/modules/user/module.go b/modules/user/module.go index bd8c56032..087755d75 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -52,19 +52,20 @@ func NewModule() core.IModule { type User struct { modules.ModuleBase - chat comm.IChat - api *apiComp - modelUser *ModelUser - modelSession *ModelSession - modelSetting *ModelSetting - modelExpand *ModelExpand - service base.IRPCXService - configure *configureComp - globalConf *cfg.GameGlobalData - modelSign *ModelSign // 签到 - timerLock sync.Mutex - timerMap map[string]*time.Ticker - reddot comm.IReddot + chat comm.IChat + api *apiComp + modelUser *ModelUser + modelSession *ModelSession + modelSetting *ModelSetting + modelExpand *ModelExpand + service base.IRPCXService + configure *configureComp + globalConf *cfg.GameGlobalData + modelSign *ModelSign // 签到 + timerLock sync.Mutex + timerMap map[string]*time.Ticker + reddot comm.IReddot + notifyUserinfo []string // userinfo change } func (this *User) GetType() core.M_Modules { @@ -107,6 +108,7 @@ func (this *User) Start() (err error) { return } this.reddot = module.(comm.IReddot) + this.notifyUserinfo = append(this.notifyUserinfo, string(comm.ModuleFriend)) // 只要涉及到更新userinof 信息的模块在此注册 return }