From 991fb40dda98ecda32fefe032b8a66b02cea73d5 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Mon, 6 Jun 2022 17:17:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=83=8C=E5=8C=85=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/core.go | 1 + modules/pack/api_comp.go | 49 +++++++ modules/pack/module.go | 30 ++++ pb/errorcode.pb.go | 161 ++++++++++++++++++++ pb/pack_db.pb.go | 301 ++++++++++++++++++++++++++++++++++++++ pb/pack_msg.pb.go | 309 +++++++++++++++++++++++++++++++++++++++ pb/proto/errorcode.proto | 16 ++ pb/proto/pack_db.proto | 22 +++ pb/proto/pack_msg.proto | 22 +++ pb_2.7.py | 5 +- sys/cache/pack.go | 38 ++++- sys/db/pack.go | 19 +++ sys/db/user.go | 2 +- 13 files changed, 972 insertions(+), 3 deletions(-) create mode 100644 modules/pack/api_comp.go create mode 100644 modules/pack/module.go create mode 100644 pb/errorcode.pb.go create mode 100644 pb/pack_db.pb.go create mode 100644 pb/pack_msg.pb.go create mode 100644 pb/proto/errorcode.proto create mode 100644 pb/proto/pack_db.proto create mode 100644 pb/proto/pack_msg.proto diff --git a/comm/core.go b/comm/core.go index ccdac2e30..424c2bf61 100644 --- a/comm/core.go +++ b/comm/core.go @@ -15,6 +15,7 @@ const ( SM_GateModule core.M_Modules = "gateway" //gate模块 网关服务模块 SM_WebModule core.M_Modules = "web" //web模块 SM_LoginModule core.M_Modules = "login" //web模块 + SM_PackModule core.M_Modules = "pack" //背包模块 ) const ( //Rpc diff --git a/modules/pack/api_comp.go b/modules/pack/api_comp.go new file mode 100644 index 000000000..85981792b --- /dev/null +++ b/modules/pack/api_comp.go @@ -0,0 +1,49 @@ +package login + +import ( + "context" + "go_dreamfactory/comm" + "go_dreamfactory/modules" + "go_dreamfactory/pb" + "go_dreamfactory/sys/cache" + + "github.com/liwei1dao/lego/sys/log" +) + +const ( + QueryUserPackReq = "pack.queryuserpackreq" + QueryUserPackResp = "pack.queryuserpackresp" +) + +type Api_Comp struct { + modules.MComp_GateComp +} + +///查询用户背包数据 +func (this *Api_Comp) QueryUserPackReq(ctx context.Context, session comm.IUserSession, req *pb.QueryUserPackReq) (err error) { + var ( + code pb.ErrorCode + pack *pb.DB_UserPackData + items []*pb.ItemAmount + ) + defer func() { + session.SendMsg(QueryUserPackResp, &pb.QueryUserPackResp{Code: code, Items: items}) + }() + if session.GetUserId() == 0 { + code = pb.ErrorCode_NoLogin + return + } + if pack, err = cache.Defsys.QueryUserPack(session.GetUserId()); err != nil { + log.Errorf("QueryUserPackReq err:%v", err) + code = pb.ErrorCode_CacheReadError + return + } else { + items = make([]*pb.ItemAmount, 0, len(pack.Pack)) + for _, v := range pack.Pack { + if v.Itype == req.IType { + items = append(items, &pb.ItemAmount{IsNew: v.IsNew, ItemId: v.ItemId, Amount: v.Amount}) + } + } + } + return nil +} diff --git a/modules/pack/module.go b/modules/pack/module.go new file mode 100644 index 000000000..3b53638bb --- /dev/null +++ b/modules/pack/module.go @@ -0,0 +1,30 @@ +package login + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/modules" + + "github.com/liwei1dao/lego/core" +) + +/* +模块名:Pack +描述:背包系统模块 +开发:李伟 +*/ +func NewModule() core.IModule { + m := new(Pack) + return m +} + +type Pack struct { + modules.ModuleBase +} + +func (this *Pack) GetType() core.M_Modules { + return comm.SM_PackModule +} + +func (this *Pack) OnInstallComp() { + this.ModuleBase.OnInstallComp() +} diff --git a/pb/errorcode.pb.go b/pb/errorcode.pb.go new file mode 100644 index 000000000..cd54102a5 --- /dev/null +++ b/pb/errorcode.pb.go @@ -0,0 +1,161 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.20.0 +// source: errorcode.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ErrorCode int32 + +const ( + ErrorCode_Success ErrorCode = 0 //成功 + ErrorCode_NoFindService ErrorCode = 10 //没有找到远程服务器 + ErrorCode_RpcFuncExecutionError ErrorCode = 11 //Rpc方法执行错误 + ErrorCode_CacheReadError ErrorCode = 12 //缓存读取失败 + ErrorCode_SqlExecutionError ErrorCode = 13 //数据库执行错误 + ErrorCode_ReqParameterError ErrorCode = 14 //请求参数错误 + ErrorCode_SignError ErrorCode = 15 //签名错误 + ErrorCode_InsufficientPermissions ErrorCode = 16 //权限不足 + ErrorCode_NoLogin ErrorCode = 17 //未登录 + ErrorCode_UserSessionNobeing ErrorCode = 18 //用户不存在 +) + +// 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", + } + ErrorCode_value = map[string]int32{ + "Success": 0, + "NoFindService": 10, + "RpcFuncExecutionError": 11, + "CacheReadError": 12, + "SqlExecutionError": 13, + "ReqParameterError": 14, + "SignError": 15, + "InsufficientPermissions": 16, + "NoLogin": 17, + "UserSessionNobeing": 18, + } +) + +func (x ErrorCode) Enum() *ErrorCode { + p := new(ErrorCode) + *p = x + return p +} + +func (x ErrorCode) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (ErrorCode) Descriptor() protoreflect.EnumDescriptor { + return file_errorcode_proto_enumTypes[0].Descriptor() +} + +func (ErrorCode) Type() protoreflect.EnumType { + return &file_errorcode_proto_enumTypes[0] +} + +func (x ErrorCode) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use ErrorCode.Descriptor instead. +func (ErrorCode) EnumDescriptor() ([]byte, []int) { + return file_errorcode_proto_rawDescGZIP(), []int{0} +} + +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, 0xd9, 0x01, 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, + 0x69, 0x6f, 0x6e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x0b, 0x12, 0x12, 0x0a, 0x0e, 0x43, 0x61, + 0x63, 0x68, 0x65, 0x52, 0x65, 0x61, 0x64, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x0c, 0x12, 0x15, + 0x0a, 0x11, 0x53, 0x71, 0x6c, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x72, + 0x72, 0x6f, 0x72, 0x10, 0x0d, 0x12, 0x15, 0x0a, 0x11, 0x52, 0x65, 0x71, 0x50, 0x61, 0x72, 0x61, + 0x6d, 0x65, 0x74, 0x65, 0x72, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x0e, 0x12, 0x0d, 0x0a, 0x09, + 0x53, 0x69, 0x67, 0x6e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x0f, 0x12, 0x1b, 0x0a, 0x17, 0x49, + 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, 0x42, 0x06, 0x5a, + 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_errorcode_proto_rawDescOnce sync.Once + file_errorcode_proto_rawDescData = file_errorcode_proto_rawDesc +) + +func file_errorcode_proto_rawDescGZIP() []byte { + file_errorcode_proto_rawDescOnce.Do(func() { + file_errorcode_proto_rawDescData = protoimpl.X.CompressGZIP(file_errorcode_proto_rawDescData) + }) + return file_errorcode_proto_rawDescData +} + +var file_errorcode_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_errorcode_proto_goTypes = []interface{}{ + (ErrorCode)(0), // 0: ErrorCode +} +var file_errorcode_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_errorcode_proto_init() } +func file_errorcode_proto_init() { + if File_errorcode_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_errorcode_proto_rawDesc, + NumEnums: 1, + NumMessages: 0, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_errorcode_proto_goTypes, + DependencyIndexes: file_errorcode_proto_depIdxs, + EnumInfos: file_errorcode_proto_enumTypes, + }.Build() + File_errorcode_proto = out.File + file_errorcode_proto_rawDesc = nil + file_errorcode_proto_goTypes = nil + file_errorcode_proto_depIdxs = nil +} diff --git a/pb/pack_db.pb.go b/pb/pack_db.pb.go new file mode 100644 index 000000000..b9aa2f991 --- /dev/null +++ b/pb/pack_db.pb.go @@ -0,0 +1,301 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.20.0 +// source: pack_db.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ItemType int32 + +const ( + ItemType_Props ItemType = 0 //道具 + ItemType_Equip ItemType = 2 //装备 + ItemType_Fragment ItemType = 12 //碎片 +) + +// Enum value maps for ItemType. +var ( + ItemType_name = map[int32]string{ + 0: "Props", + 2: "Equip", + 12: "Fragment", + } + ItemType_value = map[string]int32{ + "Props": 0, + "Equip": 2, + "Fragment": 12, + } +) + +func (x ItemType) Enum() *ItemType { + p := new(ItemType) + *p = x + return p +} + +func (x ItemType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (ItemType) Descriptor() protoreflect.EnumDescriptor { + return file_pack_db_proto_enumTypes[0].Descriptor() +} + +func (ItemType) Type() protoreflect.EnumType { + return &file_pack_db_proto_enumTypes[0] +} + +func (x ItemType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use ItemType.Descriptor instead. +func (ItemType) EnumDescriptor() ([]byte, []int) { + return file_pack_db_proto_rawDescGZIP(), []int{0} +} + +//背包格子 +type GridData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IsNew bool `protobuf:"varint,1,opt,name=IsNew,proto3" json:"IsNew,omitempty"` //是否是新的 + ItemId uint32 `protobuf:"varint,2,opt,name=ItemId,proto3" json:"ItemId,omitempty"` //存放物品的Id + Itype ItemType `protobuf:"varint,3,opt,name=Itype,proto3,enum=ItemType" json:"Itype,omitempty"` //物品类型 + Amount uint32 `protobuf:"varint,4,opt,name=Amount,proto3" json:"Amount,omitempty"` //存放物品的数量 +} + +func (x *GridData) Reset() { + *x = GridData{} + if protoimpl.UnsafeEnabled { + mi := &file_pack_db_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GridData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GridData) ProtoMessage() {} + +func (x *GridData) ProtoReflect() protoreflect.Message { + mi := &file_pack_db_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GridData.ProtoReflect.Descriptor instead. +func (*GridData) Descriptor() ([]byte, []int) { + return file_pack_db_proto_rawDescGZIP(), []int{0} +} + +func (x *GridData) GetIsNew() bool { + if x != nil { + return x.IsNew + } + return false +} + +func (x *GridData) GetItemId() uint32 { + if x != nil { + return x.ItemId + } + return 0 +} + +func (x *GridData) GetItype() ItemType { + if x != nil { + return x.Itype + } + return ItemType_Props +} + +func (x *GridData) GetAmount() uint32 { + if x != nil { + return x.Amount + } + return 0 +} + +//用户背包 +type DB_UserPackData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UserId uint32 `protobuf:"varint,1,opt,name=UserId,proto3" json:"UserId,omitempty" bson:"_id"` //tags:{bson:"_id"}用户Id + Pack []*GridData `protobuf:"bytes,2,rep,name=Pack,proto3" json:"Pack,omitempty"` //背包列表 +} + +func (x *DB_UserPackData) Reset() { + *x = DB_UserPackData{} + if protoimpl.UnsafeEnabled { + mi := &file_pack_db_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DB_UserPackData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DB_UserPackData) ProtoMessage() {} + +func (x *DB_UserPackData) ProtoReflect() protoreflect.Message { + mi := &file_pack_db_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DB_UserPackData.ProtoReflect.Descriptor instead. +func (*DB_UserPackData) Descriptor() ([]byte, []int) { + return file_pack_db_proto_rawDescGZIP(), []int{1} +} + +func (x *DB_UserPackData) GetUserId() uint32 { + if x != nil { + return x.UserId + } + return 0 +} + +func (x *DB_UserPackData) GetPack() []*GridData { + if x != nil { + return x.Pack + } + return nil +} + +var File_pack_db_proto protoreflect.FileDescriptor + +var file_pack_db_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x70, 0x61, 0x63, 0x6b, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0x71, 0x0a, 0x08, 0x47, 0x72, 0x69, 0x64, 0x44, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x49, + 0x73, 0x4e, 0x65, 0x77, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x49, 0x73, 0x4e, 0x65, + 0x77, 0x12, 0x16, 0x0a, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0d, 0x52, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x05, 0x49, 0x74, 0x79, + 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x09, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x54, + 0x79, 0x70, 0x65, 0x52, 0x05, 0x49, 0x74, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x6d, + 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, + 0x6e, 0x74, 0x22, 0x48, 0x0a, 0x0f, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x50, 0x61, 0x63, + 0x6b, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1d, 0x0a, + 0x04, 0x50, 0x61, 0x63, 0x6b, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x47, 0x72, + 0x69, 0x64, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x50, 0x61, 0x63, 0x6b, 0x2a, 0x2e, 0x0a, 0x08, + 0x49, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x12, 0x09, 0x0a, 0x05, 0x50, 0x72, 0x6f, 0x70, + 0x73, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x71, 0x75, 0x69, 0x70, 0x10, 0x02, 0x12, 0x0c, + 0x0a, 0x08, 0x46, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x10, 0x0c, 0x42, 0x06, 0x5a, 0x04, + 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_pack_db_proto_rawDescOnce sync.Once + file_pack_db_proto_rawDescData = file_pack_db_proto_rawDesc +) + +func file_pack_db_proto_rawDescGZIP() []byte { + file_pack_db_proto_rawDescOnce.Do(func() { + file_pack_db_proto_rawDescData = protoimpl.X.CompressGZIP(file_pack_db_proto_rawDescData) + }) + return file_pack_db_proto_rawDescData +} + +var file_pack_db_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_pack_db_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_pack_db_proto_goTypes = []interface{}{ + (ItemType)(0), // 0: ItemType + (*GridData)(nil), // 1: GridData + (*DB_UserPackData)(nil), // 2: DB_UserPackData +} +var file_pack_db_proto_depIdxs = []int32{ + 0, // 0: GridData.Itype:type_name -> ItemType + 1, // 1: DB_UserPackData.Pack:type_name -> GridData + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_pack_db_proto_init() } +func file_pack_db_proto_init() { + if File_pack_db_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_pack_db_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GridData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pack_db_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DB_UserPackData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_pack_db_proto_rawDesc, + NumEnums: 1, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_pack_db_proto_goTypes, + DependencyIndexes: file_pack_db_proto_depIdxs, + EnumInfos: file_pack_db_proto_enumTypes, + MessageInfos: file_pack_db_proto_msgTypes, + }.Build() + File_pack_db_proto = out.File + file_pack_db_proto_rawDesc = nil + file_pack_db_proto_goTypes = nil + file_pack_db_proto_depIdxs = nil +} diff --git a/pb/pack_msg.pb.go b/pb/pack_msg.pb.go new file mode 100644 index 000000000..08cb3964c --- /dev/null +++ b/pb/pack_msg.pb.go @@ -0,0 +1,309 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.20.0 +// source: pack_msg.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +//物品数量 +type ItemAmount struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IsNew bool `protobuf:"varint,1,opt,name=IsNew,proto3" json:"IsNew,omitempty"` //是否是新的 + ItemId uint32 `protobuf:"varint,2,opt,name=ItemId,proto3" json:"ItemId,omitempty"` + Amount uint32 `protobuf:"varint,3,opt,name=Amount,proto3" json:"Amount,omitempty"` +} + +func (x *ItemAmount) Reset() { + *x = ItemAmount{} + if protoimpl.UnsafeEnabled { + mi := &file_pack_msg_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ItemAmount) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ItemAmount) ProtoMessage() {} + +func (x *ItemAmount) ProtoReflect() protoreflect.Message { + mi := &file_pack_msg_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ItemAmount.ProtoReflect.Descriptor instead. +func (*ItemAmount) Descriptor() ([]byte, []int) { + return file_pack_msg_proto_rawDescGZIP(), []int{0} +} + +func (x *ItemAmount) GetIsNew() bool { + if x != nil { + return x.IsNew + } + return false +} + +func (x *ItemAmount) GetItemId() uint32 { + if x != nil { + return x.ItemId + } + return 0 +} + +func (x *ItemAmount) GetAmount() uint32 { + if x != nil { + return x.Amount + } + return 0 +} + +//查询用户背包请求 +type QueryUserPackReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IType ItemType `protobuf:"varint,1,opt,name=IType,proto3,enum=ItemType" json:"IType,omitempty"` +} + +func (x *QueryUserPackReq) Reset() { + *x = QueryUserPackReq{} + if protoimpl.UnsafeEnabled { + mi := &file_pack_msg_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *QueryUserPackReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*QueryUserPackReq) ProtoMessage() {} + +func (x *QueryUserPackReq) ProtoReflect() protoreflect.Message { + mi := &file_pack_msg_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use QueryUserPackReq.ProtoReflect.Descriptor instead. +func (*QueryUserPackReq) Descriptor() ([]byte, []int) { + return file_pack_msg_proto_rawDescGZIP(), []int{1} +} + +func (x *QueryUserPackReq) GetIType() ItemType { + if x != nil { + return x.IType + } + return ItemType_Props +} + +//查询用户背包请求 回应 +type QueryUserPackResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code,omitempty"` + Items []*ItemAmount `protobuf:"bytes,2,rep,name=Items,proto3" json:"Items,omitempty"` +} + +func (x *QueryUserPackResp) Reset() { + *x = QueryUserPackResp{} + if protoimpl.UnsafeEnabled { + mi := &file_pack_msg_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *QueryUserPackResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*QueryUserPackResp) ProtoMessage() {} + +func (x *QueryUserPackResp) ProtoReflect() protoreflect.Message { + mi := &file_pack_msg_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use QueryUserPackResp.ProtoReflect.Descriptor instead. +func (*QueryUserPackResp) Descriptor() ([]byte, []int) { + return file_pack_msg_proto_rawDescGZIP(), []int{2} +} + +func (x *QueryUserPackResp) GetCode() ErrorCode { + if x != nil { + return x.Code + } + return ErrorCode_Success +} + +func (x *QueryUserPackResp) GetItems() []*ItemAmount { + if x != nil { + return x.Items + } + return nil +} + +var File_pack_msg_proto protoreflect.FileDescriptor + +var file_pack_msg_proto_rawDesc = []byte{ + 0x0a, 0x0e, 0x70, 0x61, 0x63, 0x6b, 0x5f, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x1a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x1a, 0x0d, 0x70, 0x61, 0x63, 0x6b, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x22, 0x52, 0x0a, 0x0a, 0x49, 0x74, 0x65, 0x6d, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x14, + 0x0a, 0x05, 0x49, 0x73, 0x4e, 0x65, 0x77, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x49, + 0x73, 0x4e, 0x65, 0x77, 0x12, 0x16, 0x0a, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, + 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x41, 0x6d, + 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x33, 0x0a, 0x10, 0x51, 0x75, 0x65, 0x72, 0x79, 0x55, 0x73, 0x65, + 0x72, 0x50, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x12, 0x1f, 0x0a, 0x05, 0x49, 0x54, 0x79, 0x70, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x09, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x54, 0x79, + 0x70, 0x65, 0x52, 0x05, 0x49, 0x54, 0x79, 0x70, 0x65, 0x22, 0x56, 0x0a, 0x11, 0x51, 0x75, 0x65, + 0x72, 0x79, 0x55, 0x73, 0x65, 0x72, 0x50, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, + 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, + 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x21, + 0x0a, 0x05, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, + 0x49, 0x74, 0x65, 0x6d, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x05, 0x49, 0x74, 0x65, 0x6d, + 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, +} + +var ( + file_pack_msg_proto_rawDescOnce sync.Once + file_pack_msg_proto_rawDescData = file_pack_msg_proto_rawDesc +) + +func file_pack_msg_proto_rawDescGZIP() []byte { + file_pack_msg_proto_rawDescOnce.Do(func() { + file_pack_msg_proto_rawDescData = protoimpl.X.CompressGZIP(file_pack_msg_proto_rawDescData) + }) + return file_pack_msg_proto_rawDescData +} + +var file_pack_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_pack_msg_proto_goTypes = []interface{}{ + (*ItemAmount)(nil), // 0: ItemAmount + (*QueryUserPackReq)(nil), // 1: QueryUserPackReq + (*QueryUserPackResp)(nil), // 2: QueryUserPackResp + (ItemType)(0), // 3: ItemType + (ErrorCode)(0), // 4: ErrorCode +} +var file_pack_msg_proto_depIdxs = []int32{ + 3, // 0: QueryUserPackReq.IType:type_name -> ItemType + 4, // 1: QueryUserPackResp.Code:type_name -> ErrorCode + 0, // 2: QueryUserPackResp.Items:type_name -> ItemAmount + 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 +} + +func init() { file_pack_msg_proto_init() } +func file_pack_msg_proto_init() { + if File_pack_msg_proto != nil { + return + } + file_errorcode_proto_init() + file_pack_db_proto_init() + if !protoimpl.UnsafeEnabled { + file_pack_msg_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ItemAmount); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pack_msg_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*QueryUserPackReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pack_msg_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*QueryUserPackResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_pack_msg_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_pack_msg_proto_goTypes, + DependencyIndexes: file_pack_msg_proto_depIdxs, + MessageInfos: file_pack_msg_proto_msgTypes, + }.Build() + File_pack_msg_proto = out.File + file_pack_msg_proto_rawDesc = nil + file_pack_msg_proto_goTypes = nil + file_pack_msg_proto_depIdxs = nil +} diff --git a/pb/proto/errorcode.proto b/pb/proto/errorcode.proto new file mode 100644 index 000000000..c2d283c43 --- /dev/null +++ b/pb/proto/errorcode.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +option go_package = ".;pb"; + + +enum ErrorCode { + Success = 0; //成功 + NoFindService = 10; //没有找到远程服务器 + RpcFuncExecutionError = 11; //Rpc方法执行错误 + CacheReadError = 12; //缓存读取失败 + SqlExecutionError = 13; //数据库执行错误 + ReqParameterError = 14; //请求参数错误 + SignError = 15; //签名错误 + InsufficientPermissions = 16; //权限不足 + NoLogin = 17; //未登录 + UserSessionNobeing = 18; //用户不存在 +} \ No newline at end of file diff --git a/pb/proto/pack_db.proto b/pb/proto/pack_db.proto new file mode 100644 index 000000000..92d570ce7 --- /dev/null +++ b/pb/proto/pack_db.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; +option go_package = ".;pb"; + +enum ItemType { + Props = 0; //道具 + Equip = 2; //装备 + Fragment = 12; //碎片 +} + +//背包格子 +message GridData { + bool IsNew = 1; //是否是新的 + uint32 ItemId = 2; //存放物品的Id + ItemType Itype = 3; //物品类型 + uint32 Amount = 4; //存放物品的数量 +} + +//用户背包 +message DB_UserPackData { + uint32 UserId = 1; //tags:{bson:"_id"}用户Id + repeated GridData Pack = 2; //背包列表 +} \ No newline at end of file diff --git a/pb/proto/pack_msg.proto b/pb/proto/pack_msg.proto new file mode 100644 index 000000000..209b70606 --- /dev/null +++ b/pb/proto/pack_msg.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; +option go_package = ".;pb"; +import "errorcode.proto"; +import "pack_db.proto"; + +//物品数量 +message ItemAmount { + bool IsNew = 1; //是否是新的 + uint32 ItemId = 2; + uint32 Amount = 3; +} + +//查询用户背包请求 +message QueryUserPackReq { + ItemType IType = 1; +} + +//查询用户背包请求 回应 +message QueryUserPackResp { + ErrorCode Code = 1; + repeated ItemAmount Items = 2; +} diff --git a/pb_2.7.py b/pb_2.7.py index 90d5f6e01..e20ff5832 100644 --- a/pb_2.7.py +++ b/pb_2.7.py @@ -26,5 +26,8 @@ def buildProto(pbpath,outpath,pbfile): f.write(file_data) buildProto('./pb/proto','./pb','comm') +buildProto('./pb/proto','./pb','errorcode') buildProto('./pb/proto','./pb','user_db') -buildProto('./pb/proto','./pb','user_msg') \ No newline at end of file +buildProto('./pb/proto','./pb','user_msg') +buildProto('./pb/proto','./pb','pack_db') +buildProto('./pb/proto','./pb','pack_msg') \ No newline at end of file diff --git a/sys/cache/pack.go b/sys/cache/pack.go index dc4197621..f370d7492 100644 --- a/sys/cache/pack.go +++ b/sys/cache/pack.go @@ -1,7 +1,43 @@ package cache +import ( + "fmt" + "go_dreamfactory/pb" + "go_dreamfactory/sys/db" + + "github.com/liwei1dao/lego/sys/mgo" + "github.com/liwei1dao/lego/sys/redis" +) + const ( //Redis Redis_PackCache string = "pack:%d" ) -type IPack interface{} +const () + +type IPack interface { + QueryUserPack(uId uint32) (pack *pb.DB_UserPackData, err error) +} + +///查询用户背包数据 +func (this *Cache) QueryUserPack(uId uint32) (pack *pb.DB_UserPackData, err error) { + pack = &pb.DB_UserPackData{ + UserId: uId, + } + if err = this.redis.Get(fmt.Sprintf(Redis_PackCache, uId), pack); err == nil { + return + } else if err == redis.RedisNil { + if pack, err = db.Defsys.QueryUserPack(uId); err == nil { + this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, -1) + } else if err == mgo.MongodbNil { + err = nil + } + } + return +} + +///查询用户背包数据 +func (this *Cache) UpdateUserPack(pack *pb.DB_UserPackData) (err error) { + err = this.redis.Set(fmt.Sprintf(Redis_PackCache, pack.UserId), pack, -1) + return +} diff --git a/sys/db/pack.go b/sys/db/pack.go index 4633876a6..333dd4f34 100644 --- a/sys/db/pack.go +++ b/sys/db/pack.go @@ -1,4 +1,23 @@ package db +import ( + "go_dreamfactory/pb" + + "github.com/liwei1dao/lego/core" + "go.mongodb.org/mongo-driver/bson" +) + +const ( //Redis + DB_PackTable core.SqlTable = "pack" //背包表 +) + type IPack interface { + QueryUserPack(uId uint32) (pack *pb.DB_UserPackData, err error) +} + +///查询用户背包数据 +func (this *DB) QueryUserPack(uId uint32) (pack *pb.DB_UserPackData, err error) { + pack = &pb.DB_UserPackData{} + err = this.mgo.FindOne(DB_PackTable, bson.M{"_id": uId}).Decode(pack) + return } diff --git a/sys/db/user.go b/sys/db/user.go index fb595242e..97fbc850b 100644 --- a/sys/db/user.go +++ b/sys/db/user.go @@ -76,7 +76,7 @@ func (this *DB) User_UpdateUser(data *pb.DB_UserData) error { } //校验数据库初始化工作是否完成 -func (this DB) checkUserIdInit() (err error) { +func (this *DB) checkUserIdInit() (err error) { ctx, _ := context.WithTimeout(context.Background(), time.Second*60) count, err := this.mgo.CountDocuments(DB_UserIdTable, bson.M{}) if err != nil || count == 0 {