# Conflicts:
#	pb.bat
#	pb/friend_db.pb.go
#	pb/pack_db.pb.go
This commit is contained in:
meixiongfeng 2022-06-09 19:15:26 +08:00
commit cb0576aaee
25 changed files with 588 additions and 218 deletions

View File

@ -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
}

View File

@ -9,7 +9,7 @@ import (
func (r *Robot) handlePackMsg(msg *pb.UserMessage) {
switch msg.SubType {
case "queryuserpackresp":
r.handleFriendAdd(msg)
r.handleQueryUserPack(msg)
}
}

View File

@ -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)
...
}
```

View File

@ -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 {

View File

@ -3,12 +3,28 @@ 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"
Friend_SubType_ApplyList = "applylist"
)
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
}
//搜索
@ -16,17 +32,134 @@ 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.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
)
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
}
//申请列表
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
}
@ -40,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
}

View File

@ -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
}
//注销

View File

@ -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
}

View File

@ -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 {

29
pb.bat
View File

@ -1,18 +1,27 @@
@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=import ./pb/proto/comm.proto
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import ./pb/proto/errorcode.proto
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import ./pb/proto/friend/friend_db.proto
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import ./pb/proto/friend/friend_msg.proto
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import ./pb/proto/mail/mail_db.proto
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import ./pb/proto/mail/mail_msg.proto
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import ./pb/proto/pack/pack_db.proto
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import ./pb/proto/pack/pack_msg.proto
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import ./pb/proto/user/user_db.proto
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import ./pb/proto/user/user_msg.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
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
pause

View File

@ -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,
}

View File

@ -25,8 +25,12 @@ type Cache_FriendData struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId,omitempty"` //tags:{bson:"_id"}用户Id
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() {
@ -69,8 +73,24 @@ func (x *Cache_FriendData) GetUserId() string {
}
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
}
@ -85,6 +105,16 @@ var file_friend_friend_db_proto_rawDesc = []byte{
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 (

View File

@ -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
@ -553,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() {
@ -587,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
@ -1124,12 +1141,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,
@ -1147,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 (
@ -1209,8 +1231,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
@ -1231,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() }
@ -1284,7 +1307,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 +1319,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:

View File

@ -106,8 +106,10 @@ type DB_UserPackData struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
UserId string `protobuf:"bytes,1,opt,name=UserId,proto3" json:"UserId,omitempty"` //tags:{bson:"_id"}用户Id
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() {

View File

@ -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;//
}

View File

@ -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
}

View File

@ -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
}
//
@ -57,7 +58,7 @@ message FriendApplyListReq{
}
message FriendApplyListRsp{
repeated FriendBase list = 1;
}
//

View File

@ -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; //
}

42
sys/cache/friend.go vendored
View File

@ -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
}

View File

@ -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")
}

View File

@ -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
}

View File

@ -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",
},
})

View File

@ -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},

View File

@ -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", "")

View File

@ -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
}

View File

@ -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
}