From 93057ea1712fc6b2b4fdedcd0e840b9857bcea47 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Mon, 14 Nov 2022 15:55:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=A8=E5=B1=80=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 2 +- modules/friend/api_cross_addblack.go | 8 +------ modules/friend/api_cross_apply.go | 12 +++-------- modules/friend/api_cross_getreward.go | 2 +- modules/friend/api_cross_zan.go | 8 +------ modules/friend/api_cross_zanreceive.go | 8 +------ modules/friend/module.go | 7 +++++++ modules/sociaty/api_cross_apply.go | 8 +------ modules/sociaty/api_cross_create.go | 23 ++++++++++---------- modules/sociaty/api_cross_dismiss.go | 12 +++-------- modules/sociaty/api_cross_quit.go | 9 +------- modules/sociaty/api_cross_settingjob.go | 11 +++------- modules/sociaty/model_sociaty.go | 28 ++++++++++--------------- modules/sociaty/model_sociatytask.go | 10 +++------ modules/sociaty/module.go | 10 +++++++-- modules/user/api_create.go | 13 ++++-------- modules/user/api_modifyname.go | 4 ++-- modules/user/api_sign.go | 2 +- modules/user/model_session.go | 6 +++--- modules/user/model_sign.go | 2 +- modules/user/module.go | 17 ++++++++++----- services/comp_gateroute.go | 2 +- 22 files changed, 80 insertions(+), 124 deletions(-) diff --git a/comm/const.go b/comm/const.go index 18e0a0d61..a68f6f039 100644 --- a/comm/const.go +++ b/comm/const.go @@ -23,7 +23,7 @@ const ( ) const ( - RDS_SESSION = "" + RDS_EMPTY = "" ) //ERR diff --git a/modules/friend/api_cross_addblack.go b/modules/friend/api_cross_addblack.go index 527f201eb..eb7b2b4a6 100644 --- a/modules/friend/api_cross_addblack.go +++ b/modules/friend/api_cross_addblack.go @@ -21,12 +21,6 @@ func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackR return } - globalCnf := this.moduleFriend.configure.GetGlobalConf() - if globalCnf == nil { - code = pb.ErrorCode_ConfigNoFound - return - } - var ( err error self *pb.DBFriend @@ -76,7 +70,7 @@ func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackR } // 判断是否黑名单人数已满 - if len(self.BlackIds) >= int(globalCnf.FriendBlack) { + if len(self.BlackIds) >= int(this.moduleFriend.globalConf.FriendBlack) { code = pb.ErrorCode_FriendBlackMax return } diff --git a/modules/friend/api_cross_apply.go b/modules/friend/api_cross_apply.go index 9eabba4bc..540c733a3 100644 --- a/modules/friend/api_cross_apply.go +++ b/modules/friend/api_cross_apply.go @@ -22,12 +22,6 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c return } - globalCnf := this.moduleFriend.configure.GetGlobalConf() - if globalCnf == nil { - code = pb.ErrorCode_ConfigNoFound - return - } - var ( err error self *pb.DBFriend @@ -67,15 +61,15 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c code = pb.ErrorCode_FriendNotSelf return } - + globalConf := this.moduleFriend.globalConf //判断是否超过最大好友数量 - if len(self.FriendIds) >= int(globalCnf.FriendMaxnum) { + if len(self.FriendIds) >= int(globalConf.FriendMaxnum) { code = pb.ErrorCode_FriendSelfMax return } //判断对方是否也超过最大好友数量 - if len(target.FriendIds) >= int(globalCnf.FriendMaxnum) { + if len(target.FriendIds) >= int(globalConf.FriendMaxnum) { code = pb.ErrorCode_FriendTargetMax return } diff --git a/modules/friend/api_cross_getreward.go b/modules/friend/api_cross_getreward.go index d3d97af05..28fb19eec 100644 --- a/modules/friend/api_cross_getreward.go +++ b/modules/friend/api_cross_getreward.go @@ -35,7 +35,7 @@ func (this *apiComp) Getreward(session comm.IUserSession, req *pb.FriendGetrewar return } - code = this.moduleFriend.DispenseRes(session, this.moduleFriend.configure.GetGlobalConf().FriendPeize, true) + code = this.moduleFriend.DispenseRes(session, this.moduleFriend.globalConf.FriendPeize, true) rsp := &pb.FriendGetrewardResp{Received: int32(received)} diff --git a/modules/friend/api_cross_zan.go b/modules/friend/api_cross_zan.go index 87dd8835f..330973c9b 100644 --- a/modules/friend/api_cross_zan.go +++ b/modules/friend/api_cross_zan.go @@ -27,12 +27,6 @@ func (this *apiComp) Zan(session comm.IUserSession, req *pb.FriendZanReq) (code selfId string ) - globalCnf := this.moduleFriend.configure.GetGlobalConf() - if globalCnf == nil { - code = pb.ErrorCode_ConfigNoFound - return - } - selfId = session.GetUserId() // 不能给自己点赞 @@ -76,7 +70,7 @@ func (this *apiComp) Zan(session comm.IUserSession, req *pb.FriendZanReq) (code } // 今日送出的友情点是否达到上限 - if ue.FriendPointOD >= globalCnf.FriendMaxsendnum { + if ue.FriendPointOD >= this.moduleFriend.globalConf.FriendMaxsendnum { code = pb.ErrorCode_FriendPointLimit return } diff --git a/modules/friend/api_cross_zanreceive.go b/modules/friend/api_cross_zanreceive.go index 84a216162..6ec4bd0cc 100644 --- a/modules/friend/api_cross_zanreceive.go +++ b/modules/friend/api_cross_zanreceive.go @@ -22,12 +22,6 @@ func (this *apiComp) Zanreceive(session comm.IUserSession, req *pb.FriendZanrece return } - globalCnf := this.moduleFriend.configure.GetGlobalConf() - if globalCnf == nil { - code = pb.ErrorCode_ConfigNoFound - return - } - var ( self *pb.DBFriend err error @@ -68,7 +62,7 @@ func (this *apiComp) Zanreceive(session comm.IUserSession, req *pb.FriendZanrece } // 今日获赠的友情点是否达到上限 - if ue.FriendPointID >= int32(globalCnf.FriendMaxgetnum) { + if ue.FriendPointID >= int32(this.moduleFriend.globalConf.FriendMaxgetnum) { code = pb.ErrorCode_FriendPointLimit return } diff --git a/modules/friend/module.go b/modules/friend/module.go index 9a87fa795..d888087f7 100644 --- a/modules/friend/module.go +++ b/modules/friend/module.go @@ -16,6 +16,8 @@ import ( "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" + cfg "go_dreamfactory/sys/configure/structs" + "github.com/spf13/cast" ) @@ -32,6 +34,7 @@ type Friend struct { modelFriend *ModelFriend configure *modules.MCompConfigure service base.IRPCXService + globalConf *cfg.GameGlobalData } func (this *Friend) GetType() core.M_Modules { @@ -53,6 +56,10 @@ func (this *Friend) OnInstallComp() { func (this *Friend) Start() (err error) { err = this.ModuleBase.Start() this.service.RegisterFunctionName(string(comm.Rpc_ModuleFriendUseAssitHero), this.RpcUseAssisHero) + this.globalConf = this.configure.GetGlobalConf() + if this.globalConf == nil { + err = errors.New("global config not found") + } return } diff --git a/modules/sociaty/api_cross_apply.go b/modules/sociaty/api_cross_apply.go index b71e16ab6..681b7eadb 100644 --- a/modules/sociaty/api_cross_apply.go +++ b/modules/sociaty/api_cross_apply.go @@ -20,12 +20,6 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.SociatyApplyReq) ( if code = this.ApplyCheck(session, req); code != pb.ErrorCode_Success { return } - // 全局配置 - ggd := this.module.configure.GetGlobalConf() - if ggd == nil { - code = pb.ErrorCode_ConfigNoFound - return - } uid := session.GetUserId() @@ -78,7 +72,7 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.SociatyApplyReq) ( } //判断申请人数是否超出最大允许申请数 - if len(sociaty.ApplyRecord) >= int(ggd.GuildAcceptApplyMax) { + if len(sociaty.ApplyRecord) >= int(this.module.globalConf.GuildAcceptApplyMax) { code = pb.ErrorCode_SociatyApplyMax return } diff --git a/modules/sociaty/api_cross_create.go b/modules/sociaty/api_cross_create.go index 1c674016a..f62545548 100644 --- a/modules/sociaty/api_cross_create.go +++ b/modules/sociaty/api_cross_create.go @@ -1,6 +1,7 @@ package sociaty import ( + "errors" "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/utils" @@ -60,23 +61,21 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.SociatyCreateReq) } // 验证公会名是否重复 - if ok, err := this.module.modelSociaty.isNameExist(req.Name); ok { - if err != nil { - code = pb.ErrorCode_DBError - } else { - code = pb.ErrorCode_SociatyNameExist + if err := this.module.modelSociaty.isNameExist(req.Name); err != nil { + var customErr = new(comm.CustomError) + if errors.As(err, &customErr) { + if customErr.Code == pb.ErrorCode_SociatyNameExist { + code = pb.ErrorCode_SociatyNameExist + return + } } + code = pb.ErrorCode_DBError return } //检查钻石 - ggd := this.module.modelSociaty.moduleSociaty.configure.GetGlobalConf() - if ggd == nil { - code = pb.ErrorCode_ConfigNoFound - return - } - - if code = this.module.ConsumeRes(session, []*cfg.Gameatn{ggd.GuildBuildCos}, true); code != pb.ErrorCode_Success { + if code = this.module.ConsumeRes(session, []*cfg.Gameatn{ + this.module.globalConf.GuildBuildCos}, true); code != pb.ErrorCode_Success { return } diff --git a/modules/sociaty/api_cross_dismiss.go b/modules/sociaty/api_cross_dismiss.go index 4dd9ead8a..0048a6f5a 100644 --- a/modules/sociaty/api_cross_dismiss.go +++ b/modules/sociaty/api_cross_dismiss.go @@ -15,12 +15,6 @@ func (this *apiComp) DismissCheck(session comm.IUserSession, req *pb.SociatyDism } func (this *apiComp) Dismiss(session comm.IUserSession, req *pb.SociatyDismissReq) (code pb.ErrorCode, data proto.Message) { - // 全局配置 - ggd := this.module.configure.GetGlobalConf() - if ggd == nil { - code = pb.ErrorCode_ConfigNoFound - return - } uid := session.GetUserId() sociaty := this.module.modelSociaty.getUserSociaty(uid) if sociaty.Id == "" { @@ -40,10 +34,10 @@ func (this *apiComp) Dismiss(session comm.IUserSession, req *pb.SociatyDismissRe return } update := map[string]interface{}{} - + globalCnf := this.module.globalConf if sociaty.DismissTime == 0 { //更新解散倒计时 - update["dismissTime"] = utils.AddHour(int(ggd.GuildDissolutionCountDownCd)).Unix() + update["dismissTime"] = utils.AddHour(int(globalCnf.GuildDissolutionCountDownCd)).Unix() } else { if req.Dismiss == 1 { //取消解散 if utils.IsInCDHour(int64(sociaty.DismissCD)) { @@ -51,7 +45,7 @@ func (this *apiComp) Dismiss(session comm.IUserSession, req *pb.SociatyDismissRe return } else { // 设置冷区时间 - update["dismissCD"] = utils.AddHour(int(ggd.GuildDissolutionCd)).Unix() + update["dismissCD"] = utils.AddHour(int(globalCnf.GuildDissolutionCd)).Unix() } //取消倒计时 update["dismissTime"] = 0 diff --git a/modules/sociaty/api_cross_quit.go b/modules/sociaty/api_cross_quit.go index dd9e70163..d5e1e105c 100644 --- a/modules/sociaty/api_cross_quit.go +++ b/modules/sociaty/api_cross_quit.go @@ -16,13 +16,6 @@ func (this *apiComp) QuitCheck(session comm.IUserSession, req *pb.SociatyQuitReq func (this *apiComp) Quit(session comm.IUserSession, req *pb.SociatyQuitReq) (code pb.ErrorCode, data proto.Message) { uid := session.GetUserId() - // 全局配置 - ggd := this.module.configure.GetGlobalConf() - if ggd == nil { - code = pb.ErrorCode_ConfigNoFound - return - } - sociaty := this.module.modelSociaty.getUserSociaty(uid) if sociaty.Id == "" { code = pb.ErrorCode_SociatyNoFound @@ -46,7 +39,7 @@ func (this *apiComp) Quit(session comm.IUserSession, req *pb.SociatyQuitReq) (co //更新玩家sociatyId update := map[string]interface{}{ "sociatyId": "", //玩家公会ID置空 - "sociatyCd": utils.AddHour(int(ggd.GuildRejoinCd)).Unix(), + "sociatyCd": utils.AddHour(int(this.module.globalConf.GuildRejoinCd)).Unix(), } if err := this.module.ModuleUser.ChangeRemoteUserExpand(uid, update); err != nil { diff --git a/modules/sociaty/api_cross_settingjob.go b/modules/sociaty/api_cross_settingjob.go index 21e126eb4..528f98e88 100644 --- a/modules/sociaty/api_cross_settingjob.go +++ b/modules/sociaty/api_cross_settingjob.go @@ -19,12 +19,6 @@ func (this *apiComp) SettingJob(session comm.IUserSession, req *pb.SociatySettin if code = this.SettingJobCheck(session, req); code != pb.ErrorCode_Success { return } - // 全局配置 - ggd := this.module.configure.GetGlobalConf() - if ggd == nil { - code = pb.ErrorCode_ConfigNoFound - return - } uid := session.GetUserId() sociaty := this.module.modelSociaty.getUserSociaty(uid) @@ -42,9 +36,10 @@ func (this *apiComp) SettingJob(session comm.IUserSession, req *pb.SociatySettin } // 判断职位人数 + globalConf := this.module.globalConf jobCount := this.module.modelSociaty.getJobCount(req.Job, sociaty) - if req.Job == pb.SociatyJob_VICEPRESIDENT && jobCount >= int(ggd.GuildViceAllianceLeaderMaxNum) || - req.Job == pb.SociatyJob_ADMIN && jobCount >= int(ggd.GuildAdministratorsMaxNum) { + if req.Job == pb.SociatyJob_VICEPRESIDENT && jobCount >= int(globalConf.GuildViceAllianceLeaderMaxNum) || + req.Job == pb.SociatyJob_ADMIN && jobCount >= int(globalConf.GuildAdministratorsMaxNum) { code = pb.ErrorCode_SociatyMemberCountLimit return } diff --git a/modules/sociaty/model_sociaty.go b/modules/sociaty/model_sociaty.go index d5e472734..b36afdc68 100644 --- a/modules/sociaty/model_sociaty.go +++ b/modules/sociaty/model_sociaty.go @@ -72,21 +72,21 @@ func (this *ModelSociaty) create(sociaty *pb.DBSociaty) error { if sociaty.ApplyLv == 0 { sociaty.ApplyLv = 1 //默认玩家入会等级 } - return this.AddList("", sociaty.Id, sociaty) + return this.AddList(comm.RDS_EMPTY, sociaty.Id, sociaty) } // 公会名是否存在 -func (this *ModelSociaty) isNameExist(name string) (bool, error) { +func (this *ModelSociaty) isNameExist(name string) error { var sociaties []*pb.DBSociaty - if err := this.GetList("", &sociaties); err != nil { - return false, err + if err := this.GetList(comm.RDS_EMPTY, &sociaties); err != nil { + return err } for _, s := range sociaties { if s.Name == name { - return true, nil + return comm.NewCustomError(pb.ErrorCode_SociatyNameExist) } } - return false, nil + return nil } // 公会列表 @@ -179,7 +179,7 @@ func (this *ModelSociaty) isDismiss(sociaty *pb.DBSociaty) bool { if sociaty.DismissTime == 0 { return false } - if utils.IsInCDHour(sociaty.DismissTime) { // + if utils.IsInCDHour(sociaty.DismissTime) { return false } else { if err := this.dismiss(sociaty); err != nil { @@ -576,20 +576,18 @@ func (this *ModelSociaty) accuse(sociaty *pb.DBSociaty) error { if err != nil { return err } - ggd := this.moduleSociaty.configure.GetGlobalConf() - if ggd == nil { - return errors.New("config not found") - } + + globalCnf := this.moduleSociaty.globalConf //会长离线时间 now := configure.Now().Unix() left := now - user.Offlinetime - if left < int64(ggd.GuildInitiateImpeachmentTime*3600) || user.Offlinetime == 0 { + if left < int64(globalCnf.GuildInitiateImpeachmentTime*3600) || user.Offlinetime == 0 { return errors.New("会长很称职,无需弹劾") } else { //更新会长的弹劾倒计时时间 update := map[string]interface{}{ - "accuseTime": utils.AddHour(int(ggd.GuildImpeachmentCountDown)).Unix(), + "accuseTime": utils.AddHour(int(globalCnf.GuildImpeachmentCountDown)).Unix(), } return this.updateSociaty(sociaty.Id, update) } @@ -599,10 +597,6 @@ func (this *ModelSociaty) accuse(sociaty *pb.DBSociaty) error { // srcMasterId 原会长ID func (this *ModelSociaty) extendJob(srcMasterId string, sociaty *pb.DBSociaty) error { if sociaty.AccuseTime != 0 { - ggd := this.moduleSociaty.configure.GetGlobalConf() - if ggd == nil { - return errors.New("config not found") - } //终止弹劾 now := configure.Now().Unix() if now < sociaty.AccuseTime { diff --git a/modules/sociaty/model_sociatytask.go b/modules/sociaty/model_sociatytask.go index 7c2d9d5f8..b9aebdaf2 100644 --- a/modules/sociaty/model_sociatytask.go +++ b/modules/sociaty/model_sociatytask.go @@ -37,15 +37,11 @@ func (this *ModelSociatyTask) initSociatyTask(uid, sociatyId string) error { var taskList []*pb.SociatyTask list := ggt.GetDataList() - ggd := this.moduleSociaty.configure.GetGlobalConf() - if ggd == nil { - return errors.New("config not found") - } - + globalConf := this.moduleSociaty.globalConf // 大于4条配置 - if len(list) > int(ggd.GuildTaskNum) { + if len(list) > int(globalConf.GuildTaskNum) { //随机4条任务 - randInts := utils.RandomNumbers(0, len(list)-1, int(ggd.GuildTaskNum)) + randInts := utils.RandomNumbers(0, len(list)-1, int(globalConf.GuildTaskNum)) for _, v := range randInts { taskList = append(taskList, &pb.SociatyTask{ TaskId: list[v].TypeId, diff --git a/modules/sociaty/module.go b/modules/sociaty/module.go index ed04585b3..81efddd2c 100644 --- a/modules/sociaty/module.go +++ b/modules/sociaty/module.go @@ -5,6 +5,7 @@ package sociaty import ( "context" + "errors" "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" @@ -12,6 +13,7 @@ import ( "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" + cfg "go_dreamfactory/sys/configure/structs" ) var _ comm.ISociaty = (*Sociaty)(nil) @@ -24,6 +26,7 @@ type Sociaty struct { modelSociatyTask *ModelSociatyTask modelSociatyLog *ModelSociatyLog configure *configureComp + globalConf *cfg.GameGlobalData } func NewModule() core.IModule { @@ -52,14 +55,17 @@ func (this *Sociaty) OnInstallComp() { func (this *Sociaty) Start() (err error) { err = this.ModuleBase.Start() this.service.RegisterFunctionName(string(comm.Rpc_ModuleSociaty), this.RpcGetSociaty) + this.globalConf = this.configure.GetGlobalConf() + if this.globalConf == nil { + err = errors.New("global config not found") + } return } // 会长弹劾处理 // Deprecated func (this *Sociaty) ProcessAccuse(uid, sociatyId string) { - ggd := this.configure.GetGlobalConf() - t := ggd.GuildImpeachmentCountDown + t := this.globalConf.GuildImpeachmentCountDown if t == 0 { return } diff --git a/modules/user/api_create.go b/modules/user/api_create.go index 654624865..2b0c879af 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -43,12 +43,6 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c return } - gConf := this.module.configure.GetGlobalConf() - if gConf == nil { - code = pb.ErrorCode_ConfigNoFound - return - } - update := map[string]interface{}{ "name": req.NickName, //设置昵称 "created": true, //创角标识 @@ -56,12 +50,13 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c "gender": req.Gender, //设置性别 } + globalConf := this.module.globalConf if req.Gender == 0 { - update["avatar"] = gConf.BoyHeadPortrait + update["avatar"] = globalConf.BoyHeadPortrait } else if req.Gender == 1 { - update["avatar"] = gConf.GirlHeadPortrait + update["avatar"] = globalConf.GirlHeadPortrait } - + if err := this.module.modelUser.Change(session.GetUserId(), update); err != nil { code = pb.ErrorCode_DBError this.module.Errorf("创角失败 uid:%v name:%v err:%v", session.GetUserId(), req.NickName, err) diff --git a/modules/user/api_modifyname.go b/modules/user/api_modifyname.go index f02603578..3ccf9143c 100644 --- a/modules/user/api_modifyname.go +++ b/modules/user/api_modifyname.go @@ -35,11 +35,11 @@ func (this *apiComp) Modifyname(session comm.IUserSession, req *pb.UserModifynam //校验名称修改次数 if expand.ModifynameCount <= 0 { - code = this.module.ConsumeRes(session, this.module.configure.GetGlobalConf().HeroName, true) + code = this.module.ConsumeRes(session, this.module.globalConf.HeroName, true) if code != pb.ErrorCode_Success { return } - this.module.Infof("修改昵称 uid:%v 消耗:%v code:%v", session.GetUserId(), this.module.configure.GetGlobalConf().HeroName, code) + this.module.Infof("修改昵称 uid:%v 消耗:%v code:%v", session.GetUserId(), this.module.globalConf.HeroName, code) } //修改名称次数 diff --git a/modules/user/api_sign.go b/modules/user/api_sign.go index 6af680f86..dd8e0d941 100644 --- a/modules/user/api_sign.go +++ b/modules/user/api_sign.go @@ -61,7 +61,7 @@ func (this *apiComp) Sign(session comm.IUserSession, req *pb.UserSignReq) (code } } else { if bReward { - this.module.DispenseRes(session, this.module.configure.GetGlobalConf().UnifiedReward, true) // 发放通用奖励 + this.module.DispenseRes(session, this.module.globalConf.UnifiedReward, true) // 发放通用奖励 } } session.SendMsg(string(this.module.GetType()), "sign", &pb.UserSignResp{ diff --git a/modules/user/model_session.go b/modules/user/model_session.go index cf66f02e6..aba4bbab4 100644 --- a/modules/user/model_session.go +++ b/modules/user/model_session.go @@ -34,7 +34,7 @@ func (this *ModelSession) Start() (err error) { //获取用户 func (this *ModelSession) getUserSession(uid string) (user *pb.CacheUser) { user = &pb.CacheUser{} - if err := this.GetListObj(comm.RDS_SESSION, uid, user); err != nil { + if err := this.GetListObj(comm.RDS_EMPTY, uid, user); err != nil { if err != mongo.ErrNoDocuments { this.module.Errorln(err) } @@ -45,7 +45,7 @@ func (this *ModelSession) getUserSession(uid string) (user *pb.CacheUser) { //设置用户session func (this *ModelSession) addUserSession(uid string, session comm.IUserSession) (err error) { - if err = this.AddList(comm.RDS_SESSION, uid, map[string]interface{}{ + if err = this.AddList(comm.RDS_EMPTY, uid, map[string]interface{}{ "uid": uid, "sessionId": session.GetSessionId(), "serviceTag": session.GetServiecTag(), @@ -60,7 +60,7 @@ func (this *ModelSession) addUserSession(uid string, session comm.IUserSession) // 启动时清理session func (this *ModelSession) clean(key string) { - keys, err := this.Redis.Keys(fmt.Sprintf("session:%s-%s_*", comm.RDS_SESSION, key)) + keys, err := this.Redis.Keys(fmt.Sprintf("session:%s-%s_*", comm.RDS_EMPTY, key)) if err != nil { log.Errorf("redis keys err:%v", err) return diff --git a/modules/user/model_sign.go b/modules/user/model_sign.go index afcd632f9..80c3a7ff9 100644 --- a/modules/user/model_sign.go +++ b/modules/user/model_sign.go @@ -114,7 +114,7 @@ func (this *ModelSign) checkResetSignData(session comm.IUserSession) (code pb.Er } } else { if bReward { - this.module.DispenseRes(session, this.module.configure.GetGlobalConf().UnifiedReward, true) // 发放通用奖励 + this.module.DispenseRes(session, this.module.globalConf.UnifiedReward, true) // 发放通用奖励 } } session.SendMsg(string(this.module.GetType()), "sign", &pb.UserSignResp{ diff --git a/modules/user/module.go b/modules/user/module.go index 061d00daf..5de6bf409 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -18,6 +18,8 @@ import ( "go_dreamfactory/lego/sys/event" "go_dreamfactory/lego/sys/log" + cfg "go_dreamfactory/sys/configure/structs" + "github.com/pkg/errors" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" @@ -50,6 +52,7 @@ type User struct { modelExpand *ModelExpand service base.IRPCXService configure *configureComp + globalConf *cfg.GameGlobalData modelSign *ModelSign // 签到 } @@ -70,6 +73,10 @@ func (this *User) Start() (err error) { this.service.RegisterFunctionName(Rpc_GetCrossUser, this.RpcGetCrossUser) this.service.RegisterFunctionName(Rpc_GetCrossUserSession, this.RpcGetCrossUserSession) this.service.RegisterFunctionName(Rpc_QueryUser, this.RpcQueryUser) + this.globalConf = this.configure.GetGlobalConf() + if this.globalConf == nil { + err = errors.New("global config not found") + } return } @@ -134,9 +141,9 @@ func (this *User) CleanSession(session comm.IUserSession) { if !this.IsCross() { this.modelUser.updateOfflineTime(session.GetUserId()) } - sId := fmt.Sprintf("%s-%s", comm.RDS_SESSION, session.GetUserId()) + sId := fmt.Sprintf("%s-%s", comm.RDS_EMPTY, session.GetUserId()) this.modelSession.Del(sId, db.SetDBMgoLog(false)) - this.modelSession.DelListlds(comm.RDS_SESSION, session.GetUserId()) + this.modelSession.DelListlds(comm.RDS_EMPTY, session.GetUserId()) this.modelUser.DelByUId(session.GetUserId(), db.SetDBMgoLog(false)) this.modelExpand.DelByUId(session.GetUserId(), db.SetDBMgoLog(false)) this.modelSetting.DelByUId(session.GetUserId(), db.SetDBMgoLog(false)) @@ -145,7 +152,7 @@ func (this *User) CleanSession(session comm.IUserSession) { // 在线玩家列表 func (this *User) UserOnlineList() ([]*pb.CacheUser, error) { var cache []*pb.CacheUser - if err := this.modelSession.GetList(comm.RDS_SESSION, &cache); err != nil { + if err := this.modelSession.GetList(comm.RDS_EMPTY, &cache); err != nil { return nil, err } return cache, nil @@ -521,7 +528,7 @@ func (this *User) RpcGetAllOnlineUser(ctx context.Context, args *pb.EmptyReq, re } model := db.NewDBModel(comm.TableSession, 0, conn) var cache []*pb.CacheUser - if err := model.GetList(comm.RDS_SESSION, &cache); err != nil { + if err := model.GetList(comm.RDS_EMPTY, &cache); err != nil { return err } reply.Users = cache @@ -538,7 +545,7 @@ func (this *User) RpcGetCrossUserSession(ctx context.Context, req *pb.UIdReq, re return err } model := db.NewDBModel(comm.TableSession, 0, conn) - if err := model.GetListObj(comm.RDS_SESSION, req.Uid, reply); err != nil { + if err := model.GetListObj(comm.RDS_EMPTY, req.Uid, reply); err != nil { if err != mongo.ErrNoDocuments { return err } diff --git a/services/comp_gateroute.go b/services/comp_gateroute.go index d537543f1..ec682eaca 100644 --- a/services/comp_gateroute.go +++ b/services/comp_gateroute.go @@ -188,7 +188,7 @@ func (this *SCompGateRoute) NoticeUserLogin(ctx context.Context, args *pb.Notice return err } model := db.NewDBModel(comm.TableSession, 0, conn) - model.AddList(comm.RDS_SESSION, args.UserId, map[string]interface{}{ + model.AddList(comm.RDS_EMPTY, args.UserId, map[string]interface{}{ "uid": args.UserId, "sessionId": args.UserSessionId, "serviceTag": args.ServiceTag,