From 43c75ecc5c95ef2f88d6f0789873afc996cf174c Mon Sep 17 00:00:00 2001 From: zhaocy Date: Thu, 9 Jun 2022 18:36:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A5=BD=E5=8F=8B=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=B5=8B=E8=AF=951?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/robot/friend.go | 16 +++-- cmd/robot/readme.md | 48 +++++++++++++ cmd/robot/robot.go | 5 +- modules/friend/friend_comp.go | 118 ++++++++++++++++++++++++++++--- modules/user/login_comp.go | 46 ++++++------ modules/user/user_comp.go | 13 ++-- modules/web/api_comp.go | 2 +- pb.bat | 8 +-- pb/errorcode.pb.go | 98 ++++++++++++++++++------- pb/friend_db.pb.go | 40 ++++++++--- pb/friend_msg.pb.go | 70 ++++++++++-------- pb/pack_db.pb.go | 4 +- pb/pack_msg.pb.go | 2 +- pb/proto/errorcode.proto | 17 ++++- pb/proto/friend/friend_db.proto | 7 +- pb/proto/friend/friend_msg.proto | 7 +- pb/proto/pack/pack_db.proto | 4 +- pb/user_db.pb.go | 2 +- sys/cache/friend.go | 42 ++++++++--- sys/cache/friend_test.go | 19 +++-- sys/db/friend.go | 19 +++-- sys/db/friend_test.go | 4 +- sys/db/user.go | 27 +++---- sys/db/user_test.go | 8 +-- utils/base64.go | 2 +- utils/strings.go | 10 +++ 26 files changed, 469 insertions(+), 169 deletions(-) diff --git a/cmd/robot/friend.go b/cmd/robot/friend.go index 14b28ce76..6e7bfa868 100644 --- a/cmd/robot/friend.go +++ b/cmd/robot/friend.go @@ -8,15 +8,17 @@ import ( func (r *Robot) handleFriendMsg(msg *pb.UserMessage) { switch msg.SubType { - case "add": - r.handleFriendAdd(msg) + case "apply": + r.handleFriendApply(msg) } } //添加好友 -func (r *Robot) FriendAdd() { - req := &pb.FriendAddReq{} - head := &pb.UserMessage{MainType: "friend", SubType: "add"} +func (r *Robot) FriendApply(friendId string) { + req := &pb.FriendApplyReq{ + FriendId: friendId, + } + head := &pb.UserMessage{MainType: "friend", SubType: "apply"} defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUserId(), req) err := r.SendToClient(head, req) if err != nil { @@ -24,8 +26,8 @@ func (r *Robot) FriendAdd() { } } -func (r *Robot) handleFriendAdd(msg *pb.UserMessage) { - rsp := &pb.FriendAddRsp{} +func (r *Robot) handleFriendApply(msg *pb.UserMessage) { + rsp := &pb.FriendApplyRsp{} if !comm.ProtoDecode(msg, rsp) { return } diff --git a/cmd/robot/readme.md b/cmd/robot/readme.md index 345e2fc58..1fe809ced 100644 --- a/cmd/robot/readme.md +++ b/cmd/robot/readme.md @@ -10,3 +10,51 @@ go run cmd.go run --account yourAccount #使用新账号测试接口 go run cmd.go run --account newAccount --create true ``` + +@[TOC] + + +### 添加测试接口 + +* 请求的方法 + +```go +// 好友申请,参数根据实际业务添加 +func (r *Robot) FriendApply(friendIds []string) { + ... +} +``` + +* 响应的方法 + +```go +func (r *Robot) handleFriendApply(msg *pb.UserMessage) { + ... +} +``` + +### 添加subType,调用响应方法 + +```go +//根据实际情况添加subtype +func (r *Robot) handleFriendMsg(msg *pb.UserMessage) { + switch msg.SubType { + case "apply": + //调用响应 + r.handleFriendApply(msg) + } +} +``` + +### 修改请求方法调用 + +```go +func (r *Robot) onUserLoaded() { + switch msg.MainType { + case "user": + r.handleUserMsg(msg) + case "friend": + r.handleFriendMsg(msg) + ... +} +``` \ No newline at end of file diff --git a/cmd/robot/robot.go b/cmd/robot/robot.go index d740acf54..d241a87eb 100644 --- a/cmd/robot/robot.go +++ b/cmd/robot/robot.go @@ -82,8 +82,11 @@ func (r *Robot) onUserLoaded() { r.CreateUser("user671") //friend - // r.FriendAdd() + r.FriendApply("629f147e3d276120561bfa18") + + //pack r.QueryUserPack() + } func (r *Robot) SendToClient(msg *pb.UserMessage, rsp proto.Message) error { diff --git a/modules/friend/friend_comp.go b/modules/friend/friend_comp.go index e41da828c..a4f56a009 100644 --- a/modules/friend/friend_comp.go +++ b/modules/friend/friend_comp.go @@ -3,12 +3,27 @@ package friend import ( "context" "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go_dreamfactory/sys/cache" + "go_dreamfactory/utils" +) + +const ( + Friend_SubType_Apply = "apply" ) type FriendComp struct { modules.MComp_GateComp + module *Friend +} + +func (this *FriendComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.MComp_GateComp.Init(service, module, comp, options) + this.module = module.(*Friend) + return } //搜索 @@ -17,17 +32,100 @@ func (this *FriendComp) Search(ctx context.Context, session comm.IUserSession, r } //添加好友 -func (this *FriendComp) Apply(ctx context.Context, session comm.IUserSession, req *pb.FriendAddReq) error { - //判断是否超过最大好友数量 - //判断对方是否也超过最大好友数量 - //判断是否是自己 - //判断是否是好友 - //判断是否已经申请 - //判断是否在黑名单中 - //判断是否在对方的黑名单中 +func (this *FriendComp) Apply(ctx context.Context, session comm.IUserSession, req *pb.FriendApplyReq) (err error) { + var ( + code pb.ErrorCode + self *pb.Cache_FriendData + target *pb.Cache_FriendData + rsp *pb.FriendApplyRsp + ) - - return nil + defer func() { + utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), Friend_SubType_Apply, req, rsp) + }() + + defer func() { + if code == pb.ErrorCode_Success { + rsp = &pb.FriendApplyRsp{ + UserId: session.GetUserId(), + FriendId: req.FriendId, + } + } + session.SendMsg(string(this.module.GetType()), Friend_SubType_Apply, code, rsp) + }() + + self, err = cache.Defsys.Friend_Get(session.GetUserId()) + if self == nil || err != nil { + code = pb.ErrorCode_FriendSelfNoData + return + } + + target, err = cache.Defsys.Friend_Get(req.FriendId) + if target == nil || err != nil { + code = pb.ErrorCode_FriendTargetNoData + return + } + + //判断是否是自己 + if req.FriendId == session.GetUserId() { + code = pb.ErrorCode_FriendNotSelf + return + } + + //判断是否超过最大好友数量 + //TODO 最大数从全局配置中获取 + var max int32 = 50 + total := cache.Defsys.Friend_Total(session.GetUserId()) + if total >= max { + code = pb.ErrorCode_FriendSelfMax + return + } + + //判断对方是否也超过最大好友数量 + ttotal := cache.Defsys.Friend_Total(req.FriendId) + if ttotal >= max { + code = pb.ErrorCode_FriendTargetMax + return + } + + //判断是否是好友 + if _, ok := utils.Find(self.FriendIds, req.FriendId); ok { + code = pb.ErrorCode_FriendYet + return + } + + //判断自己是否在目标用户的申请列表中 + if _, ok := utils.Find(target.ApplyIds, self.UserId); ok { + code = pb.ErrorCode_FriendApplyYet + return + } + + //判断目标用户是否在黑名单中 + if _, ok := utils.Find(self.BlackIds, req.FriendId); ok { + code = pb.ErrorCode_FriendSelfBlackYet + return + } + + //判断是否在对方的黑名单中 + if _, ok := utils.Find(target.BlackIds, self.UserId); ok { + code = pb.ErrorCode_FriendTargetBlackYet + return + } + + //将自己加入到目标用户的申请列表中 + target.ApplyIds = append(target.ApplyIds, self.UserId) + err = cache.Defsys.Friend_Apply(&pb.Cache_FriendData{ + UserId: req.FriendId, + ApplyIds: target.ApplyIds, + }) + + if err != nil { + log.Errorf("firend Apply err:%v", err) + code = pb.ErrorCode_FriendApplyError + return + } + + return } //删除好友 diff --git a/modules/user/login_comp.go b/modules/user/login_comp.go index 66f82e951..47cb2a565 100644 --- a/modules/user/login_comp.go +++ b/modules/user/login_comp.go @@ -22,8 +22,8 @@ type LoginComp struct { modules.MComp_GateComp } -func DecodeUserData(base64Str string) *pb.DB_UserData { - //解码 +//解码 +func decodeUserData(base64Str string) *pb.DB_UserData { dec, err := base64.StdEncoding.DecodeString(base64Str[35:]) if err != nil { log.Errorf("base64 decode err %v", err) @@ -44,17 +44,30 @@ func DecodeUserData(base64Str string) *pb.DB_UserData { } //登录 -func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req *pb.UserLoginReq) error { - log.Debugf("User - Login: session:%v rsp:%v", session.ToString(), req) - var code pb.ErrorCode = pb.ErrorCode_Success +func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req *pb.UserLoginReq) (err error) { + var ( + code pb.ErrorCode + db_user *pb.DB_UserData + ) + + defer func() { + session.SendMsg("user", "login", code, &pb.UserLoginResp{ + Data: &pb.Cache_UserData{ + UserData: db_user, + }, + }) + + event.TriggerEvent(comm.Event_UserLogin, db_user.UserId) + }() + if !utils.ValidSecretKey(req.Sec) { - session.SendMsg("user", "login", pb.ErrorCode_SecKeyInvalid, nil) - return nil + code = pb.ErrorCode_SecKeyInvalid + return } - user := DecodeUserData(req.Sec) + user := decodeUserData(req.Sec) - db_user, err := db.Defsys.User_FindUserByAccount(user) + db_user, err = db.Defsys.User_FindByAccount(user) if err != nil { if err != mongo.ErrNoDocuments { return err @@ -63,10 +76,10 @@ func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req //如果是新玩家,创建一条基础的数据,页面会引导进入创角页面 if db_user == nil { - err = db.Defsys.User_CreateUser(user) + err = db.Defsys.User_Create(user) if err != nil { log.Errorf("User_CreateUser err %v", err) - return err + return } session.Build(user.UserId) } else { @@ -84,16 +97,7 @@ func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req return err } - err = session.SendMsg("user", "login", code, &pb.UserLoginResp{ - Data: &pb.Cache_UserData{ - UserData: db_user, - }, - }) - if err != nil { - return err - } - event.TriggerEvent(comm.Event_UserLogin, db_user.UserId) - return nil + return } //注销 diff --git a/modules/user/user_comp.go b/modules/user/user_comp.go index 8031ff667..4151fb5ea 100644 --- a/modules/user/user_comp.go +++ b/modules/user/user_comp.go @@ -25,21 +25,24 @@ func (this *UserComp) Init(service core.IService, module core.IModule, comp core } //创角 -func (this *UserComp) Create(ctx context.Context, session comm.IUserSession, req *pb.UserCreateReq) error { +func (this *UserComp) Create(ctx context.Context, session comm.IUserSession, req *pb.UserCreateReq) (err error) { defer utils.TraceFunc(session.GetUserId(), "user", "create", req, nil) user := cache.Defsys.Get(session.GetUserId()) + var code pb.ErrorCode + defer func() { + session.SendMsg("user", "create", code, &pb.UserCreateRsp{}) + }() if user == nil { log.Errorf("user no exist") - session.SendMsg("user", "create", pb.ErrorCode_UserSessionNobeing, nil) - return nil + code = pb.ErrorCode_UserSessionNobeing + return } user.UserData.NiceName = req.NickName - err := cache.Defsys.Update(user) + err = cache.Defsys.Update(user) if err != nil { log.Errorf("cache update err") } event.RegisterGO(comm.Event_CreateUser, session.GetUserId()) - session.SendMsg("user", "create", pb.ErrorCode_Success, &pb.UserCreateRsp{}) return nil } diff --git a/modules/web/api_comp.go b/modules/web/api_comp.go index 64bfb7d97..f68b4adf5 100644 --- a/modules/web/api_comp.go +++ b/modules/web/api_comp.go @@ -37,7 +37,7 @@ func (this *Api_Comp) Register(c *engine.Context) { rsp := &pb.UserRegisterRsp{} err := c.BindJSON(&req) if err == nil { - err := db.Defsys.User_CreateUser(&pb.DB_UserData{ + err := db.Defsys.User_Create(&pb.DB_UserData{ Account: req.Account, }) if err != nil { diff --git a/pb.bat b/pb.bat index 1f12a60ee..417cb5d5f 100644 --- a/pb.bat +++ b/pb.bat @@ -1,12 +1,12 @@ @echo off -set PROJECT_ROOT=.\ +set PROJECT_ROOT=. set SRC=%PROJECT_ROOT%\pb\proto set TAR=%PROJECT_ROOT%\pb - -protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=source_relative %SRC%\*.proto -protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=source_relative %SRC%\*.proto +protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\*.proto +protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\friend\*.proto +protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\pack\*.proto pause \ No newline at end of file diff --git a/pb/errorcode.pb.go b/pb/errorcode.pb.go index 721cb3939..5bce39018 100644 --- a/pb/errorcode.pb.go +++ b/pb/errorcode.pb.go @@ -33,31 +33,53 @@ const ( ErrorCode_InsufficientPermissions ErrorCode = 16 //权限不足 ErrorCode_NoLogin ErrorCode = 17 //未登录 ErrorCode_UserSessionNobeing ErrorCode = 18 //用户不存在 - ErrorCode_SecKey ErrorCode = 19 //秘钥格式错误 - ErrorCode_SecKeyInvalid ErrorCode = 20 //秘钥无效 ErrorCode_StateInvalid ErrorCode = 21 //无效状态 ErrorCode_DBError ErrorCode = 22 // 数据库操作失败 ErrorCode_SystemError ErrorCode = 23 // 通用错误 + //user + ErrorCode_SecKeyInvalid ErrorCode = 1000 //秘钥无效 + ErrorCode_SecKey ErrorCode = 1001 //秘钥格式错误 + //friend + ErrorCode_FriendNotSelf ErrorCode = 1100 //不能是自己 + ErrorCode_FriendSelfMax ErrorCode = 1101 //超出好友最大数量 + ErrorCode_FriendTargetMax ErrorCode = 1102 //超出目标好友最大数量 + ErrorCode_FriendSelfNoData ErrorCode = 1103 //无好友记录 + ErrorCode_FriendTargetNoData ErrorCode = 1104 //无目标好友记录 + ErrorCode_FriendYet ErrorCode = 1105 //已是好友 + ErrorCode_FriendApplyYet ErrorCode = 1106 //已申请该好友 + ErrorCode_FriendSelfBlackYet ErrorCode = 1107 //已在自己黑名单中 + ErrorCode_FriendTargetBlackYet ErrorCode = 1108 //已在对方的黑名单中 + ErrorCode_FriendApplyError ErrorCode = 1109 //申请失败 ) // Enum value maps for ErrorCode. var ( ErrorCode_name = map[int32]string{ - 0: "Success", - 10: "NoFindService", - 11: "RpcFuncExecutionError", - 12: "CacheReadError", - 13: "SqlExecutionError", - 14: "ReqParameterError", - 15: "SignError", - 16: "InsufficientPermissions", - 17: "NoLogin", - 18: "UserSessionNobeing", - 19: "SecKey", - 20: "SecKeyInvalid", - 21: "StateInvalid", - 22: "DBError", - 23: "SystemError", + 0: "Success", + 10: "NoFindService", + 11: "RpcFuncExecutionError", + 12: "CacheReadError", + 13: "SqlExecutionError", + 14: "ReqParameterError", + 15: "SignError", + 16: "InsufficientPermissions", + 17: "NoLogin", + 18: "UserSessionNobeing", + 21: "StateInvalid", + 22: "DBError", + 23: "SystemError", + 1000: "SecKeyInvalid", + 1001: "SecKey", + 1100: "FriendNotSelf", + 1101: "FriendSelfMax", + 1102: "FriendTargetMax", + 1103: "FriendSelfNoData", + 1104: "FriendTargetNoData", + 1105: "FriendYet", + 1106: "FriendApplyYet", + 1107: "FriendSelfBlackYet", + 1108: "FriendTargetBlackYet", + 1109: "FriendApplyError", } ErrorCode_value = map[string]int32{ "Success": 0, @@ -70,11 +92,21 @@ var ( "InsufficientPermissions": 16, "NoLogin": 17, "UserSessionNobeing": 18, - "SecKey": 19, - "SecKeyInvalid": 20, "StateInvalid": 21, "DBError": 22, "SystemError": 23, + "SecKeyInvalid": 1000, + "SecKey": 1001, + "FriendNotSelf": 1100, + "FriendSelfMax": 1101, + "FriendTargetMax": 1102, + "FriendSelfNoData": 1103, + "FriendTargetNoData": 1104, + "FriendYet": 1105, + "FriendApplyYet": 1106, + "FriendSelfBlackYet": 1107, + "FriendTargetBlackYet": 1108, + "FriendApplyError": 1109, } ) @@ -109,7 +141,7 @@ var File_errorcode_proto protoreflect.FileDescriptor var file_errorcode_proto_rawDesc = []byte{ 0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2a, 0xa8, 0x02, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, + 0x6f, 0x2a, 0x88, 0x04, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12, 0x19, 0x0a, 0x15, 0x52, 0x70, 0x63, 0x46, 0x75, 0x6e, 0x63, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, @@ -122,12 +154,26 @@ var file_errorcode_proto_rawDesc = []byte{ 0x6e, 0x73, 0x75, 0x66, 0x66, 0x69, 0x63, 0x69, 0x65, 0x6e, 0x74, 0x50, 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x10, 0x10, 0x12, 0x0b, 0x0a, 0x07, 0x4e, 0x6f, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x10, 0x11, 0x12, 0x16, 0x0a, 0x12, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, - 0x73, 0x69, 0x6f, 0x6e, 0x4e, 0x6f, 0x62, 0x65, 0x69, 0x6e, 0x67, 0x10, 0x12, 0x12, 0x0a, 0x0a, - 0x06, 0x53, 0x65, 0x63, 0x4b, 0x65, 0x79, 0x10, 0x13, 0x12, 0x11, 0x0a, 0x0d, 0x53, 0x65, 0x63, - 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0x14, 0x12, 0x10, 0x0a, 0x0c, - 0x53, 0x74, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0x15, 0x12, 0x0b, - 0x0a, 0x07, 0x44, 0x42, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x16, 0x12, 0x0f, 0x0a, 0x0b, 0x53, - 0x79, 0x73, 0x74, 0x65, 0x6d, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x17, 0x42, 0x06, 0x5a, 0x04, + 0x73, 0x69, 0x6f, 0x6e, 0x4e, 0x6f, 0x62, 0x65, 0x69, 0x6e, 0x67, 0x10, 0x12, 0x12, 0x10, 0x0a, + 0x0c, 0x53, 0x74, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0x15, 0x12, + 0x0b, 0x0a, 0x07, 0x44, 0x42, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x16, 0x12, 0x0f, 0x0a, 0x0b, + 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x17, 0x12, 0x12, 0x0a, + 0x0d, 0x53, 0x65, 0x63, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0xe8, + 0x07, 0x12, 0x0b, 0x0a, 0x06, 0x53, 0x65, 0x63, 0x4b, 0x65, 0x79, 0x10, 0xe9, 0x07, 0x12, 0x12, + 0x0a, 0x0d, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x4e, 0x6f, 0x74, 0x53, 0x65, 0x6c, 0x66, 0x10, + 0xcc, 0x08, 0x12, 0x12, 0x0a, 0x0d, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x53, 0x65, 0x6c, 0x66, + 0x4d, 0x61, 0x78, 0x10, 0xcd, 0x08, 0x12, 0x14, 0x0a, 0x0f, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, + 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x4d, 0x61, 0x78, 0x10, 0xce, 0x08, 0x12, 0x15, 0x0a, 0x10, + 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x53, 0x65, 0x6c, 0x66, 0x4e, 0x6f, 0x44, 0x61, 0x74, 0x61, + 0x10, 0xcf, 0x08, 0x12, 0x17, 0x0a, 0x12, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, + 0x67, 0x65, 0x74, 0x4e, 0x6f, 0x44, 0x61, 0x74, 0x61, 0x10, 0xd0, 0x08, 0x12, 0x0e, 0x0a, 0x09, + 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x59, 0x65, 0x74, 0x10, 0xd1, 0x08, 0x12, 0x13, 0x0a, 0x0e, + 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x59, 0x65, 0x74, 0x10, 0xd2, + 0x08, 0x12, 0x17, 0x0a, 0x12, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x53, 0x65, 0x6c, 0x66, 0x42, + 0x6c, 0x61, 0x63, 0x6b, 0x59, 0x65, 0x74, 0x10, 0xd3, 0x08, 0x12, 0x19, 0x0a, 0x14, 0x46, 0x72, + 0x69, 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x42, 0x6c, 0x61, 0x63, 0x6b, 0x59, + 0x65, 0x74, 0x10, 0xd4, 0x08, 0x12, 0x15, 0x0a, 0x10, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, + 0x70, 0x70, 0x6c, 0x79, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0xd5, 0x08, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } diff --git a/pb/friend_db.pb.go b/pb/friend_db.pb.go index c961ac9aa..8e5d8ac2a 100644 --- a/pb/friend_db.pb.go +++ b/pb/friend_db.pb.go @@ -25,8 +25,10 @@ type Cache_FriendData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId,omitempty" bson:"_id"` //tags:{bson:"_id"}用户Id - FriendId []string `protobuf:"bytes,2,rep,name=friendId,proto3" json:"friendId,omitempty"` + UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId,omitempty" bson:"_id"` // ID + FriendIds []string `protobuf:"bytes,2,rep,name=friendIds,proto3" json:"friendIds,omitempty"` //好友ID + ApplyIds []string `protobuf:"bytes,3,rep,name=applyIds,proto3" json:"applyIds,omitempty"` //申请用户ID + BlackIds []string `protobuf:"bytes,4,rep,name=blackIds,proto3" json:"blackIds,omitempty"` //黑名单ID } func (x *Cache_FriendData) Reset() { @@ -68,9 +70,23 @@ func (x *Cache_FriendData) GetUserId() string { return "" } -func (x *Cache_FriendData) GetFriendId() []string { +func (x *Cache_FriendData) GetFriendIds() []string { if x != nil { - return x.FriendId + return x.FriendIds + } + return nil +} + +func (x *Cache_FriendData) GetApplyIds() []string { + if x != nil { + return x.ApplyIds + } + return nil +} + +func (x *Cache_FriendData) GetBlackIds() []string { + if x != nil { + return x.BlackIds } return nil } @@ -79,12 +95,16 @@ var File_friend_friend_db_proto protoreflect.FileDescriptor var file_friend_friend_db_proto_rawDesc = []byte{ 0x0a, 0x16, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x2f, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x5f, - 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x46, 0x0a, 0x10, 0x43, 0x61, 0x63, 0x68, - 0x65, 0x5f, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, - 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, - 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, - 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, - 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x80, 0x01, 0x0a, 0x10, 0x43, 0x61, 0x63, + 0x68, 0x65, 0x5f, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, + 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, + 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, + 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, + 0x49, 0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x49, 0x64, 0x73, 0x18, + 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x49, 0x64, 0x73, 0x12, + 0x1a, 0x0a, 0x08, 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x49, 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, + 0x09, 0x52, 0x08, 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x49, 0x64, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, + 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pb/friend_msg.pb.go b/pb/friend_msg.pb.go index 7770af397..8cf76b816 100644 --- a/pb/friend_msg.pb.go +++ b/pb/friend_msg.pb.go @@ -201,8 +201,8 @@ func (x *FriendListRsp) GetList() []*Cache_FriendData { return nil } -//添加好友 -type FriendAddReq struct { +//申请好友 +type FriendApplyReq struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -210,8 +210,8 @@ type FriendAddReq struct { FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` //好友ID } -func (x *FriendAddReq) Reset() { - *x = FriendAddReq{} +func (x *FriendApplyReq) Reset() { + *x = FriendApplyReq{} if protoimpl.UnsafeEnabled { mi := &file_friend_friend_msg_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -219,13 +219,13 @@ func (x *FriendAddReq) Reset() { } } -func (x *FriendAddReq) String() string { +func (x *FriendApplyReq) String() string { return protoimpl.X.MessageStringOf(x) } -func (*FriendAddReq) ProtoMessage() {} +func (*FriendApplyReq) ProtoMessage() {} -func (x *FriendAddReq) ProtoReflect() protoreflect.Message { +func (x *FriendApplyReq) ProtoReflect() protoreflect.Message { mi := &file_friend_friend_msg_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -237,28 +237,29 @@ func (x *FriendAddReq) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use FriendAddReq.ProtoReflect.Descriptor instead. -func (*FriendAddReq) Descriptor() ([]byte, []int) { +// Deprecated: Use FriendApplyReq.ProtoReflect.Descriptor instead. +func (*FriendApplyReq) Descriptor() ([]byte, []int) { return file_friend_friend_msg_proto_rawDescGZIP(), []int{3} } -func (x *FriendAddReq) GetFriendId() string { +func (x *FriendApplyReq) GetFriendId() string { if x != nil { return x.FriendId } return "" } -type FriendAddRsp struct { +type FriendApplyRsp struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId,omitempty"` //用户ID + UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId,omitempty"` //用户ID + FriendId string `protobuf:"bytes,2,opt,name=friendId,proto3" json:"friendId,omitempty"` //好友ID } -func (x *FriendAddRsp) Reset() { - *x = FriendAddRsp{} +func (x *FriendApplyRsp) Reset() { + *x = FriendApplyRsp{} if protoimpl.UnsafeEnabled { mi := &file_friend_friend_msg_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -266,13 +267,13 @@ func (x *FriendAddRsp) Reset() { } } -func (x *FriendAddRsp) String() string { +func (x *FriendApplyRsp) String() string { return protoimpl.X.MessageStringOf(x) } -func (*FriendAddRsp) ProtoMessage() {} +func (*FriendApplyRsp) ProtoMessage() {} -func (x *FriendAddRsp) ProtoReflect() protoreflect.Message { +func (x *FriendApplyRsp) ProtoReflect() protoreflect.Message { mi := &file_friend_friend_msg_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -284,18 +285,25 @@ func (x *FriendAddRsp) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use FriendAddRsp.ProtoReflect.Descriptor instead. -func (*FriendAddRsp) Descriptor() ([]byte, []int) { +// Deprecated: Use FriendApplyRsp.ProtoReflect.Descriptor instead. +func (*FriendApplyRsp) Descriptor() ([]byte, []int) { return file_friend_friend_msg_proto_rawDescGZIP(), []int{4} } -func (x *FriendAddRsp) GetUserId() string { +func (x *FriendApplyRsp) GetUserId() string { if x != nil { return x.UserId } return "" } +func (x *FriendApplyRsp) GetFriendId() string { + if x != nil { + return x.FriendId + } + return "" +} + //删除好友 type FriendDelReq struct { state protoimpl.MessageState @@ -1124,12 +1132,14 @@ var file_friend_friend_msg_proto_rawDesc = []byte{ 0x0d, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x73, 0x70, 0x12, 0x25, 0x0a, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x43, 0x61, 0x63, 0x68, 0x65, 0x5f, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x44, 0x61, 0x74, 0x61, 0x52, - 0x04, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x2a, 0x0a, 0x0c, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, - 0x64, 0x64, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, - 0x64, 0x22, 0x26, 0x0a, 0x0c, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, 0x64, 0x64, 0x52, 0x73, - 0x70, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x2a, 0x0a, 0x0c, 0x46, 0x72, 0x69, + 0x04, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x2c, 0x0a, 0x0e, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, + 0x70, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, + 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, + 0x64, 0x49, 0x64, 0x22, 0x44, 0x0a, 0x0e, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, 0x70, 0x70, + 0x6c, 0x79, 0x52, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, + 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x22, 0x2a, 0x0a, 0x0c, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x44, 0x65, 0x6c, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x22, 0x42, 0x0a, 0x0c, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x44, @@ -1209,8 +1219,8 @@ var file_friend_friend_msg_proto_goTypes = []interface{}{ (*FriendBase)(nil), // 0: FriendBase (*FriendListReq)(nil), // 1: FriendListReq (*FriendListRsp)(nil), // 2: FriendListRsp - (*FriendAddReq)(nil), // 3: FriendAddReq - (*FriendAddRsp)(nil), // 4: FriendAddRsp + (*FriendApplyReq)(nil), // 3: FriendApplyReq + (*FriendApplyRsp)(nil), // 4: FriendApplyRsp (*FriendDelReq)(nil), // 5: FriendDelReq (*FriendDelRsp)(nil), // 6: FriendDelRsp (*FriendAgreeOrRefuseReq)(nil), // 7: FriendAgreeOrRefuseReq @@ -1284,7 +1294,7 @@ func file_friend_friend_msg_proto_init() { } } file_friend_friend_msg_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*FriendAddReq); i { + switch v := v.(*FriendApplyReq); i { case 0: return &v.state case 1: @@ -1296,7 +1306,7 @@ func file_friend_friend_msg_proto_init() { } } file_friend_friend_msg_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*FriendAddRsp); i { + switch v := v.(*FriendApplyRsp); i { case 0: return &v.state case 1: diff --git a/pb/pack_db.pb.go b/pb/pack_db.pb.go index 73460579a..c55ce43db 100644 --- a/pb/pack_db.pb.go +++ b/pb/pack_db.pb.go @@ -106,8 +106,8 @@ type DB_UserPackData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId string `protobuf:"bytes,1,opt,name=UserId,proto3" json:"UserId,omitempty" bson:"_id"` //tags:{bson:"_id"}用户Id - Pack []*DB_GridData `protobuf:"bytes,2,rep,name=Pack,proto3" json:"Pack,omitempty"` //背包列表 + UserId string `protobuf:"bytes,1,opt,name=UserId,proto3" json:"UserId,omitempty" bson:"_id"` // 用户Id + Pack []*DB_GridData `protobuf:"bytes,2,rep,name=Pack,proto3" json:"Pack,omitempty"` //背包列表 } func (x *DB_UserPackData) Reset() { diff --git a/pb/pack_msg.pb.go b/pb/pack_msg.pb.go index 92d88648a..cd1be6dad 100644 --- a/pb/pack_msg.pb.go +++ b/pb/pack_msg.pb.go @@ -219,7 +219,7 @@ func (*UseItemResp) Descriptor() ([]byte, []int) { return file_pack_pack_msg_proto_rawDescGZIP(), []int{3} } -//出售道具请求 +//出售道具请求sailitem type SellItemReq struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache diff --git a/pb/proto/errorcode.proto b/pb/proto/errorcode.proto index 63e6db91b..aa9b1b11d 100644 --- a/pb/proto/errorcode.proto +++ b/pb/proto/errorcode.proto @@ -13,10 +13,23 @@ enum ErrorCode { InsufficientPermissions = 16; //权限不足 NoLogin = 17; //未登录 UserSessionNobeing = 18; //用户不存在 - SecKey = 19; //秘钥格式错误 - SecKeyInvalid = 20; //秘钥无效 StateInvalid = 21; //无效状态 DBError = 22; // 数据库操作失败 SystemError = 23; // 通用错误 + //user + SecKeyInvalid = 1000; //秘钥无效 + SecKey = 1001; //秘钥格式错误 + + //friend + FriendNotSelf = 1100; //不能是自己 + FriendSelfMax = 1101; //超出好友最大数量 + FriendTargetMax = 1102;//超出目标好友最大数量 + FriendSelfNoData = 1103; //无好友记录 + FriendTargetNoData = 1104; //无目标好友记录 + FriendYet = 1105; //已是好友 + FriendApplyYet =1106; //已申请该好友 + FriendSelfBlackYet = 1107;//已在自己黑名单中 + FriendTargetBlackYet = 1108;//已在对方的黑名单中 + FriendApplyError = 1109;//申请失败 } \ No newline at end of file diff --git a/pb/proto/friend/friend_db.proto b/pb/proto/friend/friend_db.proto index 3261f6da9..b93ff5adb 100644 --- a/pb/proto/friend/friend_db.proto +++ b/pb/proto/friend/friend_db.proto @@ -3,6 +3,9 @@ option go_package = ".;pb"; message Cache_FriendData { - string userId = 1; //tags:{bson:"_id"}用户Id - repeated string friendId = 2; + string userId = 1;// @go_tags(`json:"userId,omitempty" bson:"_id"`) ID + repeated string friendIds = 2; //好友ID + repeated string applyIds = 3;//申请用户ID + repeated string blackIds = 4;//黑名单ID + } \ No newline at end of file diff --git a/pb/proto/friend/friend_msg.proto b/pb/proto/friend/friend_msg.proto index 8f10ab953..1ae8f1dd6 100644 --- a/pb/proto/friend/friend_msg.proto +++ b/pb/proto/friend/friend_msg.proto @@ -21,12 +21,13 @@ message FriendListRsp{ repeated Cache_FriendData list = 1; } -//添加好友 -message FriendAddReq{ +//申请好友 +message FriendApplyReq{ string friendId = 1; //好友ID } -message FriendAddRsp{ +message FriendApplyRsp{ string userId = 1; //用户ID + string friendId =2;//好友ID } //删除好友 diff --git a/pb/proto/pack/pack_db.proto b/pb/proto/pack/pack_db.proto index 6cafe582e..a0e5ea47d 100644 --- a/pb/proto/pack/pack_db.proto +++ b/pb/proto/pack/pack_db.proto @@ -13,6 +13,6 @@ message DB_GridData { //用户背包 message DB_UserPackData { - string UserId = 1; //tags:{bson:"_id"}用户Id - repeated DB_GridData Pack = 2; //背包列表 + string UserId = 1; // @go_tags(`bson:"_id"`) 用户Id + repeated DB_GridData Pack = 2; //背包列表 } \ No newline at end of file diff --git a/pb/user_db.pb.go b/pb/user_db.pb.go index 8d954cb8b..1ea0a64fc 100644 --- a/pb/user_db.pb.go +++ b/pb/user_db.pb.go @@ -88,7 +88,7 @@ type DB_UserData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId string `protobuf:"bytes,1,opt,name=UserId,proto3" json:"UserId,omitempty" bson:"_id"` //tags:{bson:"_id"}动态Id + UserId string `protobuf:"bytes,1,opt,name=UserId,proto3" json:"UserId,omitempty"` //tags:{bson:"_id"}动态Id Account string `protobuf:"bytes,2,opt,name=Account,proto3" json:"Account,omitempty"` NiceName string `protobuf:"bytes,3,opt,name=NiceName,proto3" json:"NiceName,omitempty"` ServerId int32 `protobuf:"varint,4,opt,name=ServerId,proto3" json:"ServerId,omitempty"` diff --git a/sys/cache/friend.go b/sys/cache/friend.go index 0ae639584..c21d472bd 100644 --- a/sys/cache/friend.go +++ b/sys/cache/friend.go @@ -2,35 +2,57 @@ package cache import ( "fmt" + "go_dreamfactory/lego/sys/redis" "go_dreamfactory/pb" "go_dreamfactory/sys/db" ) const ( //Redis Redis_FriendCache string = "friend:%s" + Redis_Friend string = "apply:%s" ) -func getRdsUserKey(userId string) string { - return fmt.Sprintf(Redis_UserCache, userId) +func getRdsFriendKey(userId string) string { + return fmt.Sprintf(Redis_FriendCache, userId) } type IFriend interface { - FriendAdd(data *pb.Cache_FriendData) (err error) - FriendGetTotal(userId string) int32 + Friend_Apply(data *pb.Cache_FriendData) (err error) + Friend_Total(userId string) int32 + Friend_Get(userId string) (*pb.Cache_FriendData, error) } -func (this *Cache) FriendAdd(data *pb.Cache_FriendData) (err error) { - if err = db.Defsys.FriendApply(data); err == nil { - err = this.redis.Set(fmt.Sprintf(Redis_FriendCache, data.UserId), data, 0) +//好友申请 +func (this *Cache) Friend_Apply(data *pb.Cache_FriendData) (err error) { + if err = db.Defsys.Friend_Apply(data); err == nil { + err = this.redis.Set(getRdsFriendKey(data.UserId), data, 0) } return } -func (this *Cache) FriendGetTotal(userId string) int32 { +//好友总数 +func (this *Cache) Friend_Total(userId string) int32 { var friend *pb.Cache_FriendData - err := this.redis.Get(getRdsUserKey(userId), &friend) + err := this.redis.Get(getRdsFriendKey(userId), &friend) if err != nil { return 0 } - return int32(len(friend.FriendId)) + return int32(len(friend.FriendIds)) +} + +//好友获取 +func (this *Cache) Friend_Get(userId string) (*pb.Cache_FriendData, error) { + var d *pb.Cache_FriendData + err := this.redis.Get(getRdsFriendKey(userId), &d) + if err != nil { + if err.Error() == string(redis.RedisNil) { + d = &pb.Cache_FriendData{UserId: userId} + err = this.Friend_Apply(d) + if err != nil { + return d, nil + } + } + return nil, err + } + return d, nil } diff --git a/sys/cache/friend_test.go b/sys/cache/friend_test.go index 5e7d1d234..59e673dd9 100644 --- a/sys/cache/friend_test.go +++ b/sys/cache/friend_test.go @@ -9,16 +9,23 @@ import ( "github.com/stretchr/testify/require" ) -func TestFriendAdd(t *testing.T) { - err := cache.Defsys.FriendAdd(&pb.Cache_FriendData{ - UserId: "629f159310d6970846f7ef26", - FriendId: []string{"629f147e3d276120561bfa18", "629eb3f4132dc4bb26139659"}, +func TestFriendApply(t *testing.T) { + err := cache.Defsys.Friend_Apply(&pb.Cache_FriendData{ + UserId: "629f159310d6970846f7ef26", + FriendIds: []string{"629f147e3d276120561bfa18"}, + ApplyIds: []string{"629eb3f4132dc4bb26139659"}, }) require.Nil(t, err, nil) } func TestFriendGetTotal(t *testing.T) { - total := cache.Defsys.FriendGetTotal("629f159310d6970846f7ef26") - assert.Equal(t, total, int32(1)) + total := cache.Defsys.Friend_Total("629f159310d6970846f7ef26") + assert.Equal(t, total, int32(2)) +} + +func TestFriendGet(t *testing.T) { + data, err := cache.Defsys.Friend_Get("629f159310d6970846f7ef26") + require.NotNil(t, err, nil) + assert.Equal(t, data.UserId, "629f159310d6970846f7ef26") } diff --git a/sys/db/friend.go b/sys/db/friend.go index 226fdcb5d..ba0924330 100644 --- a/sys/db/friend.go +++ b/sys/db/friend.go @@ -5,6 +5,7 @@ import ( "go_dreamfactory/pb" "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" ) @@ -13,13 +14,21 @@ const ( ) type IFriend interface { - FriendApply(data *pb.Cache_FriendData) error + Friend_Apply(data *pb.Cache_FriendData) (err error) } -func (this *DB) FriendApply(data *pb.Cache_FriendData) error { - err := this.mgo.FindOneAndUpdate(DB_FriendTable, +//好友申请 +func (this *DB) Friend_Apply(data *pb.Cache_FriendData) (err error) { + err = this.mgo.FindOneAndUpdate(DB_FriendTable, bson.M{"_id": data.UserId}, - bson.M{"$set": bson.M{"friendid": data.FriendId}}, + bson.M{"$set": bson.M{ + "friendids": data.FriendIds, + "applyids": data.ApplyIds}}, options.FindOneAndUpdate().SetUpsert(true)).Err() - return err + if err != nil { + if err == mongo.ErrNoDocuments { + _, err = this.mgo.InsertOne(DB_FriendTable, data) + } + } + return } diff --git a/sys/db/friend_test.go b/sys/db/friend_test.go index a22de4f64..b86c09c46 100644 --- a/sys/db/friend_test.go +++ b/sys/db/friend_test.go @@ -8,9 +8,9 @@ import ( ) func TestFriendAdd(t *testing.T) { - err := db.FriendApply(&pb.Cache_FriendData{ + err := db.Friend_Apply(&pb.Cache_FriendData{ UserId: "629f159310d6970846f7ef26", - FriendId: []string{ + FriendIds: []string{ "629f147e3d276120561bfa18", }, }) diff --git a/sys/db/user.go b/sys/db/user.go index 88c7cbd07..3f897dae0 100644 --- a/sys/db/user.go +++ b/sys/db/user.go @@ -15,16 +15,17 @@ const ( //Redis ) type IUser interface { - User_FindUserByAccount(user *pb.DB_UserData) (*pb.DB_UserData, error) - User_FindUserById(id string) (*pb.DB_UserData, error) - User_CreateUser(user *pb.DB_UserData) error - User_UpdateUser(data *pb.DB_UserData) (err error) + User_FindByAccount(user *pb.DB_UserData) (*pb.DB_UserData, error) + User_FindById(id string) (*pb.DB_UserData, error) + User_Create(user *pb.DB_UserData) error + User_Update(data *pb.DB_UserData) (err error) } -func (this *DB) User_FindUserByAccount(user *pb.DB_UserData) (*pb.DB_UserData, error) { - filter := bson.D{ - {"serverid", user.ServerId}, - {"account", user.Account}, +// +func (this *DB) User_FindByAccount(user *pb.DB_UserData) (*pb.DB_UserData, error) { + filter := bson.M{ + "serverid": user.ServerId, + "account": user.Account, } sr := this.mgo.FindOne(DB_UserTable, filter) var nd *pb.DB_UserData @@ -32,9 +33,9 @@ func (this *DB) User_FindUserByAccount(user *pb.DB_UserData) (*pb.DB_UserData, e return nd, err } -func (this *DB) User_FindUserById(id string) (*pb.DB_UserData, error) { - filter := bson.D{ - {"_id", id}, +func (this *DB) User_FindById(id string) (*pb.DB_UserData, error) { + filter := bson.M{ + "_id": id, } sr := this.mgo.FindOne(DB_UserTable, filter) user := &pb.DB_UserData{} @@ -42,14 +43,14 @@ func (this *DB) User_FindUserById(id string) (*pb.DB_UserData, error) { return user, err } -func (this *DB) User_CreateUser(user *pb.DB_UserData) (err error) { +func (this *DB) User_Create(user *pb.DB_UserData) (err error) { user.UserId = primitive.NewObjectID().Hex() _, err = this.mgo.InsertOne(DB_UserTable, user) return err } //更新用户数据到DB -func (this *DB) User_UpdateUser(data *pb.DB_UserData) (err error) { +func (this *DB) User_Update(data *pb.DB_UserData) (err error) { err = this.mgo.FindOneAndUpdate( DB_UserTable, bson.M{"_id": data.UserId}, diff --git a/sys/db/user_test.go b/sys/db/user_test.go index 917e3d07a..3d26c2b7b 100644 --- a/sys/db/user_test.go +++ b/sys/db/user_test.go @@ -16,17 +16,17 @@ func TestCreate(t *testing.T) { ServerId: 1, } - err := db.User_CreateUser(user) + err := db.User_Create(user) require.Nil(t, err) } func TestFindOne(t *testing.T) { - user, err := db.User_FindUserById("629eb3f4132dc4bb26139659") + user, err := db.User_FindById("629eb3f4132dc4bb26139659") require.Nil(t, err) assert.Equal(t, "legu3", user.Account) // user.ServerId = 2 - user2, err := db.User_FindUserByAccount(user) + user2, err := db.User_FindByAccount(user) require.Nil(t, err) assert.Equal(t, "legu3", user2.Account) assert.Equal(t, int32(1), user2.ServerId) @@ -36,7 +36,7 @@ func TestUpdate(t *testing.T) { user := &pb.DB_UserData{ UserId: primitive.NewObjectID().Hex(), } - err := db.User_UpdateUser(user) + err := db.User_Update(user) require.Nil(t, err) assert.Equal(t, "NiceName", "") diff --git a/utils/base64.go b/utils/base64.go index 7676f36e4..9557d5bce 100644 --- a/utils/base64.go +++ b/utils/base64.go @@ -20,6 +20,7 @@ func Base64Decode(data string) string { return string(b) } +//校验加密串 func ValidSecretKey(secStr string) bool { if !strings.HasPrefix(secStr, "CE:") || len(secStr) < 35 { return false @@ -29,7 +30,6 @@ func ValidSecretKey(secStr string) bool { rawmsg := secStr[35:] log.Debugf("data base: %s", rawmsg) serverMd5Key := MD5Str(rawmsg) - // s := fmt.Sprintf("%x", serverMd5Key) if !strings.EqualFold(strings.ToLower(serverMd5Key), strings.ToLower(clientMd5Key)) { return false } diff --git a/utils/strings.go b/utils/strings.go index 34d87e3ed..82dcea71e 100644 --- a/utils/strings.go +++ b/utils/strings.go @@ -15,3 +15,13 @@ func ParseP(p string) (string, string, bool) { return s[0], s[1], true } + + +func Find(slice []string, val string) (int, bool) { + for i, item := range slice { + if item == val { + return i, true + } + } + return -1, false +} \ No newline at end of file From 9277322537cbf44f9b774716cbed87be8f241647 Mon Sep 17 00:00:00 2001 From: zhaocy Date: Thu, 9 Jun 2022 19:03:58 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=A5=BD=E5=8F=8B?= =?UTF-8?q?=E6=8E=A5=E5=8F=A32?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/robot/pack.go | 2 +- modules/friend/friend_comp.go | 48 +++++++++++-- pb/friend_msg.pb.go | 111 +++++++++++++++++-------------- pb/proto/friend/friend_msg.proto | 2 +- 4 files changed, 106 insertions(+), 57 deletions(-) diff --git a/cmd/robot/pack.go b/cmd/robot/pack.go index 80c1b8912..4bdecfc09 100644 --- a/cmd/robot/pack.go +++ b/cmd/robot/pack.go @@ -9,7 +9,7 @@ import ( func (r *Robot) handlePackMsg(msg *pb.UserMessage) { switch msg.SubType { case "queryuserpackresp": - r.handleFriendAdd(msg) + r.handleQueryUserPack(msg) } } diff --git a/modules/friend/friend_comp.go b/modules/friend/friend_comp.go index a4f56a009..f0e48dc2c 100644 --- a/modules/friend/friend_comp.go +++ b/modules/friend/friend_comp.go @@ -12,7 +12,8 @@ import ( ) const ( - Friend_SubType_Apply = "apply" + Friend_SubType_Apply = "apply" + Friend_SubType_ApplyList = "applylist" ) type FriendComp struct { @@ -31,7 +32,7 @@ func (this *FriendComp) Search(ctx context.Context, session comm.IUserSession, r return nil } -//添加好友 +//好友申请 func (this *FriendComp) Apply(ctx context.Context, session comm.IUserSession, req *pb.FriendApplyReq) (err error) { var ( code pb.ErrorCode @@ -128,6 +129,40 @@ func (this *FriendComp) Apply(ctx context.Context, session comm.IUserSession, re return } +//申请列表 +func (this *FriendComp) ApplyList(ctx context.Context, session comm.IUserSession, req *pb.FriendApplyListReq) (err error) { + var ( + code pb.ErrorCode + self *pb.Cache_FriendData + rsp *pb.FriendApplyListRsp + list []*pb.FriendBase + ) + + self, err = cache.Defsys.Friend_Get(session.GetUserId()) + if self == nil || err != nil { + code = pb.ErrorCode_FriendSelfNoData + return + } + + defer func() { + if code == pb.ErrorCode_Success { + rsp = &pb.FriendApplyListRsp{ + List: list, + } + } + session.SendMsg(string(this.module.GetType()), Friend_SubType_ApplyList, code, rsp) + }() + + for _, userId := range self.ApplyIds { + //TODO 组装FriendBase明细数据 + list = append(list, &pb.FriendBase{ + UserId: userId, + }) + } + + return nil +} + //删除好友 func (this *FriendComp) Del(ctx context.Context, session comm.IUserSession, req *pb.FriendDelReq) error { return nil @@ -138,13 +173,14 @@ func (this *FriendComp) List(ctx context.Context, session comm.IUserSession, req return nil } -//同意或拒绝 -func (this *FriendComp) Check(ctx context.Context, session comm.IUserSession, req *pb.FriendAgreeOrRefuseReq) error { +//单个/批量同意 +func (this *FriendComp) Agree(ctx context.Context, session comm.IUserSession, req *pb.FriendAgreeOrRefuseReq) error { + return nil } -//批量同意或拒绝 -func (this *FriendComp) CheckAll(ctx context.Context, session comm.IUserSession, req *pb.FriendAgreeOrRefuseReq) error { +//单个/批量拒绝 +func (this *FriendComp) Refuse(ctx context.Context, session comm.IUserSession, req *pb.FriendAgreeOrRefuseReq) error { return nil } diff --git a/pb/friend_msg.pb.go b/pb/friend_msg.pb.go index 8cf76b816..a88fd3497 100644 --- a/pb/friend_msg.pb.go +++ b/pb/friend_msg.pb.go @@ -561,6 +561,8 @@ type FriendApplyListRsp struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + List []*FriendBase `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"` } func (x *FriendApplyListRsp) Reset() { @@ -595,6 +597,13 @@ func (*FriendApplyListRsp) Descriptor() ([]byte, []int) { return file_friend_friend_msg_proto_rawDescGZIP(), []int{10} } +func (x *FriendApplyListRsp) GetList() []*FriendBase { + if x != nil { + return x.List + } + return nil +} + //好友搜索 type FriendSearchReq struct { state protoimpl.MessageState @@ -1157,49 +1166,52 @@ var file_friend_friend_msg_proto_rawDesc = []byte{ 0x05, 0x52, 0x03, 0x4e, 0x75, 0x6d, 0x12, 0x18, 0x0a, 0x07, 0x69, 0x73, 0x41, 0x67, 0x72, 0x65, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x41, 0x67, 0x72, 0x65, 0x65, 0x22, 0x14, 0x0a, 0x12, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x4c, - 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x22, 0x14, 0x0a, 0x12, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, - 0x41, 0x70, 0x70, 0x6c, 0x79, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x73, 0x70, 0x22, 0x49, 0x0a, 0x0f, - 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x71, 0x12, - 0x1a, 0x0a, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x6e, - 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, - 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x38, 0x0a, 0x0f, 0x46, 0x72, 0x69, 0x65, 0x6e, - 0x64, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 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, 0x22, 0x14, 0x0a, 0x12, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x6c, 0x61, 0x63, 0x6b, - 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x22, 0x3b, 0x0a, 0x12, 0x46, 0x72, 0x69, 0x65, 0x6e, - 0x64, 0x42, 0x6c, 0x61, 0x63, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x52, 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, 0x22, 0x2f, 0x0a, 0x11, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x6c, - 0x61, 0x63, 0x6b, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x72, 0x69, - 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x72, 0x69, - 0x65, 0x6e, 0x64, 0x49, 0x64, 0x22, 0x47, 0x0a, 0x11, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, - 0x6c, 0x61, 0x63, 0x6b, 0x41, 0x64, 0x64, 0x52, 0x73, 0x70, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x72, - 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x72, - 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x52, - 0x0a, 0x16, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x4f, - 0x72, 0x53, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x72, 0x69, 0x65, - 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x72, 0x69, 0x65, - 0x6e, 0x64, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x73, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x52, 0x65, 0x63, 0x65, 0x69, - 0x76, 0x65, 0x22, 0x6a, 0x0a, 0x16, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x63, 0x65, - 0x69, 0x76, 0x65, 0x4f, 0x72, 0x53, 0x65, 0x6e, 0x64, 0x52, 0x73, 0x70, 0x12, 0x1a, 0x0a, 0x08, - 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, - 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, - 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, - 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x73, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x22, 0x2c, - 0x0a, 0x0e, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x52, 0x65, 0x71, + 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x22, 0x35, 0x0a, 0x12, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, + 0x41, 0x70, 0x70, 0x6c, 0x79, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x73, 0x70, 0x12, 0x1f, 0x0a, 0x04, + 0x6c, 0x69, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x46, 0x72, 0x69, + 0x65, 0x6e, 0x64, 0x42, 0x61, 0x73, 0x65, 0x52, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x49, 0x0a, + 0x0f, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x22, 0x42, 0x0a, 0x0e, - 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x52, 0x73, 0x70, 0x12, 0x1a, - 0x0a, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, - 0x74, 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, - 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x28, 0x09, 0x52, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, + 0x6e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x6e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x38, 0x0a, 0x0f, 0x46, 0x72, 0x69, 0x65, + 0x6e, 0x64, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 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, 0x22, 0x14, 0x0a, 0x12, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x6c, 0x61, 0x63, + 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x22, 0x3b, 0x0a, 0x12, 0x46, 0x72, 0x69, 0x65, + 0x6e, 0x64, 0x42, 0x6c, 0x61, 0x63, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x52, 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, 0x22, 0x2f, 0x0a, 0x11, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, + 0x6c, 0x61, 0x63, 0x6b, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x72, + 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x72, + 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x22, 0x47, 0x0a, 0x11, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, + 0x42, 0x6c, 0x61, 0x63, 0x6b, 0x41, 0x64, 0x64, 0x52, 0x73, 0x70, 0x12, 0x1a, 0x0a, 0x08, 0x66, + 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, + 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, + 0x52, 0x0a, 0x16, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, + 0x4f, 0x72, 0x53, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x72, 0x69, + 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x72, 0x69, + 0x65, 0x6e, 0x64, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x73, 0x52, 0x65, 0x63, 0x65, 0x69, + 0x76, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x52, 0x65, 0x63, 0x65, + 0x69, 0x76, 0x65, 0x22, 0x6a, 0x0a, 0x16, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x63, + 0x65, 0x69, 0x76, 0x65, 0x4f, 0x72, 0x53, 0x65, 0x6e, 0x64, 0x52, 0x73, 0x70, 0x12, 0x1a, 0x0a, + 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, + 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, + 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x73, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x22, + 0x2c, 0x0a, 0x0e, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x52, 0x65, + 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x22, 0x42, 0x0a, + 0x0e, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x52, 0x73, 0x70, 0x12, + 0x1a, 0x0a, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x74, + 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x74, 0x6f, 0x74, 0x61, + 0x6c, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -1241,13 +1253,14 @@ var file_friend_friend_msg_proto_goTypes = []interface{}{ } var file_friend_friend_msg_proto_depIdxs = []int32{ 21, // 0: FriendListRsp.list:type_name -> Cache_FriendData - 0, // 1: FriendSearchRsp.friends:type_name -> FriendBase - 0, // 2: FriendBlackListRsp.friends:type_name -> FriendBase - 3, // [3:3] is the sub-list for method output_type - 3, // [3:3] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 0, // 1: FriendApplyListRsp.list:type_name -> FriendBase + 0, // 2: FriendSearchRsp.friends:type_name -> FriendBase + 0, // 3: FriendBlackListRsp.friends:type_name -> FriendBase + 4, // [4:4] is the sub-list for method output_type + 4, // [4:4] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_friend_friend_msg_proto_init() } diff --git a/pb/proto/friend/friend_msg.proto b/pb/proto/friend/friend_msg.proto index 1ae8f1dd6..67f9f70a8 100644 --- a/pb/proto/friend/friend_msg.proto +++ b/pb/proto/friend/friend_msg.proto @@ -58,7 +58,7 @@ message FriendApplyListReq{ } message FriendApplyListRsp{ - + repeated FriendBase list = 1; } //好友搜索