好友审核修复

This commit is contained in:
wh_zcy 2022-12-14 19:24:00 +08:00
parent b5954efc8f
commit 5270f706d3
5 changed files with 81 additions and 39 deletions

View File

@ -228,7 +228,7 @@ const ( //Rpc
Rpc_ModuleRtaskSendTask core.Rpc_Key = "Rpc_ModuleRtaskSendTask" //随机任务触发 Rpc_ModuleRtaskSendTask core.Rpc_Key = "Rpc_ModuleRtaskSendTask" //随机任务触发
// friend // friend
Rpc_ModuleFriendUseAssitHero core.Rpc_Key = "Rpc_ModuleFriendUseAssitHero" //使用助战英雄 Rpc_ModuleFriendUseAssitHero core.Rpc_Key = "Rpc_ModuleFriendUseAssitHero" //使用助战英雄
Rpc_ModuleFriendDB core.Rpc_Key = "Rpc_ModuleFriendDB"
// arena // arena
Rpc_ModuleArenaRaceSettlement core.Rpc_Key = "Rpc_ModuleArenaRaceSettlement" //竞技场比赛结算信息 Rpc_ModuleArenaRaceSettlement core.Rpc_Key = "Rpc_ModuleArenaRaceSettlement" //竞技场比赛结算信息
Rpc_ModuleArenaModifyIntegral core.Rpc_Key = "Rpc_ModuleArenaModifyIntegral" //竞技场修改积分 Rpc_ModuleArenaModifyIntegral core.Rpc_Key = "Rpc_ModuleArenaModifyIntegral" //竞技场修改积分

View File

@ -69,6 +69,9 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (c
//将目标加入到自己的好友列表中 //将目标加入到自己的好友列表中
for _, userId := range agreeIds { for _, userId := range agreeIds {
//将目标从申请列表中删除
self.ApplyIds = utils.DeleteString(self.ApplyIds, userId)
if _, ok := utils.Find(self.FriendIds, userId); !ok { if _, ok := utils.Find(self.FriendIds, userId); !ok {
if self.FriendIds == nil { if self.FriendIds == nil {
self.FriendIds = []string{} self.FriendIds = []string{}
@ -82,6 +85,7 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (c
code = pb.ErrorCode_FriendTargetNoData code = pb.ErrorCode_FriendTargetNoData
return return
} }
target.ApplyIds = utils.DeleteString(target.ApplyIds, self.Uid)
if _, ok := utils.Find(target.FriendIds, self.Uid); !ok { if _, ok := utils.Find(target.FriendIds, self.Uid); !ok {
if target.FriendIds == nil { if target.FriendIds == nil {
target.FriendIds = []string{} target.FriendIds = []string{}
@ -106,19 +110,19 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (c
pushAssistHero(self.Uid, target.Uid, self.AssistHeroId) pushAssistHero(self.Uid, target.Uid, self.AssistHeroId)
} }
//将目标从申请列表中删除
self.ApplyIds = utils.DeleteString(self.ApplyIds, userId)
optNum++ optNum++
} }
//更新 if optNum > 0 {
err = this.moduleFriend.modelFriend.Change(self.Uid, map[string]interface{}{ //更新
"applyIds": self.ApplyIds, err = this.moduleFriend.modelFriend.Change(self.Uid, map[string]interface{}{
"friendIds": self.FriendIds, "applyIds": self.ApplyIds,
}) "friendIds": self.FriendIds,
if err != nil { })
code = pb.ErrorCode_DBError if err != nil {
return code = pb.ErrorCode_DBError
return
}
} }
// 拥有xx个好友 // 拥有xx个好友

View File

@ -31,6 +31,13 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c
) )
uid := session.GetUserId() uid := session.GetUserId()
//判断是否是自己
if req.FriendId == uid {
code = pb.ErrorCode_FriendNotSelf
return
}
//获取玩家自己好友数据 //获取玩家自己好友数据
self = this.moduleFriend.modelFriend.GetFriend(uid) self = this.moduleFriend.modelFriend.GetFriend(uid)
if self == nil { if self == nil {
@ -38,6 +45,19 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c
return return
} }
globalConf := this.moduleFriend.globalConf
//判断是否超过最大好友数量
if len(self.FriendIds) >= int(globalConf.FriendMaxnum) {
code = pb.ErrorCode_FriendSelfMax
return
}
//判断是否是好友
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
code = pb.ErrorCode_FriendYet
return
}
//获取好友数据 //获取好友数据
target = this.moduleFriend.modelFriend.GetFriend(req.FriendId) target = this.moduleFriend.modelFriend.GetFriend(req.FriendId)
if target == nil { if target == nil {
@ -45,15 +65,9 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c
return return
} }
//判断是否是自己 //判断自己是否在目标用户的申请列表中
if req.FriendId == uid { if _, ok := utils.Find(target.ApplyIds, self.Uid); ok {
code = pb.ErrorCode_FriendNotSelf code = pb.ErrorCode_FriendApplyYet
return
}
globalConf := this.moduleFriend.globalConf
//判断是否超过最大好友数量
if len(self.FriendIds) >= int(globalConf.FriendMaxnum) {
code = pb.ErrorCode_FriendSelfMax
return return
} }
@ -63,18 +77,6 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c
return return
} }
//判断是否是好友
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
code = pb.ErrorCode_FriendYet
return
}
//判断自己是否在目标用户的申请列表中
if _, ok := utils.Find(target.ApplyIds, self.Uid); ok {
code = pb.ErrorCode_FriendApplyYet
return
}
//判断目标用户是否在黑名单中 //判断目标用户是否在黑名单中
if _, ok := utils.Find(self.BlackIds, req.FriendId); ok { if _, ok := utils.Find(self.BlackIds, req.FriendId); ok {
code = pb.ErrorCode_FriendSelfBlackYet code = pb.ErrorCode_FriendSelfBlackYet

View File

@ -1,6 +1,7 @@
package friend package friend
import ( import (
"context"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
@ -14,12 +15,13 @@ import (
type ModelFriend struct { type ModelFriend struct {
modules.MCompModel modules.MCompModel
moduleFriend *Friend
} }
func (this *ModelFriend) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *ModelFriend) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = comm.TableFriend this.TableName = comm.TableFriend
err = this.MCompModel.Init(service, module, comp, options) err = this.MCompModel.Init(service, module, comp, options)
this.moduleFriend = module.(*Friend)
return return
} }
@ -38,14 +40,28 @@ func (this *ModelFriend) Frined_FindCond(nickName string) *pb.DBUser {
//查询好友 //查询好友
func (this *ModelFriend) GetFriend(uid string) *pb.DBFriend { func (this *ModelFriend) GetFriend(uid string) *pb.DBFriend {
friend := &pb.DBFriend{Uid: uid} friend := &pb.DBFriend{Uid: uid}
err := this.Get(uid, friend) if this.moduleFriend.IsCross() {
if err != nil { err := this.Get(uid, friend)
if err == redis.RedisNil || err == mongo.ErrNoDocuments { if err != nil {
if err := this.Add(uid, friend); err != nil { if err == redis.RedisNil || err == mongo.ErrNoDocuments {
return nil if err := this.Add(uid, friend); err != nil {
return nil
}
} }
log.Error("未获得好友数据", log.Fields{"uid": uid})
}
} else {
friend := &pb.DBFriend{}
if err := this.moduleFriend.service.AcrossClusterRpcCall(
context.Background(),
this.moduleFriend.GetCrossTag(),
comm.Service_Worker,
string(comm.Rpc_ModuleFriendDB),
pb.RPCGeneralReqA1{Param1: uid},
friend); err != nil {
this.moduleFriend.Errorln(err)
} }
log.Error("未获得好友数据", log.Fields{"uid": uid})
} }
return friend return friend
} }

View File

@ -15,10 +15,12 @@ import (
"go_dreamfactory/lego/base" "go_dreamfactory/lego/base"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/redis"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"github.com/spf13/cast" "github.com/spf13/cast"
"go.mongodb.org/mongo-driver/mongo"
) )
var _ comm.IFriend = (*Friend)(nil) var _ comm.IFriend = (*Friend)(nil)
@ -56,6 +58,7 @@ func (this *Friend) OnInstallComp() {
func (this *Friend) Start() (err error) { func (this *Friend) Start() (err error) {
err = this.ModuleBase.Start() err = this.ModuleBase.Start()
this.service.RegisterFunctionName(string(comm.Rpc_ModuleFriendUseAssitHero), this.RpcUseAssisHero) this.service.RegisterFunctionName(string(comm.Rpc_ModuleFriendUseAssitHero), this.RpcUseAssisHero)
this.service.RegisterFunctionName(string(comm.Rpc_ModuleFriendDB), this.RpcFriendDB)
this.globalConf = this.configure.GetGlobalConf() this.globalConf = this.configure.GetGlobalConf()
if this.globalConf == nil { if this.globalConf == nil {
err = errors.New("global config not found") err = errors.New("global config not found")
@ -109,6 +112,23 @@ func (this *Friend) RpcUseAssisHero(ctx context.Context, req *pb.RPCGeneralReqA2
return nil return nil
} }
func (this *Friend) RpcFriendDB(ctx context.Context, req *pb.RPCGeneralReqA1, reply *pb.DBFriend) error {
this.Debug("Rpc_ModuleFriendDB", log.Fields{"req": req})
friend := &pb.DBFriend{Uid: req.Param1}
err := this.modelFriend.Get(req.Param1, friend)
if err != nil {
if err == redis.RedisNil || err == mongo.ErrNoDocuments {
if err := this.modelFriend.Add(req.Param1, friend); err != nil {
return nil
}
} else {
log.Error("未获得好友数据", log.Fields{"uid": req.Param1, "err": err})
}
}
*reply = *friend
return nil
}
// 使用好友助战英雄 // 使用好友助战英雄
// friendId 好友Id // friendId 好友Id
func (this *Friend) UseAssistHero(uid, friendId string) (*pb.DBHero, error) { func (this *Friend) UseAssistHero(uid, friendId string) (*pb.DBHero, error) {