diff --git a/comm/const.go b/comm/const.go index 5ef705984..f1cde8be9 100644 --- a/comm/const.go +++ b/comm/const.go @@ -575,3 +575,46 @@ const ( Yueka_1 string = "Activity_PrivilegeCardDailyReward_lv1" Yueka_2 string = "Activity_PrivilegeCardDailyReward_lv2" ) + +// open funcName +const ( + Hero = "hero" + Backpack = "backpack" + Shop = "shop" + Friend = "friend" + Mall = "mall" + Rdtask = "rdtask" + Currency = "currency" + Alliance = "alliance" + Task = "task" + Trials = "trials" + Moon = "moon" + Story = "story" + Kungfu = "kungfu" + Event = "event" + MistyIsland = "mistyIsland" + Vikingexpedition = "vikingexpedition" + Vikingexpedition2 = "vikingexpedition2" + Vikingexpedition3 = "vikingexpedition3" + HjeartDemonTower = "hjeart demon tower" + Catchsheep = "catchsheep" + Darkcuisine = "darkcuisine" + UndergroundArena = "underground Arena" + Crazycompetition = "crazycompetition" + Fiveheroeschallenge = "fiveheroeschallenge" + Library = "library" + Bonfiredance = "bonfiredance" + Caravan = "caravan" + Gourmetrestaurant = "gourmetrestaurant" + Goberblacksmithshop = "goberblacksmithshop" + Hunting = "hunting" + Channel_lock_icon = "channel_lock_icon" + Channel_lock_world = "channel_lock_world" + Channel_lock_guild = "channel_lock_guild" + Channel_lock_private = "channel_lock_private" + Channel_lock_public = "channel_lock_public" + Channel_lock_system = "channel_lock_system" + Guild = "guild" + Arena = "arena" + Sign = "sign" +) diff --git a/comm/imodule.go b/comm/imodule.go index 4ba88f88b..2f2514e50 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -16,7 +16,7 @@ type ( type ( ISys interface { - IsAccess(funcName string, userLv int32) bool + IsAccess(funcName string, uid string) bool } //邮件业务模块对外接口定义 提供给其他模块使用的 @@ -90,8 +90,6 @@ type ( IUser interface { //获取本服用户数据 GetUser(uid string) *pb.DBUser - // 获取跨服用户数据 - GetCrossUser(uid string) (*pb.DBUser, error) //获取用户回话 GetUserSession(uid string) *pb.CacheUser //查询用户属性值 例如 金币 经验 @@ -114,14 +112,9 @@ type ( CrossUserSession(uid string) *pb.CacheUser // 跨服搜索玩家 CrossSearchUser(nickname string) ([]*pb.DBUser, error) - // 获取远程用户 - GetRemoteUser(uid string) (*pb.DBUser, error) // 搜索远程用户 SearchRmoteUser(nickname string) ([]*pb.DBUser, error) - // 获取远程用户expand - GetRemoteUserExpand(uid string) (result *pb.DBUserExpand, err error) - // 更新远程用户expand - ChangeRemoteUserExpand(uid string, value map[string]interface{}) error + } //武器模块 IEquipment interface { diff --git a/modules/friend/api.go b/modules/friend/api.go index cb03888ea..e6b7913d8 100644 --- a/modules/friend/api.go +++ b/modules/friend/api.go @@ -2,7 +2,6 @@ package friend import ( "go_dreamfactory/lego/core" - "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" ) @@ -41,19 +40,15 @@ func (this *apiComp) Init(service core.IService, module core.IModule, comp core. } func (this *apiComp) setDefaultFriendUserBaseInfo(userId string) *pb.FriendBase { - if user, err := this.moduleFriend.ModuleUser.GetRemoteUser(userId); err != nil { - this.moduleFriend.Error("GetRmoteUser", log.Fields{"err": err.Error()}) - return nil - } else { - if user != nil { - return &pb.FriendBase{ - ServerId: user.Sid, - UserId: userId, - NickName: user.Name, - Level: user.Lv, - Avatar: user.Avatar, - OfflineTime: user.Offlinetime, - } + user := this.moduleFriend.ModuleUser.GetUser(userId) + if user != nil { + return &pb.FriendBase{ + ServerId: user.Sid, + UserId: userId, + NickName: user.Name, + Level: user.Lv, + Avatar: user.Avatar, + OfflineTime: user.Offlinetime, } } diff --git a/modules/friend/api_cross_agree.go b/modules/friend/api_cross_agree.go index 740f1ea4a..16faeb3fe 100644 --- a/modules/friend/api_cross_agree.go +++ b/modules/friend/api_cross_agree.go @@ -42,11 +42,8 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (c agreeIds := []string{} for _, friendId := range req.FriendIds { // 验证friendId是否有效 - user, err := this.moduleFriend.ModuleUser.GetRemoteUser(friendId) - if err != nil { - continue - } - if user.Uid == "" { + user := this.moduleFriend.ModuleUser.GetUser(friendId) + if user == nil { continue } if _, ok := utils.Find(self.FriendIds, friendId); !ok { diff --git a/modules/gourmet/api_getranduser.go b/modules/gourmet/api_getranduser.go index 57d1eed04..dcaa0b710 100644 --- a/modules/gourmet/api_getranduser.go +++ b/modules/gourmet/api_getranduser.go @@ -85,7 +85,7 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.GourmetGetRa } } for k := range mapUser { - if user, err := this.module.ModuleUser.GetRemoteUser(k); err == nil && user.Uid != "" { + if user := this.module.ModuleUser.GetUser(k); user != nil { szDbUser = append(szDbUser, user) // 转成user对象 } else { this.module.Errorf("%v", err) diff --git a/modules/smithy/api_getranduser.go b/modules/smithy/api_getranduser.go index a545de272..8389d55d7 100644 --- a/modules/smithy/api_getranduser.go +++ b/modules/smithy/api_getranduser.go @@ -85,7 +85,7 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.SmithyGetRan } } for k := range mapUser { - if user, err := this.module.ModuleUser.GetRemoteUser(k); err == nil && user.Uid != "" { + if user := this.module.ModuleUser.GetUser(k); user != nil { szDbUser = append(szDbUser, user) // 转成user对象 } else { this.module.Errorf("%v", err) diff --git a/modules/sociaty/api_cross_apply.go b/modules/sociaty/api_cross_apply.go index a992338ac..9ec538245 100644 --- a/modules/sociaty/api_cross_apply.go +++ b/modules/sociaty/api_cross_apply.go @@ -35,7 +35,7 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.SociatyApplyReq) ( } // userex - userEx, err := this.module.ModuleUser.GetRemoteUserExpand(uid) + userEx, err := this.module.ModuleUser.GetUserExpand(uid) if err != nil { this.module.Error("GetRemoteUserExpand", log.Fields{"uid": uid, "err": err.Error()}) code = pb.ErrorCode_UserSessionNobeing @@ -53,12 +53,7 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.SociatyApplyReq) ( return } - user, err := this.module.ModuleUser.GetRemoteUser(uid) - if err != nil { - code = pb.ErrorCode_DBError - return - } - + user := this.module.ModuleUser.GetUser(uid) if user == nil { code = pb.ErrorCode_UserSessionNobeing return diff --git a/modules/sociaty/api_cross_create.go b/modules/sociaty/api_cross_create.go index d6c5cfbd2..04521853b 100644 --- a/modules/sociaty/api_cross_create.go +++ b/modules/sociaty/api_cross_create.go @@ -29,20 +29,14 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.SociatyCreateReq) } uid := session.GetUserId() - - user, err := this.module.ModuleUser.GetRemoteUser(uid) - if err != nil { - code = pb.ErrorCode_DBError - return - } - - if user.Uid == "" { + user := this.module.ModuleUser.GetUser(uid) + if user == nil{ this.module.Error("GetRmoteUser not found", log.Fields{"uid": uid}) code = pb.ErrorCode_UserSessionNobeing return } - userExpand, err := this.module.ModuleUser.GetRemoteUserExpand(uid) + userExpand, err := this.module.ModuleUser.GetUserExpand(uid) if err != nil { code = pb.ErrorCode_DBError return @@ -111,7 +105,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.SociatyCreateReq) "sociatyId": sociaty.Id, } - if err = this.module.ModuleUser.ChangeRemoteUserExpand(user.Uid, update); err != nil { + if err = this.module.ModuleUser.ChangeUserExpand(user.Uid, update); err != nil { code = pb.ErrorCode_DBError this.module.Error("更新玩家公会ID", log.Fields{"uid": uid, "sociatyId": sociaty.Id, "err": err.Error()}) return diff --git a/modules/sociaty/api_cross_discharge.go b/modules/sociaty/api_cross_discharge.go index 44ca08375..7f444e377 100644 --- a/modules/sociaty/api_cross_discharge.go +++ b/modules/sociaty/api_cross_discharge.go @@ -62,7 +62,7 @@ func (this *apiComp) Discharge(session comm.IUserSession, req *pb.SociatyDischar "sociatyId": "", //公会ID置空 } - if err := this.module.ModuleUser.ChangeRemoteUserExpand(req.TargetId, update); err != nil { + if err := this.module.ModuleUser.ChangeUserExpand(req.TargetId, update); err != nil { code = pb.ErrorCode_DBError this.module.Error("更新玩家公会ID", log.Fields{"uid": uid, "被踢人": req.TargetId, "err": err.Error()}) return diff --git a/modules/sociaty/api_cross_list.go b/modules/sociaty/api_cross_list.go index 6f1a5265e..da4904c5f 100644 --- a/modules/sociaty/api_cross_list.go +++ b/modules/sociaty/api_cross_list.go @@ -18,6 +18,7 @@ func (this *apiComp) ListCheck(session comm.IUserSession, req *pb.SociatyListReq } func (this *apiComp) List(session comm.IUserSession, req *pb.SociatyListReq) (code pb.ErrorCode, data proto.Message) { + // this.module.ModuleSys.IsAccess(comm.Guild, userLv int32) if code = this.ListCheck(session, req); code != pb.ErrorCode_Success { return } diff --git a/modules/sociaty/api_cross_mine.go b/modules/sociaty/api_cross_mine.go index 3b171dcfd..d66eb7ddf 100644 --- a/modules/sociaty/api_cross_mine.go +++ b/modules/sociaty/api_cross_mine.go @@ -17,7 +17,7 @@ func (this *apiComp) MineCheck(session comm.IUserSession, req *pb.SociatyMineReq func (this *apiComp) Mine(session comm.IUserSession, req *pb.SociatyMineReq) (code pb.ErrorCode, data proto.Message) { uid := session.GetUserId() - userEx, err := this.module.ModuleUser.GetRemoteUserExpand(uid) + userEx, err := this.module.ModuleUser.GetUserExpand(uid) if err != nil { this.module.Error("GetRemoteUserExpand", log.Fields{"uid": uid, "err": err}) code = pb.ErrorCode_UserSessionNobeing diff --git a/modules/sociaty/api_cross_quit.go b/modules/sociaty/api_cross_quit.go index 7eaf00543..41a82f8c0 100644 --- a/modules/sociaty/api_cross_quit.go +++ b/modules/sociaty/api_cross_quit.go @@ -44,7 +44,7 @@ func (this *apiComp) Quit(session comm.IUserSession, req *pb.SociatyQuitReq) (co "sociatyCd": utils.AddHour(int(this.module.globalConf.GuildRejoinCd)).Unix(), } - if err := this.module.ModuleUser.ChangeRemoteUserExpand(uid, update); err != nil { + if err := this.module.ModuleUser.ChangeUserExpand(uid, update); err != nil { code = pb.ErrorCode_DBError this.module.Error("退出公会,更新玩家公会ID", log.Fields{"uid": uid, "sociatyId": sociaty.Id, "err": err.Error()}) return diff --git a/modules/sociaty/model_sociaty.go b/modules/sociaty/model_sociaty.go index 69306c56e..759641aea 100644 --- a/modules/sociaty/model_sociaty.go +++ b/modules/sociaty/model_sociaty.go @@ -90,10 +90,10 @@ func (this *ModelSociaty) isNameExist(name string) error { // 公会列表 func (this *ModelSociaty) list(uid string, filter pb.SociatyListFilter) (list []*pb.DBSociaty) { - user, err := this.moduleSociaty.ModuleUser.GetRemoteUser(uid) - if err != nil { - return - } + user := this.moduleSociaty.ModuleUser.GetUser(uid) + // if err != nil { + // return + // } if user == nil { return } @@ -196,7 +196,7 @@ func (this *ModelSociaty) getUserSociaty(uid string) (sociaty *pb.DBSociaty) { err error ) if this.moduleSociaty.IsCross() { - userEx, err = this.moduleSociaty.ModuleUser.GetRemoteUserExpand(uid) + userEx, err = this.moduleSociaty.ModuleUser.GetUserExpand(uid) if err != nil { return } @@ -232,7 +232,7 @@ func (this *ModelSociaty) getUserSociaty(uid string) (sociaty *pb.DBSociaty) { } // 申请公会 -func (this *ModelSociaty) apply(uid string, sociaty *pb.DBSociaty) (isCheck bool,err error) { +func (this *ModelSociaty) apply(uid string, sociaty *pb.DBSociaty) (isCheck bool, err error) { // 判断公会审批设置 if sociaty.IsApplyCheck { //需要审核 isCheck = true @@ -246,12 +246,12 @@ func (this *ModelSociaty) apply(uid string, sociaty *pb.DBSociaty) (isCheck bool err = this.updateSociaty(sociaty.Id, update) } else { //无需审核直接入会 if err := this.addMember(uid, sociaty); err != nil { - return isCheck,err + return isCheck, err } //初始玩家公会任务 this.moduleSociaty.modelSociatyTask.initSociatyTask(uid, sociaty.Id) } - return + return } // 设置公会 @@ -283,8 +283,8 @@ func (this *ModelSociaty) isApplied(uid string, sociaty *pb.DBSociaty) bool { // 申请列表 func (this *ModelSociaty) applyList(sociaty *pb.DBSociaty) (list []*pb.SociatyMemberInfo) { for _, r := range sociaty.ApplyRecord { - user, err := this.moduleSociaty.ModuleUser.GetRemoteUser(r.Uid) - if err != nil || user.Uid == "" { + user := this.moduleSociaty.ModuleUser.GetUser(r.Uid) + if user == nil { continue } @@ -399,7 +399,7 @@ func (this *ModelSociaty) addMember(uid string, sociaty *pb.DBSociaty) error { updateEx := map[string]interface{}{ "sociatyId": sociaty.Id, } - if err := this.moduleSociaty.ModuleUser.ChangeRemoteUserExpand(uid, updateEx); err != nil { + if err := this.moduleSociaty.ModuleUser.ChangeUserExpand(uid, updateEx); err != nil { return err } @@ -424,8 +424,8 @@ func (this *ModelSociaty) sendMail(confId string, params []string, receiver []st // 成员列表 func (this *ModelSociaty) members(sociaty *pb.DBSociaty) (list []*pb.SociatyMemberInfo) { for _, m := range sociaty.Members { - user, err := this.moduleSociaty.ModuleUser.GetRemoteUser(m.Uid) - if err != nil || user.Uid == "" { + user := this.moduleSociaty.ModuleUser.GetUser(m.Uid) + if user == nil { continue } list = append(list, &pb.SociatyMemberInfo{ @@ -534,8 +534,8 @@ func (this *ModelSociaty) settingJob(targetId string, job pb.SociatyJob, sociaty func (this *ModelSociaty) getMasterInfo(sociaty *pb.DBSociaty) *pb.SociatyMemberInfo { for _, m := range sociaty.Members { if m.Job == pb.SociatyJob_PRESIDENT { - user, err := this.moduleSociaty.ModuleUser.GetRemoteUser(m.Uid) - if err != nil || user.Uid == "" { + user := this.moduleSociaty.ModuleUser.GetUser(m.Uid) + if user == nil { continue } return &pb.SociatyMemberInfo{ @@ -557,9 +557,9 @@ func (this *ModelSociaty) accuse(sociaty *pb.DBSociaty) error { return comm.NewCustomError(pb.ErrorCode_SociatyNoMaster) } - user, err := this.moduleSociaty.ModuleUser.GetRemoteUser(master.Uid) - if err != nil { - return err + user := this.moduleSociaty.ModuleUser.GetUser(master.Uid) + if user == nil { + return comm.NewCustomError(pb.ErrorCode_UserSessionNobeing) } globalCnf := this.moduleSociaty.globalConf @@ -913,7 +913,7 @@ func (this *ModelSociaty) memberClear(sociaty *pb.DBSociaty) error { update := map[string]interface{}{ "sociatyId": "", //公会ID置空 } - if err := this.moduleSociaty.ModuleUser.ChangeRemoteUserExpand(m.Uid, update); err != nil { + if err := this.moduleSociaty.ModuleUser.ChangeUserExpand(m.Uid, update); err != nil { log.Errorf("更新玩家公会ID err:%v", err) } diff --git a/modules/sociaty/model_sociatylog.go b/modules/sociaty/model_sociatylog.go index 55164e545..9918eb01e 100644 --- a/modules/sociaty/model_sociatylog.go +++ b/modules/sociaty/model_sociatylog.go @@ -40,8 +40,8 @@ func (this *ModelSociatyLog) addLog(tag Tag, sociatyId string, params ...string) return comm.NewCustomError(pb.ErrorCode_SociatyLogParams) } for i := 0; i < len(params); i++ { - user, err := this.moduleSociaty.ModuleUser.GetRemoteUser(params[i]) - if err == nil && user.Uid != "" { + user := this.moduleSociaty.ModuleUser.GetUser(params[i]) + if user != nil { content = strings.Replace(content, "%s", user.Name, 1) } } @@ -52,8 +52,8 @@ func (this *ModelSociatyLog) addLog(tag Tag, sociatyId string, params ...string) return comm.NewCustomError(pb.ErrorCode_SociatyLogParams) } for i := 0; i < len(params); i++ { - user, err := this.moduleSociaty.ModuleUser.GetRemoteUser(params[i]) - if err == nil && user.Uid != "" { + user := this.moduleSociaty.ModuleUser.GetUser(params[i]) + if user != nil { content = strings.Replace(content, "%s", user.Name, 1) } } @@ -78,8 +78,8 @@ func (this *ModelSociatyLog) addLog(tag Tag, sociatyId string, params ...string) } content = strings.Replace(content, "%s", job, 1) } else { - user, err := this.moduleSociaty.ModuleUser.GetRemoteUser(params[i]) - if err == nil && user.Uid != "" { + user := this.moduleSociaty.ModuleUser.GetUser(params[i]) + if user != nil { content = strings.Replace(content, "%s", user.Name, 1) } } @@ -91,8 +91,8 @@ func (this *ModelSociatyLog) addLog(tag Tag, sociatyId string, params ...string) return comm.NewCustomError(pb.ErrorCode_SociatyLogParams) } for i := 0; i < len(params); i++ { - user, err := this.moduleSociaty.ModuleUser.GetRemoteUser(params[i]) - if err == nil && user.Uid != "" { + user := this.moduleSociaty.ModuleUser.GetUser(params[i]) + if user != nil { content = strings.Replace(content, "%s", params[i], 1) } } diff --git a/modules/sys/model_sys.go b/modules/sys/model_sys.go index e6feddb94..153401831 100644 --- a/modules/sys/model_sys.go +++ b/modules/sys/model_sys.go @@ -21,10 +21,14 @@ func (this *ModelSys) Init(service core.IService, module core.IModule, comp core } // 是否允许访问功能,条件:玩家等级 -func (this *ModelSys) IsAccess(funName string, userLv int32) bool { - conf := this.moduleSys.configure.getFuncCfg(funName) - if conf != nil { - return userLv >= conf.Main +func (this *ModelSys) IsAccess(funName string, uid string) bool { + user := this.moduleSys.ModuleUser.GetUser(uid) + if user != nil { + conf := this.moduleSys.configure.getFuncCfg(funName) + if conf != nil { + return user.Lv >= conf.Main + } } + return false } diff --git a/modules/sys/module.go b/modules/sys/module.go index a077ae4d4..ca8ab6759 100644 --- a/modules/sys/module.go +++ b/modules/sys/module.go @@ -31,6 +31,6 @@ func (this *ModuleSys) GetType() core.M_Modules { return comm.ModuleSys } -func (this *ModuleSys) IsAccess(funcName string, userLv int32) bool { - return this.modelSys.IsAccess(funcName, userLv) +func (this *ModuleSys) IsAccess(funcName string, userId string) bool { + return this.modelSys.IsAccess(funcName, userId) } diff --git a/modules/user/module.go b/modules/user/module.go index 9e88111c2..1d6727efa 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -92,8 +92,17 @@ func (this *User) OnInstallComp() { } //获取用户数据 -func (this *User) GetUser(uid string) *pb.DBUser { - user := this.modelUser.GetUser(uid) +func (this *User) GetUser(uid string) (user *pb.DBUser) { + var err error + if this.IsCross() { + user, err = this.getRemoteUser(uid) + if err != nil { + return nil + } + } else { + user = this.modelUser.GetUser(uid) + } + if user.Id == "" { return nil } @@ -108,8 +117,8 @@ func (this *User) GetCrossUser(uid string) (*pb.DBUser, error) { return reply, err } -// 获取远程用户数据sss -func (this *User) GetRemoteUser(uid string) (*pb.DBUser, error) { +// 获取远程用户数据 +func (this *User) getRemoteUser(uid string) (*pb.DBUser, error) { reply := &pb.DBUser{} if err := this.getUserFromRemoteDb(uid, reply); err != nil { return nil, err @@ -117,20 +126,6 @@ func (this *User) GetRemoteUser(uid string) (*pb.DBUser, error) { return reply, nil } -// 获取远程用户expand -func (this *User) GetRemoteUserExpand(uid string) (result *pb.DBUserExpand, err error) { - reply := &pb.DBUserExpand{} - if err := this.getUserExpandFromRemoteDb(uid, reply); err != nil { - return nil, err - } - return reply, nil -} - -// 更新远程用户expand -func (this *User) ChangeRemoteUserExpand(uid string, value map[string]interface{}) error { - return this.changeUserExpandFromRemoteDb(uid, value) -} - //获取用户会话 func (this *User) GetUserSession(uid string) *pb.CacheUser { return this.modelSession.getUserSession(uid) @@ -212,7 +207,7 @@ func (this *User) QueryAttributeValue(uid string, attr string) (value int64) { err error ) if this.IsCross() { - user, err = this.GetRemoteUser(uid) + user, err = this.getRemoteUser(uid) if err != nil { return } @@ -251,25 +246,12 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha userEx *pb.DBUserExpand err error ) - if this.IsCross() { - user, err = this.GetRemoteUser(uid) - if err != nil { - code = pb.ErrorCode_UserSessionNobeing - return - } - - userEx, err = this.GetRemoteUserExpand(uid) - if err != nil { - code = pb.ErrorCode_UserExpandNull - return - } - } else { - user = this.GetUser(uid) - userEx, err = this.GetUserExpand(uid) - if err != nil { - code = pb.ErrorCode_UserExpandNull - return - } + + user = this.GetUser(uid) + userEx, err = this.GetUserExpand(uid) + if err != nil { + code = pb.ErrorCode_UserExpandNull + return } if user == nil {