优化好友日志

This commit is contained in:
wh_zcy 2022-11-17 14:38:04 +08:00
parent 9757796ba3
commit af3ce8f4e8
9 changed files with 91 additions and 92 deletions

View File

@ -2,6 +2,7 @@ package friend
import ( import (
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "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 { func (this *apiComp) setDefaultFriendUserBaseInfo(userId string) *pb.FriendBase {
if user, err := this.moduleFriend.ModuleUser.GetRemoteUser(userId); err != nil { 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 return nil
} else { } else {
if user != nil { if user != nil {

View File

@ -2,20 +2,23 @@ package friend
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
//加入黑名单
func (this *apiComp) AddblackCheck(session comm.IUserSession, req *pb.FriendAddBlackReq) (code pb.ErrorCode) { func (this *apiComp) AddblackCheck(session comm.IUserSession, req *pb.FriendAddBlackReq) (code pb.ErrorCode) {
if req.FriendId == "" { if req.FriendId == "" {
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
this.moduleFriend.Error("加入黑名单参数错误", log.Fields{"uid": session.GetUserId(), "params": req})
} }
return return
} }
//加入黑名单
func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackReq) (code pb.ErrorCode, data proto.Message) { 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 { if code = this.AddblackCheck(session, req); code != pb.ErrorCode_Success {
return return
@ -28,18 +31,8 @@ func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackR
Resp *pb.FriendAddBlackResp Resp *pb.FriendAddBlackResp
) )
defer func() { uid := session.GetUserId()
Resp = &pb.FriendAddBlackResp{ self = this.moduleFriend.modelFriend.GetFriend(uid)
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())
if self == nil { if self == nil {
code = pb.ErrorCode_FriendSelfNoData code = pb.ErrorCode_FriendSelfNoData
return return
@ -51,20 +44,20 @@ func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackR
return return
} }
//判断目标是否在好友列表里面 //判断目标是否在好友列表里面(目标不在好友列表中也可加入黑名单)
// if _, ok := utils.Find(self.FriendIds, req.FriendId); ok { // if _, ok := utils.Findx(self.FriendIds, req.FriendId); ok {
// code = pb.ErrorCode_FriendYet // code = pb.ErrorCode_FriendYet
// return // return
// } // }
//判断目标是否已经在黑名单中 //判断目标是否已经在黑名单中
if _, ok := utils.Find(self.BlackIds, req.FriendId); ok { if _, ok := utils.Findx(self.BlackIds, req.FriendId); ok {
code = pb.ErrorCode_FriendSelfBlackYet code = pb.ErrorCode_FriendSelfBlackYet
return return
} }
// 判断自己是否在对方的黑名单中 // 判断自己是否在对方的黑名单中
if _, ok := utils.Find(target.BlackIds, self.Uid); ok { if _, ok := utils.Findx(target.BlackIds, self.Uid); ok {
code = pb.ErrorCode_FriendTargetBlackYet code = pb.ErrorCode_FriendTargetBlackYet
return return
} }
@ -79,7 +72,7 @@ func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackR
self.BlackIds = append(self.BlackIds, req.FriendId) 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{}{ 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 { if err != nil {
code = pb.ErrorCode_DBError 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 return
} }

View File

@ -2,21 +2,24 @@ package friend
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
//单个/批量同意
func (this *apiComp) AgreeCheck(session comm.IUserSession, req *pb.FriendAgreeReq) (code pb.ErrorCode) { func (this *apiComp) AgreeCheck(session comm.IUserSession, req *pb.FriendAgreeReq) (code pb.ErrorCode) {
if len(req.FriendIds) == 0 { if len(req.FriendIds) == 0 {
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
this.moduleFriend.Error("好友审批同意参数错误", log.Fields{"uid": session.GetUserId(), "params": req})
} }
return return
} }
//单个/批量同意
func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (code pb.ErrorCode, data proto.Message) { 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 { if code = this.AgreeCheck(session, req); code != pb.ErrorCode_Success {
return return
@ -25,23 +28,11 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (c
err error err error
self *pb.DBFriend self *pb.DBFriend
target *pb.DBFriend target *pb.DBFriend
Resp *pb.FriendAgreeResp
optNum int32 optNum int32
) )
uid := session.GetUserId()
defer func() {
Resp = &pb.FriendAgreeResp{
Num: optNum,
}
err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeAgree, Resp)
if err != nil {
code = pb.ErrorCode_SystemError
return
}
}()
//获取玩家自己好友数据 //获取玩家自己好友数据
self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) self = this.moduleFriend.modelFriend.GetFriend(uid)
if self == nil { if self == nil {
code = pb.ErrorCode_FriendSelfNoData code = pb.ErrorCode_FriendSelfNoData
return return
@ -90,6 +81,7 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (c
}) })
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
this.moduleFriend.Error("好友审批同意", log.Fields{"uid": uid, "params": req.FriendIds, "err": err.Error()})
return return
} }
@ -110,5 +102,13 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (c
// 拥有xx个好友 // 拥有xx个好友
this.moduleFriend.ModuleRtask.SendToRtask(session, comm.Rtype10, int32(len(agreeIds))) 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 return
} }

View File

@ -9,14 +9,16 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
//好友申请
func (this *apiComp) ApplyCheck(session comm.IUserSession, req *pb.FriendApplyReq) (code pb.ErrorCode) { func (this *apiComp) ApplyCheck(session comm.IUserSession, req *pb.FriendApplyReq) (code pb.ErrorCode) {
if req.FriendId == "" { if req.FriendId == "" {
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
this.moduleFriend.Error("好友申请参数错误", log.Fields{"uid": session.GetUserId(), "params": req})
} }
return return
} }
//好友申请
func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (code pb.ErrorCode, data proto.Message) { 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 { if code = this.ApplyCheck(session, req); code != pb.ErrorCode_Success {
return return
@ -26,24 +28,11 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c
err error err error
self *pb.DBFriend self *pb.DBFriend
target *pb.DBFriend target *pb.DBFriend
Resp *pb.FriendApplyResp
) )
defer func() { uid := session.GetUserId()
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
}
}()
//获取玩家自己好友数据 //获取玩家自己好友数据
self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) self = this.moduleFriend.modelFriend.GetFriend(uid)
if self == nil { if self == nil {
code = pb.ErrorCode_FriendSelfNoData code = pb.ErrorCode_FriendSelfNoData
return 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 code = pb.ErrorCode_FriendNotSelf
return return
} }
@ -104,14 +93,22 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c
} }
target.ApplyIds = append(target.ApplyIds, session.GetUserId()) 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, "applyIds": target.ApplyIds,
}) }); err != nil {
if err != nil {
log.Errorf("firend Apply err:%v", err)
code = pb.ErrorCode_FriendApplyError code = pb.ErrorCode_FriendApplyError
this.moduleFriend.Error("好友申请", log.Fields{"uid": uid, "params": req.FriendId, "err": err.Error()})
return 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 return
} }

View File

@ -7,29 +7,18 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
//申请列表
func (this *apiComp) ApplyListCheck(session comm.IUserSession, req *pb.FriendApplyListReq) (code pb.ErrorCode) { func (this *apiComp) ApplyListCheck(session comm.IUserSession, req *pb.FriendApplyListReq) (code pb.ErrorCode) {
return return
} }
//申请列表
func (this *apiComp) ApplyList(session comm.IUserSession, req *pb.FriendApplyListReq) (code pb.ErrorCode, data proto.Message) { func (this *apiComp) ApplyList(session comm.IUserSession, req *pb.FriendApplyListReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
self *pb.DBFriend self *pb.DBFriend
Resp *pb.FriendApplyListResp
list []*pb.FriendBase 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()) self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId())
if self == nil { if self == nil {
code = pb.ErrorCode_FriendSelfNoData 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 return
} }

View File

@ -14,6 +14,7 @@ import (
func (this *apiComp) AssistheroCheck(session comm.IUserSession, req *pb.FriendAssistheroReq) (code pb.ErrorCode) { func (this *apiComp) AssistheroCheck(session comm.IUserSession, req *pb.FriendAssistheroReq) (code pb.ErrorCode) {
if req.HeroObjId == "" { if req.HeroObjId == "" {
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
this.moduleFriend.Error("设置助战英雄参数错误", log.Fields{"uid": session.GetUserId(), "params": req})
} }
return 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 { if code = this.AssistheroCheck(session, req); code != pb.ErrorCode_Success {
return return
} }
uid := session.GetUserId()
// 获取英雄 // 获取英雄
hero, err := this.moduleFriend.ModuleHero.QueryCrossHeroinfo(req.HeroObjId) hero, err := this.moduleFriend.ModuleHero.QueryCrossHeroinfo(req.HeroObjId)
if err != nil { if err != nil {
code = pb.ErrorCode_DBError 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 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 { if self == nil {
code = pb.ErrorCode_FriendSelfNoData code = pb.ErrorCode_FriendSelfNoData
return 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 { if err := this.moduleFriend.modelFriend.Change(self.Uid, update); err != nil {
log.Errorf("Assisthero err:%v", err)
code = pb.ErrorCode_FriendApplyError code = pb.ErrorCode_FriendApplyError
this.moduleFriend.Error("设置助战英雄", log.Fields{"uid": uid, "param": req.HeroObjId, "err": err.Error()})
return 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 { 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()})
} }
} }

View File

@ -9,6 +9,8 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
// 助战列表
func (this *apiComp) AssistlistCheck(session comm.IUserSession, req *pb.FriendAssistlistReq) (code pb.ErrorCode) { func (this *apiComp) AssistlistCheck(session comm.IUserSession, req *pb.FriendAssistlistReq) (code pb.ErrorCode) {
return return
} }

View File

@ -7,30 +7,17 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
//黑名单列表
func (this *apiComp) BlacklistCheck(session comm.IUserSession, req *pb.FriendBlackListReq) (code pb.ErrorCode) { func (this *apiComp) BlacklistCheck(session comm.IUserSession, req *pb.FriendBlackListReq) (code pb.ErrorCode) {
return return
} }
//黑名单
func (this *apiComp) Blacklist(session comm.IUserSession, req *pb.FriendBlackListReq) (code pb.ErrorCode, data proto.Message) { func (this *apiComp) Blacklist(session comm.IUserSession, req *pb.FriendBlackListReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
self *pb.DBFriend self *pb.DBFriend
Resp *pb.FriendBlackListResp
list []*pb.FriendBase 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()) self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId())
if self == nil { if self == nil {
code = pb.ErrorCode_FriendSelfNoData code = pb.ErrorCode_FriendSelfNoData
@ -44,5 +31,14 @@ func (this *apiComp) Blacklist(session comm.IUserSession, req *pb.FriendBlackLis
} }
} }
resp := &pb.FriendBlackListResp{
Friends: list,
}
err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeBlacklist, resp)
if err != nil {
code = pb.ErrorCode_SystemError
return
}
return return
} }

View File

@ -9,27 +9,29 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
//删除好友
func (this *apiComp) DelCheck(session comm.IUserSession, req *pb.FriendDelReq) (code pb.ErrorCode) { func (this *apiComp) DelCheck(session comm.IUserSession, req *pb.FriendDelReq) (code pb.ErrorCode) {
if req.FriendId == "" { if req.FriendId == "" {
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
this.moduleFriend.Error("删除好友参数错误", log.Fields{"uid": session.GetUserId(), "params": req})
} }
return return
} }
//删除好友
func (this *apiComp) Del(session comm.IUserSession, req *pb.FriendDelReq) (code pb.ErrorCode, data proto.Message) { 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 { if code = this.DelCheck(session, req); code != pb.ErrorCode_Success {
return return
} }
self := this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) uid := session.GetUserId()
self := this.moduleFriend.modelFriend.GetFriend(uid)
if self == nil { if self == nil {
code = pb.ErrorCode_FriendSelfNoData code = pb.ErrorCode_FriendSelfNoData
return 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{}{ if err := this.moduleFriend.modelFriend.Change(self.Uid, map[string]interface{}{
"friendIds": selfFriendIds, "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{}{ if err := this.moduleFriend.modelFriend.Change(req.FriendId, map[string]interface{}{
"friendIds": targetFriendIds, "friendIds": targetFriendIds,
}); err != nil { }); err != nil {
log.Errorf("Del friend err:%v", err)
code = pb.ErrorCode_FriendApplyError code = pb.ErrorCode_FriendApplyError
this.moduleFriend.Error("删除好友", log.Fields{"uid": uid, "param": req.FriendId, "err": err.Error()})
return return
} }