优化好友日志
This commit is contained in:
parent
9757796ba3
commit
af3ce8f4e8
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,8 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// 助战列表
|
||||
|
||||
func (this *apiComp) AssistlistCheck(session comm.IUserSession, req *pb.FriendAssistlistReq) (code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user