From af3ce8f4e8e3995ba0148a3c82f7cc5a6259eb8f Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Thu, 17 Nov 2022 14:38:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A5=BD=E5=8F=8B=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/friend/api.go | 3 +- modules/friend/api_cross_addblack.go | 39 ++++++++++++++------------ modules/friend/api_cross_agree.go | 30 ++++++++++---------- modules/friend/api_cross_apply.go | 39 ++++++++++++-------------- modules/friend/api_cross_applylist.go | 23 +++++++-------- modules/friend/api_cross_assisthero.go | 11 ++++---- modules/friend/api_cross_assistlist.go | 2 ++ modules/friend/api_cross_blacklist.go | 24 +++++++--------- modules/friend/api_cross_del.go | 12 ++++---- 9 files changed, 91 insertions(+), 92 deletions(-) diff --git a/modules/friend/api.go b/modules/friend/api.go index ab453d18c..c144c9f53 100644 --- a/modules/friend/api.go +++ b/modules/friend/api.go @@ -2,6 +2,7 @@ package friend import ( "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" ) @@ -40,7 +41,7 @@ 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.Errorf("GetRmoteUser err:%v", err) + this.moduleFriend.Error("GetRmoteUser", log.Fields{"err": err.Error()}) return nil } else { if user != nil { diff --git a/modules/friend/api_cross_addblack.go b/modules/friend/api_cross_addblack.go index eb7b2b4a6..6bef8c607 100644 --- a/modules/friend/api_cross_addblack.go +++ b/modules/friend/api_cross_addblack.go @@ -2,20 +2,23 @@ package friend import ( "go_dreamfactory/comm" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" "go_dreamfactory/utils" "google.golang.org/protobuf/proto" ) +//加入黑名单 + func (this *apiComp) AddblackCheck(session comm.IUserSession, req *pb.FriendAddBlackReq) (code pb.ErrorCode) { if req.FriendId == "" { code = pb.ErrorCode_ReqParameterError + this.moduleFriend.Error("加入黑名单参数错误", log.Fields{"uid": session.GetUserId(), "params": req}) } return } -//加入黑名单 func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackReq) (code pb.ErrorCode, data proto.Message) { if code = this.AddblackCheck(session, req); code != pb.ErrorCode_Success { return @@ -28,18 +31,8 @@ func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackR Resp *pb.FriendAddBlackResp ) - defer func() { - Resp = &pb.FriendAddBlackResp{ - FriendId: req.FriendId, - UserId: session.GetUserId(), - } - if err = session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeAddBlack, Resp); err != nil { - code = pb.ErrorCode_SystemError - return - } - }() - - self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) + uid := session.GetUserId() + self = this.moduleFriend.modelFriend.GetFriend(uid) if self == nil { code = pb.ErrorCode_FriendSelfNoData return @@ -51,20 +44,20 @@ func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackR return } - //判断目标是否在好友列表里面 - // if _, ok := utils.Find(self.FriendIds, req.FriendId); ok { + //判断目标是否在好友列表里面(目标不在好友列表中也可加入黑名单) + // if _, ok := utils.Findx(self.FriendIds, req.FriendId); ok { // code = pb.ErrorCode_FriendYet // return // } //判断目标是否已经在黑名单中 - if _, ok := utils.Find(self.BlackIds, req.FriendId); ok { + if _, ok := utils.Findx(self.BlackIds, req.FriendId); ok { code = pb.ErrorCode_FriendSelfBlackYet return } // 判断自己是否在对方的黑名单中 - if _, ok := utils.Find(target.BlackIds, self.Uid); ok { + if _, ok := utils.Findx(target.BlackIds, self.Uid); ok { code = pb.ErrorCode_FriendTargetBlackYet return } @@ -79,7 +72,7 @@ func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackR self.BlackIds = append(self.BlackIds, req.FriendId) // 将目标从好友列表中移除 - friendIds := utils.DeleteString(self.FriendIds, req.FriendId) + friendIds := utils.Deletex(self.FriendIds, req.FriendId) //更新 err = this.moduleFriend.modelFriend.Change(self.Uid, map[string]interface{}{ @@ -88,6 +81,16 @@ func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackR }) if err != nil { code = pb.ErrorCode_DBError + this.moduleFriend.Error("加入黑名单", log.Fields{"uid": uid, "目标人": req.FriendId, "err": err.Error()}) + return + } + + Resp = &pb.FriendAddBlackResp{ + FriendId: req.FriendId, + UserId: session.GetUserId(), + } + if err = session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeAddBlack, Resp); err != nil { + code = pb.ErrorCode_SystemError return } diff --git a/modules/friend/api_cross_agree.go b/modules/friend/api_cross_agree.go index ef288bc34..740f1ea4a 100644 --- a/modules/friend/api_cross_agree.go +++ b/modules/friend/api_cross_agree.go @@ -2,21 +2,24 @@ package friend import ( "go_dreamfactory/comm" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" "go_dreamfactory/utils" "google.golang.org/protobuf/proto" ) +//单个/批量同意 + func (this *apiComp) AgreeCheck(session comm.IUserSession, req *pb.FriendAgreeReq) (code pb.ErrorCode) { if len(req.FriendIds) == 0 { code = pb.ErrorCode_ReqParameterError + this.moduleFriend.Error("好友审批同意参数错误", log.Fields{"uid": session.GetUserId(), "params": req}) } return } -//单个/批量同意 func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (code pb.ErrorCode, data proto.Message) { if code = this.AgreeCheck(session, req); code != pb.ErrorCode_Success { return @@ -25,23 +28,11 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (c err error self *pb.DBFriend target *pb.DBFriend - Resp *pb.FriendAgreeResp optNum int32 ) - - defer func() { - Resp = &pb.FriendAgreeResp{ - Num: optNum, - } - err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeAgree, Resp) - if err != nil { - code = pb.ErrorCode_SystemError - return - } - }() - + uid := session.GetUserId() //获取玩家自己好友数据 - self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) + self = this.moduleFriend.modelFriend.GetFriend(uid) if self == nil { code = pb.ErrorCode_FriendSelfNoData return @@ -90,6 +81,7 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (c }) if err != nil { code = pb.ErrorCode_DBError + this.moduleFriend.Error("好友审批同意", log.Fields{"uid": uid, "params": req.FriendIds, "err": err.Error()}) return } @@ -110,5 +102,13 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (c // 拥有xx个好友 this.moduleFriend.ModuleRtask.SendToRtask(session, comm.Rtype10, int32(len(agreeIds))) + + resp := &pb.FriendAgreeResp{ + Num: optNum, + } + if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeAgree, resp); err != nil { + code = pb.ErrorCode_SystemError + return + } return } diff --git a/modules/friend/api_cross_apply.go b/modules/friend/api_cross_apply.go index 540c733a3..f78905e19 100644 --- a/modules/friend/api_cross_apply.go +++ b/modules/friend/api_cross_apply.go @@ -9,14 +9,16 @@ import ( "google.golang.org/protobuf/proto" ) +//好友申请 + func (this *apiComp) ApplyCheck(session comm.IUserSession, req *pb.FriendApplyReq) (code pb.ErrorCode) { if req.FriendId == "" { code = pb.ErrorCode_ReqParameterError + this.moduleFriend.Error("好友申请参数错误", log.Fields{"uid": session.GetUserId(), "params": req}) } return } -//好友申请 func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (code pb.ErrorCode, data proto.Message) { if code = this.ApplyCheck(session, req); code != pb.ErrorCode_Success { return @@ -26,24 +28,11 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c err error self *pb.DBFriend target *pb.DBFriend - Resp *pb.FriendApplyResp ) - defer func() { - if code == pb.ErrorCode_Success { - Resp = &pb.FriendApplyResp{ - UserId: session.GetUserId(), - FriendId: req.FriendId, - } - } - if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeApply, Resp); err != nil { - code = pb.ErrorCode_SystemError - return - } - }() - + uid := session.GetUserId() //获取玩家自己好友数据 - self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) + self = this.moduleFriend.modelFriend.GetFriend(uid) if self == nil { code = pb.ErrorCode_FriendSelfNoData return @@ -57,7 +46,7 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c } //判断是否是自己 - if req.FriendId == session.GetUserId() { + if req.FriendId == uid { code = pb.ErrorCode_FriendNotSelf return } @@ -104,14 +93,22 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c } target.ApplyIds = append(target.ApplyIds, session.GetUserId()) - err = this.moduleFriend.modelFriend.Change(req.FriendId, map[string]interface{}{ + if err = this.moduleFriend.modelFriend.Change(req.FriendId, map[string]interface{}{ "applyIds": target.ApplyIds, - }) - if err != nil { - log.Errorf("firend Apply err:%v", err) + }); err != nil { code = pb.ErrorCode_FriendApplyError + this.moduleFriend.Error("好友申请", log.Fields{"uid": uid, "params": req.FriendId, "err": err.Error()}) return } + resp := &pb.FriendApplyResp{ + UserId: session.GetUserId(), + FriendId: req.FriendId, + } + + if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeApply, resp); err != nil { + code = pb.ErrorCode_SystemError + return + } return } diff --git a/modules/friend/api_cross_applylist.go b/modules/friend/api_cross_applylist.go index 4dd95cc34..fd35e6244 100644 --- a/modules/friend/api_cross_applylist.go +++ b/modules/friend/api_cross_applylist.go @@ -7,29 +7,18 @@ import ( "google.golang.org/protobuf/proto" ) +//申请列表 + func (this *apiComp) ApplyListCheck(session comm.IUserSession, req *pb.FriendApplyListReq) (code pb.ErrorCode) { return } -//申请列表 func (this *apiComp) ApplyList(session comm.IUserSession, req *pb.FriendApplyListReq) (code pb.ErrorCode, data proto.Message) { var ( self *pb.DBFriend - Resp *pb.FriendApplyListResp list []*pb.FriendBase ) - defer func() { - if code == pb.ErrorCode_Success { - Resp = &pb.FriendApplyListResp{ - List: list, - } - } - if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeApplyList, Resp); err != nil { - code = pb.ErrorCode_SystemError - } - }() - self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) if self == nil { code = pb.ErrorCode_FriendSelfNoData @@ -43,5 +32,13 @@ func (this *apiComp) ApplyList(session comm.IUserSession, req *pb.FriendApplyLis } } + resp := &pb.FriendApplyListResp{ + List: list, + } + + if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeApplyList, resp); err != nil { + code = pb.ErrorCode_SystemError + } + return } diff --git a/modules/friend/api_cross_assisthero.go b/modules/friend/api_cross_assisthero.go index ddbc5b04b..5c339cb75 100644 --- a/modules/friend/api_cross_assisthero.go +++ b/modules/friend/api_cross_assisthero.go @@ -14,6 +14,7 @@ import ( func (this *apiComp) AssistheroCheck(session comm.IUserSession, req *pb.FriendAssistheroReq) (code pb.ErrorCode) { if req.HeroObjId == "" { code = pb.ErrorCode_ReqParameterError + this.moduleFriend.Error("设置助战英雄参数错误", log.Fields{"uid": session.GetUserId(), "params": req}) } return } @@ -22,12 +23,12 @@ func (this *apiComp) Assisthero(session comm.IUserSession, req *pb.FriendAssisth if code = this.AssistheroCheck(session, req); code != pb.ErrorCode_Success { return } - + uid := session.GetUserId() // 获取英雄 hero, err := this.moduleFriend.ModuleHero.QueryCrossHeroinfo(req.HeroObjId) if err != nil { code = pb.ErrorCode_DBError - this.moduleFriend.Errorf("query hero by cross err:%v", err) + this.moduleFriend.Error("查询英雄数据 QueryCrossHeroinfo", log.Fields{"uid": uid, "param": req.HeroObjId, "err": err.Error()}) return } @@ -37,7 +38,7 @@ func (this *apiComp) Assisthero(session comm.IUserSession, req *pb.FriendAssisth } //获取玩家自己好友数据 - self := this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) + self := this.moduleFriend.modelFriend.GetFriend(uid) if self == nil { code = pb.ErrorCode_FriendSelfNoData return @@ -54,8 +55,8 @@ func (this *apiComp) Assisthero(session comm.IUserSession, req *pb.FriendAssisth } if err := this.moduleFriend.modelFriend.Change(self.Uid, update); err != nil { - log.Errorf("Assisthero err:%v", err) code = pb.ErrorCode_FriendApplyError + this.moduleFriend.Error("设置助战英雄", log.Fields{"uid": uid, "param": req.HeroObjId, "err": err.Error()}) return } @@ -76,7 +77,7 @@ func (this *apiComp) Assisthero(session comm.IUserSession, req *pb.FriendAssisth } if err := this.moduleFriend.SendMsgToUsers(string(this.moduleFriend.GetType()), "assistheroupdate", push, self.FriendIds...); err != nil { - this.moduleFriend.Errorf("push AssistHeroList err:", err) + this.moduleFriend.Error("推送助战英雄列表", log.Fields{"uid": uid, "friends": self.FriendIds, "err": err.Error()}) } } diff --git a/modules/friend/api_cross_assistlist.go b/modules/friend/api_cross_assistlist.go index e04427f1f..f5c8117b1 100644 --- a/modules/friend/api_cross_assistlist.go +++ b/modules/friend/api_cross_assistlist.go @@ -9,6 +9,8 @@ import ( "google.golang.org/protobuf/proto" ) +// 助战列表 + func (this *apiComp) AssistlistCheck(session comm.IUserSession, req *pb.FriendAssistlistReq) (code pb.ErrorCode) { return } diff --git a/modules/friend/api_cross_blacklist.go b/modules/friend/api_cross_blacklist.go index 453be5dfa..3fcb18539 100644 --- a/modules/friend/api_cross_blacklist.go +++ b/modules/friend/api_cross_blacklist.go @@ -7,30 +7,17 @@ import ( "google.golang.org/protobuf/proto" ) +//黑名单列表 func (this *apiComp) BlacklistCheck(session comm.IUserSession, req *pb.FriendBlackListReq) (code pb.ErrorCode) { return } -//黑名单 func (this *apiComp) Blacklist(session comm.IUserSession, req *pb.FriendBlackListReq) (code pb.ErrorCode, data proto.Message) { var ( self *pb.DBFriend - Resp *pb.FriendBlackListResp list []*pb.FriendBase ) - defer func() { - Resp = &pb.FriendBlackListResp{ - Friends: list, - } - - err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeBlacklist, Resp) - if err != nil { - code = pb.ErrorCode_SystemError - return - } - }() - self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) if self == nil { code = pb.ErrorCode_FriendSelfNoData @@ -43,6 +30,15 @@ func (this *apiComp) Blacklist(session comm.IUserSession, req *pb.FriendBlackLis list = append(list, base) } } + + resp := &pb.FriendBlackListResp{ + Friends: list, + } + err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeBlacklist, resp) + if err != nil { + code = pb.ErrorCode_SystemError + return + } return } diff --git a/modules/friend/api_cross_del.go b/modules/friend/api_cross_del.go index f1bcbad0e..279186340 100644 --- a/modules/friend/api_cross_del.go +++ b/modules/friend/api_cross_del.go @@ -9,27 +9,29 @@ import ( "google.golang.org/protobuf/proto" ) +//删除好友 func (this *apiComp) DelCheck(session comm.IUserSession, req *pb.FriendDelReq) (code pb.ErrorCode) { if req.FriendId == "" { code = pb.ErrorCode_ReqParameterError + this.moduleFriend.Error("删除好友参数错误", log.Fields{"uid": session.GetUserId(), "params": req}) } return } -//删除好友 func (this *apiComp) Del(session comm.IUserSession, req *pb.FriendDelReq) (code pb.ErrorCode, data proto.Message) { if code = this.DelCheck(session, req); code != pb.ErrorCode_Success { return } - self := this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) + uid := session.GetUserId() + self := this.moduleFriend.modelFriend.GetFriend(uid) if self == nil { code = pb.ErrorCode_FriendSelfNoData return } // 从好友列表中删除 - selfFriendIds := utils.DeleteString(self.FriendIds, req.FriendId) + selfFriendIds := utils.Deletex(self.FriendIds, req.FriendId) if err := this.moduleFriend.modelFriend.Change(self.Uid, map[string]interface{}{ "friendIds": selfFriendIds, @@ -46,13 +48,13 @@ func (this *apiComp) Del(session comm.IUserSession, req *pb.FriendDelReq) (code } // 将自己从对方好友列表中移除 - targetFriendIds := utils.DeleteString(target.FriendIds, session.GetUserId()) + targetFriendIds := utils.DeleteString(target.FriendIds, uid) if err := this.moduleFriend.modelFriend.Change(req.FriendId, map[string]interface{}{ "friendIds": targetFriendIds, }); err != nil { - log.Errorf("Del friend err:%v", err) code = pb.ErrorCode_FriendApplyError + this.moduleFriend.Error("删除好友", log.Fields{"uid": uid, "param": req.FriendId, "err": err.Error()}) return }