From b01e92ca669a39087bb8aed93c35d16969812bfb Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Mon, 21 Nov 2022 16:39:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E8=8E=B7=E5=8F=96=E4=B8=8E?= =?UTF-8?q?=E5=A5=BD=E5=8F=8B=E7=9A=84=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/friend/api.go | 1 + modules/friend/api_cross_getrelation.go | 58 +++++++++ modules/friend/api_cross_list.go | 5 + pb/friend_msg.pb.go | 149 +++++++++++++++++++++++- 4 files changed, 207 insertions(+), 6 deletions(-) create mode 100644 modules/friend/api_cross_getrelation.go diff --git a/modules/friend/api.go b/modules/friend/api.go index c144c9f53..cb03888ea 100644 --- a/modules/friend/api.go +++ b/modules/friend/api.go @@ -26,6 +26,7 @@ const ( FriendSubTypeAssistlist = "assistlist" FriendSubTypeGetreward = "getreward" FriendSubTypeAssistHeroList = "assistherolist" + FriendSubTypeRelation = "getrelation" ) type apiComp struct { diff --git a/modules/friend/api_cross_getrelation.go b/modules/friend/api_cross_getrelation.go new file mode 100644 index 000000000..d37923f6e --- /dev/null +++ b/modules/friend/api_cross_getrelation.go @@ -0,0 +1,58 @@ +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) GetRelationCheck(session comm.IUserSession, req *pb.FriendGetRelationReq) (code pb.ErrorCode) { + if req.TargetUid == "" { + code = pb.ErrorCode_ReqParameterError + this.moduleFriend.Error("参数错误", log.Fields{"uid": session.GetUserId(), "params": req}) + } + return +} + +func (this *apiComp) GetRelation(session comm.IUserSession, req *pb.FriendGetRelationReq) (code pb.ErrorCode, data proto.Message) { + if code = this.GetRelationCheck(session, req); code != pb.ErrorCode_Success { + return + } + + self := this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) + if self == nil { + code = pb.ErrorCode_FriendSelfNoData + return + } + + target := this.moduleFriend.modelFriend.GetFriend(req.TargetUid) + if target == nil { + code = pb.ErrorCode_FriendTargetNoData + return + } + var status bool + + // 已申请目标玩家 + if _, ok := utils.Findx(target.ApplyIds, self.Uid); ok { + status = true + } + + //目标玩家已是好友 + if _, ok := utils.Findx(self.FriendIds, req.TargetUid); ok { + status = true + } + + resp := &pb.FriendGetRelationResp{ + TargetUid: req.TargetUid, + Status: status, + } + if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeRelation, resp); err != nil { + code = pb.ErrorCode_SystemError + return + } + return +} diff --git a/modules/friend/api_cross_list.go b/modules/friend/api_cross_list.go index f829f5007..98cff5bd8 100644 --- a/modules/friend/api_cross_list.go +++ b/modules/friend/api_cross_list.go @@ -45,6 +45,11 @@ func (this *apiComp) List(session comm.IUserSession, req *pb.FriendListReq) (cod if target == nil { continue } + // 申请过的在线好友,设置申请状态 + if _, ok := utils.Findx(target.ApplyIds, self.Uid); ok { + base.IsApplied = true + } + if _, ok := utils.Findx(target.ZanIds, self.Uid); ok { base.IsZaned = true } diff --git a/pb/friend_msg.pb.go b/pb/friend_msg.pb.go index d242e8104..ff1a9722a 100644 --- a/pb/friend_msg.pb.go +++ b/pb/friend_msg.pb.go @@ -2008,6 +2008,109 @@ func (x *FriendAssistHeroListResp) GetFriends() []*FriendBase { return nil } +// 查询是否已申请目标玩家为好友或目标玩家是否已是好友 +type FriendGetRelationReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TargetUid string `protobuf:"bytes,1,opt,name=targetUid,proto3" json:"targetUid"` //目标玩家ID +} + +func (x *FriendGetRelationReq) Reset() { + *x = FriendGetRelationReq{} + if protoimpl.UnsafeEnabled { + mi := &file_friend_friend_msg_proto_msgTypes[40] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *FriendGetRelationReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FriendGetRelationReq) ProtoMessage() {} + +func (x *FriendGetRelationReq) ProtoReflect() protoreflect.Message { + mi := &file_friend_friend_msg_proto_msgTypes[40] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FriendGetRelationReq.ProtoReflect.Descriptor instead. +func (*FriendGetRelationReq) Descriptor() ([]byte, []int) { + return file_friend_friend_msg_proto_rawDescGZIP(), []int{40} +} + +func (x *FriendGetRelationReq) GetTargetUid() string { + if x != nil { + return x.TargetUid + } + return "" +} + +type FriendGetRelationResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TargetUid string `protobuf:"bytes,1,opt,name=targetUid,proto3" json:"targetUid"` + Status bool `protobuf:"varint,2,opt,name=status,proto3" json:"status"` //已是好友或已申请返回true +} + +func (x *FriendGetRelationResp) Reset() { + *x = FriendGetRelationResp{} + if protoimpl.UnsafeEnabled { + mi := &file_friend_friend_msg_proto_msgTypes[41] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *FriendGetRelationResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FriendGetRelationResp) ProtoMessage() {} + +func (x *FriendGetRelationResp) ProtoReflect() protoreflect.Message { + mi := &file_friend_friend_msg_proto_msgTypes[41] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FriendGetRelationResp.ProtoReflect.Descriptor instead. +func (*FriendGetRelationResp) Descriptor() ([]byte, []int) { + return file_friend_friend_msg_proto_rawDescGZIP(), []int{41} +} + +func (x *FriendGetRelationResp) GetTargetUid() string { + if x != nil { + return x.TargetUid + } + return "" +} + +func (x *FriendGetRelationResp) GetStatus() bool { + if x != nil { + return x.Status + } + return false +} + var File_friend_friend_msg_proto protoreflect.FileDescriptor var file_friend_friend_msg_proto_rawDesc = []byte{ @@ -2159,8 +2262,16 @@ var file_friend_friend_msg_proto_rawDesc = []byte{ 0x48, 0x65, 0x72, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x25, 0x0a, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x61, 0x73, 0x65, 0x52, 0x07, 0x66, 0x72, 0x69, 0x65, - 0x6e, 0x64, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x6e, 0x64, 0x73, 0x22, 0x34, 0x0a, 0x14, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x47, 0x65, 0x74, + 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x1c, 0x0a, 0x09, 0x74, + 0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, + 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, 0x64, 0x22, 0x4d, 0x0a, 0x15, 0x46, 0x72, 0x69, + 0x65, 0x6e, 0x64, 0x47, 0x65, 0x74, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, + 0x73, 0x70, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, 0x64, + 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -2175,7 +2286,7 @@ func file_friend_friend_msg_proto_rawDescGZIP() []byte { return file_friend_friend_msg_proto_rawDescData } -var file_friend_friend_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 40) +var file_friend_friend_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 42) var file_friend_friend_msg_proto_goTypes = []interface{}{ (*FriendBase)(nil), // 0: FriendBase (*FriendListReq)(nil), // 1: FriendListReq @@ -2217,7 +2328,9 @@ var file_friend_friend_msg_proto_goTypes = []interface{}{ (*FriendAssistHeroUpdatePush)(nil), // 37: FriendAssistHeroUpdatePush (*FriendAssistHeroListReq)(nil), // 38: FriendAssistHeroListReq (*FriendAssistHeroListResp)(nil), // 39: FriendAssistHeroListResp - (*AssistRecord)(nil), // 40: AssistRecord + (*FriendGetRelationReq)(nil), // 40: FriendGetRelationReq + (*FriendGetRelationResp)(nil), // 41: FriendGetRelationResp + (*AssistRecord)(nil), // 42: AssistRecord } var file_friend_friend_msg_proto_depIdxs = []int32{ 0, // 0: FriendListResp.list:type_name -> FriendBase @@ -2227,7 +2340,7 @@ var file_friend_friend_msg_proto_depIdxs = []int32{ 0, // 4: FriendBlackListResp.friends:type_name -> FriendBase 0, // 5: FriendZanlistResp.list:type_name -> FriendBase 0, // 6: FriendAssistlistResp.list:type_name -> FriendBase - 40, // 7: FriendAssistlistResp.record:type_name -> AssistRecord + 42, // 7: FriendAssistlistResp.record:type_name -> AssistRecord 0, // 8: FriendAssistHeroUpdatePush.friend:type_name -> FriendBase 0, // 9: FriendAssistHeroListResp.friends:type_name -> FriendBase 10, // [10:10] is the sub-list for method output_type @@ -2724,6 +2837,30 @@ func file_friend_friend_msg_proto_init() { return nil } } + file_friend_friend_msg_proto_msgTypes[40].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*FriendGetRelationReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_friend_friend_msg_proto_msgTypes[41].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*FriendGetRelationResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -2731,7 +2868,7 @@ func file_friend_friend_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_friend_friend_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 40, + NumMessages: 42, NumExtensions: 0, NumServices: 0, },