改造获取玩家数据的方法

This commit is contained in:
wh_zcy 2022-11-24 16:35:44 +08:00
parent 85c174a498
commit c28ae84698
17 changed files with 125 additions and 121 deletions

View File

@ -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"
)

View File

@ -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 {

View File

@ -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,
}
}

View File

@ -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 {

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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 {