From 7be635c007b11b47e17b6e1748dcc46c5a22c7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B7=E5=8B=87?= Date: Tue, 15 Aug 2023 14:46:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E6=B7=BB=E5=8A=A0=E5=92=8C?= =?UTF-8?q?=E5=90=8C=E6=84=8F=E6=B7=BB=E5=8A=A0=E5=A5=BD=E5=8F=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/imserver/cs/cs_proto.pb.go | 465 +++++++++++++++++++++++---- server/imserver/friendsmgr.go | 74 +++-- server/imserver/proto/cs_proto.proto | 32 ++ 3 files changed, 490 insertions(+), 81 deletions(-) diff --git a/server/imserver/cs/cs_proto.pb.go b/server/imserver/cs/cs_proto.pb.go index 0f9d613a..6f74477b 100644 --- a/server/imserver/cs/cs_proto.pb.go +++ b/server/imserver/cs/cs_proto.pb.go @@ -885,6 +885,278 @@ func (x *SMSearchFriend) GetFriends() []*MFFriend { return nil } +// 请求发送添加好友请求 +type CMAddFriendRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ServerId *int32 `protobuf:"varint,1,opt,name=server_id,json=serverId" json:"server_id,omitempty"` //保留 + TeamUuid *string `protobuf:"bytes,2,opt,name=team_uuid,json=teamUuid" json:"team_uuid,omitempty"` //保留 + AccountId *string `protobuf:"bytes,3,opt,name=account_id,json=accountId" json:"account_id,omitempty"` //账号id + Account2Id *string `protobuf:"bytes,5,opt,name=account2_id,json=account2Id" json:"account2_id,omitempty"` // + SessionId *string `protobuf:"bytes,20,opt,name=session_id,json=sessionId" json:"session_id,omitempty"` //账号id +} + +func (x *CMAddFriendRequest) Reset() { + *x = CMAddFriendRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_cs_proto_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CMAddFriendRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CMAddFriendRequest) ProtoMessage() {} + +func (x *CMAddFriendRequest) ProtoReflect() protoreflect.Message { + mi := &file_cs_proto_proto_msgTypes[13] + 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 CMAddFriendRequest.ProtoReflect.Descriptor instead. +func (*CMAddFriendRequest) Descriptor() ([]byte, []int) { + return file_cs_proto_proto_rawDescGZIP(), []int{13} +} + +func (x *CMAddFriendRequest) GetServerId() int32 { + if x != nil && x.ServerId != nil { + return *x.ServerId + } + return 0 +} + +func (x *CMAddFriendRequest) GetTeamUuid() string { + if x != nil && x.TeamUuid != nil { + return *x.TeamUuid + } + return "" +} + +func (x *CMAddFriendRequest) GetAccountId() string { + if x != nil && x.AccountId != nil { + return *x.AccountId + } + return "" +} + +func (x *CMAddFriendRequest) GetAccount2Id() string { + if x != nil && x.Account2Id != nil { + return *x.Account2Id + } + return "" +} + +func (x *CMAddFriendRequest) GetSessionId() string { + if x != nil && x.SessionId != nil { + return *x.SessionId + } + return "" +} + +// 回复发送添加好友请求 +type SMAddFriendRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Reason *string `protobuf:"bytes,1,opt,name=reason" json:"reason,omitempty"` + Status *string `protobuf:"bytes,2,opt,name=status" json:"status,omitempty"` +} + +func (x *SMAddFriendRequest) Reset() { + *x = SMAddFriendRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_cs_proto_proto_msgTypes[14] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SMAddFriendRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SMAddFriendRequest) ProtoMessage() {} + +func (x *SMAddFriendRequest) ProtoReflect() protoreflect.Message { + mi := &file_cs_proto_proto_msgTypes[14] + 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 SMAddFriendRequest.ProtoReflect.Descriptor instead. +func (*SMAddFriendRequest) Descriptor() ([]byte, []int) { + return file_cs_proto_proto_rawDescGZIP(), []int{14} +} + +func (x *SMAddFriendRequest) GetReason() string { + if x != nil && x.Reason != nil { + return *x.Reason + } + return "" +} + +func (x *SMAddFriendRequest) GetStatus() string { + if x != nil && x.Status != nil { + return *x.Status + } + return "" +} + +// 同意接受发送添加好友请求 +type CMAcceptFriendRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ServerId *int32 `protobuf:"varint,1,opt,name=server_id,json=serverId" json:"server_id,omitempty"` //保留 + TeamUuid *string `protobuf:"bytes,2,opt,name=team_uuid,json=teamUuid" json:"team_uuid,omitempty"` //保留 + AccountId *string `protobuf:"bytes,3,opt,name=account_id,json=accountId" json:"account_id,omitempty"` //账号id + Account2Id *string `protobuf:"bytes,5,opt,name=account2_id,json=account2Id" json:"account2_id,omitempty"` // + SessionId *string `protobuf:"bytes,20,opt,name=session_id,json=sessionId" json:"session_id,omitempty"` //账号id +} + +func (x *CMAcceptFriendRequest) Reset() { + *x = CMAcceptFriendRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_cs_proto_proto_msgTypes[15] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CMAcceptFriendRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CMAcceptFriendRequest) ProtoMessage() {} + +func (x *CMAcceptFriendRequest) ProtoReflect() protoreflect.Message { + mi := &file_cs_proto_proto_msgTypes[15] + 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 CMAcceptFriendRequest.ProtoReflect.Descriptor instead. +func (*CMAcceptFriendRequest) Descriptor() ([]byte, []int) { + return file_cs_proto_proto_rawDescGZIP(), []int{15} +} + +func (x *CMAcceptFriendRequest) GetServerId() int32 { + if x != nil && x.ServerId != nil { + return *x.ServerId + } + return 0 +} + +func (x *CMAcceptFriendRequest) GetTeamUuid() string { + if x != nil && x.TeamUuid != nil { + return *x.TeamUuid + } + return "" +} + +func (x *CMAcceptFriendRequest) GetAccountId() string { + if x != nil && x.AccountId != nil { + return *x.AccountId + } + return "" +} + +func (x *CMAcceptFriendRequest) GetAccount2Id() string { + if x != nil && x.Account2Id != nil { + return *x.Account2Id + } + return "" +} + +func (x *CMAcceptFriendRequest) GetSessionId() string { + if x != nil && x.SessionId != nil { + return *x.SessionId + } + return "" +} + +// 同意接受发送添加好友请求 +type SMAcceptFriendRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Reason *string `protobuf:"bytes,1,opt,name=reason" json:"reason,omitempty"` + Status *string `protobuf:"bytes,2,opt,name=status" json:"status,omitempty"` +} + +func (x *SMAcceptFriendRequest) Reset() { + *x = SMAcceptFriendRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_cs_proto_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SMAcceptFriendRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SMAcceptFriendRequest) ProtoMessage() {} + +func (x *SMAcceptFriendRequest) ProtoReflect() protoreflect.Message { + mi := &file_cs_proto_proto_msgTypes[16] + 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 SMAcceptFriendRequest.ProtoReflect.Descriptor instead. +func (*SMAcceptFriendRequest) Descriptor() ([]byte, []int) { + return file_cs_proto_proto_rawDescGZIP(), []int{16} +} + +func (x *SMAcceptFriendRequest) GetReason() string { + if x != nil && x.Reason != nil { + return *x.Reason + } + return "" +} + +func (x *SMAcceptFriendRequest) GetStatus() string { + if x != nil && x.Status != nil { + return *x.Status + } + return "" +} + // 请求我的好友列表 type CMListFriend struct { state protoimpl.MessageState @@ -901,7 +1173,7 @@ type CMListFriend struct { func (x *CMListFriend) Reset() { *x = CMListFriend{} if protoimpl.UnsafeEnabled { - mi := &file_cs_proto_proto_msgTypes[13] + mi := &file_cs_proto_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -914,7 +1186,7 @@ func (x *CMListFriend) String() string { func (*CMListFriend) ProtoMessage() {} func (x *CMListFriend) ProtoReflect() protoreflect.Message { - mi := &file_cs_proto_proto_msgTypes[13] + mi := &file_cs_proto_proto_msgTypes[17] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -927,7 +1199,7 @@ func (x *CMListFriend) ProtoReflect() protoreflect.Message { // Deprecated: Use CMListFriend.ProtoReflect.Descriptor instead. func (*CMListFriend) Descriptor() ([]byte, []int) { - return file_cs_proto_proto_rawDescGZIP(), []int{13} + return file_cs_proto_proto_rawDescGZIP(), []int{17} } func (x *CMListFriend) GetServerId() int32 { @@ -978,7 +1250,7 @@ type MFFriend struct { func (x *MFFriend) Reset() { *x = MFFriend{} if protoimpl.UnsafeEnabled { - mi := &file_cs_proto_proto_msgTypes[14] + mi := &file_cs_proto_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -991,7 +1263,7 @@ func (x *MFFriend) String() string { func (*MFFriend) ProtoMessage() {} func (x *MFFriend) ProtoReflect() protoreflect.Message { - mi := &file_cs_proto_proto_msgTypes[14] + mi := &file_cs_proto_proto_msgTypes[18] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1004,7 +1276,7 @@ func (x *MFFriend) ProtoReflect() protoreflect.Message { // Deprecated: Use MFFriend.ProtoReflect.Descriptor instead. func (*MFFriend) Descriptor() ([]byte, []int) { - return file_cs_proto_proto_rawDescGZIP(), []int{14} + return file_cs_proto_proto_rawDescGZIP(), []int{18} } func (x *MFFriend) GetAccountId() string { @@ -1032,7 +1304,7 @@ type SMListFriend struct { func (x *SMListFriend) Reset() { *x = SMListFriend{} if protoimpl.UnsafeEnabled { - mi := &file_cs_proto_proto_msgTypes[15] + mi := &file_cs_proto_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1045,7 +1317,7 @@ func (x *SMListFriend) String() string { func (*SMListFriend) ProtoMessage() {} func (x *SMListFriend) ProtoReflect() protoreflect.Message { - mi := &file_cs_proto_proto_msgTypes[15] + mi := &file_cs_proto_proto_msgTypes[19] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1058,7 +1330,7 @@ func (x *SMListFriend) ProtoReflect() protoreflect.Message { // Deprecated: Use SMListFriend.ProtoReflect.Descriptor instead. func (*SMListFriend) Descriptor() ([]byte, []int) { - return file_cs_proto_proto_rawDescGZIP(), []int{15} + return file_cs_proto_proto_rawDescGZIP(), []int{19} } func (x *SMListFriend) GetFriends() []*MFFriend { @@ -1147,29 +1419,60 @@ var file_cs_proto_proto_rawDesc = []byte{ 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x38, 0x0a, 0x0e, 0x53, 0x4d, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x12, 0x26, 0x0a, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x63, 0x73, 0x2e, 0x4d, 0x46, 0x46, - 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x22, 0xab, - 0x01, 0x0a, 0x0c, 0x43, 0x4d, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x12, - 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x05, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, - 0x74, 0x65, 0x61, 0x6d, 0x5f, 0x75, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x08, 0x74, 0x65, 0x61, 0x6d, 0x55, 0x75, 0x69, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, - 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, - 0x0c, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, - 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x45, 0x0a, 0x08, - 0x4d, 0x46, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x63, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, - 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, - 0x61, 0x6d, 0x65, 0x22, 0x36, 0x0a, 0x0c, 0x53, 0x4d, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x72, 0x69, - 0x65, 0x6e, 0x64, 0x12, 0x26, 0x0a, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x63, 0x73, 0x2e, 0x4d, 0x46, 0x46, 0x72, 0x69, 0x65, - 0x6e, 0x64, 0x52, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x2a, 0x22, 0x0a, 0x0a, 0x43, - 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x5f, 0x65, 0x12, 0x14, 0x0a, 0x0c, 0x50, 0x72, 0x6f, - 0x74, 0x6f, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x10, 0xd1, 0xa2, 0xd5, 0xc4, 0x07, 0x42, - 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x63, 0x73, + 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x22, 0xad, + 0x01, 0x0a, 0x12, 0x43, 0x4d, 0x41, 0x64, 0x64, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, + 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x74, 0x65, 0x61, 0x6d, 0x5f, 0x75, 0x75, 0x69, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x74, 0x65, 0x61, 0x6d, 0x55, 0x75, 0x69, 0x64, 0x12, + 0x1d, 0x0a, 0x0a, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1f, + 0x0a, 0x0b, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x32, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0a, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x32, 0x49, 0x64, 0x12, + 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x14, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x44, + 0x0a, 0x12, 0x53, 0x4d, 0x41, 0x64, 0x64, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, + 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x22, 0xb0, 0x01, 0x0a, 0x15, 0x43, 0x4d, 0x41, 0x63, 0x63, 0x65, 0x70, + 0x74, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, + 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x74, + 0x65, 0x61, 0x6d, 0x5f, 0x75, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x74, 0x65, 0x61, 0x6d, 0x55, 0x75, 0x69, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x63, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x61, 0x63, 0x63, 0x6f, 0x75, + 0x6e, 0x74, 0x32, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x61, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x32, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, + 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, + 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x47, 0x0a, 0x15, 0x53, 0x4d, 0x41, 0x63, 0x63, + 0x65, 0x70, 0x74, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x22, 0xab, 0x01, 0x0a, 0x0c, 0x43, 0x4d, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x72, 0x69, 0x65, 0x6e, + 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1b, + 0x0a, 0x09, 0x74, 0x65, 0x61, 0x6d, 0x5f, 0x75, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x74, 0x65, 0x61, 0x6d, 0x55, 0x75, 0x69, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x61, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x0c, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, + 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x14, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x45, + 0x0a, 0x08, 0x4d, 0x46, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, + 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x36, 0x0a, 0x0c, 0x53, 0x4d, 0x4c, 0x69, 0x73, 0x74, 0x46, + 0x72, 0x69, 0x65, 0x6e, 0x64, 0x12, 0x26, 0x0a, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x63, 0x73, 0x2e, 0x4d, 0x46, 0x46, 0x72, + 0x69, 0x65, 0x6e, 0x64, 0x52, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x2a, 0x22, 0x0a, + 0x0a, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x5f, 0x65, 0x12, 0x14, 0x0a, 0x0c, 0x50, + 0x72, 0x6f, 0x74, 0x6f, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x10, 0xd1, 0xa2, 0xd5, 0xc4, + 0x07, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x63, 0x73, } var ( @@ -1185,29 +1488,33 @@ func file_cs_proto_proto_rawDescGZIP() []byte { } var file_cs_proto_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_cs_proto_proto_msgTypes = make([]protoimpl.MessageInfo, 16) +var file_cs_proto_proto_msgTypes = make([]protoimpl.MessageInfo, 20) var file_cs_proto_proto_goTypes = []interface{}{ - (ConstantE)(0), // 0: cs.Constant_e - (*CMPing)(nil), // 1: cs.CMPing - (*SMPing)(nil), // 2: cs.SMPing - (*SMRpcError)(nil), // 3: cs.SMRpcError - (*MFPair)(nil), // 4: cs.MFPair - (*MFPair64)(nil), // 5: cs.MFPair64 - (*MFTuple)(nil), // 6: cs.MFTuple - (*MFTupleString)(nil), // 7: cs.MFTupleString - (*CMLogin)(nil), // 8: cs.CMLogin - (*SMLogin)(nil), // 9: cs.SMLogin - (*CMReconnect)(nil), // 10: cs.CMReconnect - (*SMReconnect)(nil), // 11: cs.SMReconnect - (*CMSearchFriend)(nil), // 12: cs.CMSearchFriend - (*SMSearchFriend)(nil), // 13: cs.SMSearchFriend - (*CMListFriend)(nil), // 14: cs.CMListFriend - (*MFFriend)(nil), // 15: cs.MFFriend - (*SMListFriend)(nil), // 16: cs.SMListFriend + (ConstantE)(0), // 0: cs.Constant_e + (*CMPing)(nil), // 1: cs.CMPing + (*SMPing)(nil), // 2: cs.SMPing + (*SMRpcError)(nil), // 3: cs.SMRpcError + (*MFPair)(nil), // 4: cs.MFPair + (*MFPair64)(nil), // 5: cs.MFPair64 + (*MFTuple)(nil), // 6: cs.MFTuple + (*MFTupleString)(nil), // 7: cs.MFTupleString + (*CMLogin)(nil), // 8: cs.CMLogin + (*SMLogin)(nil), // 9: cs.SMLogin + (*CMReconnect)(nil), // 10: cs.CMReconnect + (*SMReconnect)(nil), // 11: cs.SMReconnect + (*CMSearchFriend)(nil), // 12: cs.CMSearchFriend + (*SMSearchFriend)(nil), // 13: cs.SMSearchFriend + (*CMAddFriendRequest)(nil), // 14: cs.CMAddFriendRequest + (*SMAddFriendRequest)(nil), // 15: cs.SMAddFriendRequest + (*CMAcceptFriendRequest)(nil), // 16: cs.CMAcceptFriendRequest + (*SMAcceptFriendRequest)(nil), // 17: cs.SMAcceptFriendRequest + (*CMListFriend)(nil), // 18: cs.CMListFriend + (*MFFriend)(nil), // 19: cs.MFFriend + (*SMListFriend)(nil), // 20: cs.SMListFriend } var file_cs_proto_proto_depIdxs = []int32{ - 15, // 0: cs.SMSearchFriend.friends:type_name -> cs.MFFriend - 15, // 1: cs.SMListFriend.friends:type_name -> cs.MFFriend + 19, // 0: cs.SMSearchFriend.friends:type_name -> cs.MFFriend + 19, // 1: cs.SMListFriend.friends:type_name -> cs.MFFriend 2, // [2:2] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name @@ -1378,7 +1685,7 @@ func file_cs_proto_proto_init() { } } file_cs_proto_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CMListFriend); i { + switch v := v.(*CMAddFriendRequest); i { case 0: return &v.state case 1: @@ -1390,7 +1697,7 @@ func file_cs_proto_proto_init() { } } file_cs_proto_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*MFFriend); i { + switch v := v.(*SMAddFriendRequest); i { case 0: return &v.state case 1: @@ -1402,6 +1709,54 @@ func file_cs_proto_proto_init() { } } file_cs_proto_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CMAcceptFriendRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cs_proto_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SMAcceptFriendRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cs_proto_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CMListFriend); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cs_proto_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MFFriend); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cs_proto_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SMListFriend); i { case 0: return &v.state @@ -1420,7 +1775,7 @@ func file_cs_proto_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_cs_proto_proto_rawDesc, NumEnums: 1, - NumMessages: 16, + NumMessages: 20, NumExtensions: 0, NumServices: 0, }, diff --git a/server/imserver/friendsmgr.go b/server/imserver/friendsmgr.go index cdd8a9d4..f8c33e30 100644 --- a/server/imserver/friendsmgr.go +++ b/server/imserver/friendsmgr.go @@ -2,7 +2,6 @@ package main import ( "cs" - "errors" "f5" "mt" "q5" @@ -67,42 +66,65 @@ func (fm *FriendsMgr) CMSearchFriends(hdr *f5.MsgHdr, msg *cs.CMSearchFriend) { wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, listFriend) } -// AddFriendRequest 发送好友请求 -func (fm *FriendsMgr) addFriendRequest(user1ID, user2ID string) error { - // Check if users exist - _, exists1 := fm.users[user1ID] - _, exists2 := fm.users[user2ID] - if !exists1 || !exists2 { - return errors.New("users not exist") - } - if fm.pendingReqs[user2ID] == nil { - fm.pendingReqs[user2ID] = make(map[string]bool) - } - fm.pendingReqs[user2ID][user1ID] = true +// CMAddFriendRequest 发送好友请求 +func (fm *FriendsMgr) CMAddFriendRequest(hdr *f5.MsgHdr, msg *cs.CMAddFriendRequest) { + response := &cs.SMAddFriendRequest{} - return nil + user1Id := msg.GetAccountId() + user2Id := msg.GetAccount2Id() + // Check if users exist + _, exists1 := fm.users[user1Id] + _, exists2 := fm.users[user2Id] + if !exists1 || !exists2 { + reason := "users not exist" + response.Reason = &reason + wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, response) + f5.GetSysLog().Info("CMAddFriendRequest: reason:%s, params: %s or %s\n", reason, user1Id, user2Id) + return + } + // 为 user2 创建等待验证好友请求 记录,由userid1 申请的 + if fm.pendingReqs[user2Id] == nil { + fm.pendingReqs[user2Id] = make(map[string]bool) + } + fm.pendingReqs[user2Id][user1Id] = true + + status := "pending" + response.Status = &status + wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, response) } -// AcceptFriendRequest 接受好友请求 -func (fm *FriendsMgr) acceptFriendRequest(user1ID, user2ID string) error { - if !fm.pendingReqs[user1ID][user2ID] { - return errors.New("no pending friend request from user1 to user2") +// CMAcceptFriendRequest 接受好友请求 +func (fm *FriendsMgr) CMAcceptFriendRequest(hdr *f5.MsgHdr, msg *cs.CMAcceptFriendRequest) { + response := &cs.SMAcceptFriendRequest{} + + user1Id := msg.GetAccountId() + user2Id := msg.GetAccount2Id() + if !fm.pendingReqs[user1Id][user2Id] { + reason := "no pending friend request from user1 to user2" + response.Reason = &reason + wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, response) + f5.GetSysLog().Info("CMAcceptFriendRequest: reason:%s, params: %s or %s\n", reason, user1Id, user2Id) + return } // Create a new friendship friendship := &Friendship{ - User1: fm.users[user1ID], - User2: fm.users[user2ID], + User1: fm.users[user1Id], + User2: fm.users[user2Id], } - fm.friendships[user1ID] = append(fm.friendships[user1ID], friendship) - fm.friendships[user2ID] = append(fm.friendships[user2ID], friendship) + fm.friendships[user1Id] = append(fm.friendships[user1Id], friendship) + fm.friendships[user2Id] = append(fm.friendships[user2Id], friendship) - delete(fm.pendingReqs[user1ID], user2ID) - if len(fm.pendingReqs[user1ID]) == 0 { - delete(fm.pendingReqs, user1ID) + // step1. delete db record + // step2. add friend history to db + delete(fm.pendingReqs[user1Id], user2Id) + if len(fm.pendingReqs[user1Id]) == 0 { + delete(fm.pendingReqs, user1Id) } - return nil + status := "approved" + response.Status = &status + wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, response) } // CMListFriend 我的好友列表 diff --git a/server/imserver/proto/cs_proto.proto b/server/imserver/proto/cs_proto.proto index a8527e5f..18d38724 100644 --- a/server/imserver/proto/cs_proto.proto +++ b/server/imserver/proto/cs_proto.proto @@ -134,6 +134,38 @@ message SMSearchFriend repeated MFFriend friends = 1; } +// 请求发送添加好友请求 +message CMAddFriendRequest +{ + optional int32 server_id = 1; //保留 + optional string team_uuid = 2; //保留 + optional string account_id = 3; //账号id + optional string account2_id = 5; // + optional string session_id = 20; //账号id +} +// 回复发送添加好友请求 +message SMAddFriendRequest +{ + optional string reason = 1; + optional string status = 2; +} + +// 同意接受发送添加好友请求 +message CMAcceptFriendRequest +{ + optional int32 server_id = 1; //保留 + optional string team_uuid = 2; //保留 + optional string account_id = 3; //账号id + optional string account2_id = 5; // + optional string session_id = 20; //账号id +} +// 同意接受发送添加好友请求 +message SMAcceptFriendRequest +{ + optional string reason = 1; + optional string status = 2; +} + // 请求我的好友列表 message CMListFriend {