From 9743f023961b825c144b0ef1a8614acf6e5edc6e Mon Sep 17 00:00:00 2001 From: zhaocy Date: Thu, 30 Jun 2022 17:45:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=B5=84=E6=BA=90=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/robot/hero.go | 2 +- cmd/robot/user.go | 10 ++ modules/user/api.go | 1 + modules/user/api_res.go | 49 ++++++++++ pb/proto/user/user_msg.proto | 13 ++- pb/user_msg.pb.go | 175 ++++++++++++++++++++++++++++++++--- 6 files changed, 233 insertions(+), 17 deletions(-) create mode 100644 modules/user/api_res.go diff --git a/cmd/robot/hero.go b/cmd/robot/hero.go index 862e42948..2ea33ac8a 100644 --- a/cmd/robot/hero.go +++ b/cmd/robot/hero.go @@ -24,7 +24,7 @@ var ( fmt.Printf("%d- %v\n", (i + 1), v) } }, - enabled: true, + // enabled: true, }, { mainType: string(comm.ModuleHero), subType: hero.HeroSubTypeInfo, diff --git a/cmd/robot/user.go b/cmd/robot/user.go index d50ed2fad..5905f2aaa 100644 --- a/cmd/robot/user.go +++ b/cmd/robot/user.go @@ -18,6 +18,16 @@ var user_builders = []*builder{ }, rsp: &pb.UserCreateRsp{}, enabled: true, + }, { + desc: "添加资源", + mainType: string(comm.ModuleUser), + subType: user.UserSubTypeAddRes, + req: &pb.UserAddResReq{ //设置请求参数 + ResType: comm.ResGold, + Count: 100, + }, + rsp: &pb.UserAddResResp{}, + enabled: true, }, } diff --git a/modules/user/api.go b/modules/user/api.go index 324a00d36..618e82436 100644 --- a/modules/user/api.go +++ b/modules/user/api.go @@ -12,6 +12,7 @@ const ( UserSubTypeLogin = "login" UserSubTypeLogout = "logout" UserSubTypeCreate = "create" + UserSubTypeAddRes = "addres" //添加用户资源 金币、宝石等 ) type apiComp struct { diff --git a/modules/user/api_res.go b/modules/user/api_res.go new file mode 100644 index 000000000..4099b6f80 --- /dev/null +++ b/modules/user/api_res.go @@ -0,0 +1,49 @@ +package user + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" +) + +func (this *apiComp) AddResCheck(session comm.IUserSession, req *pb.UserAddResReq) (result map[string]interface{}, code comm.ErrorCode) { + result = make(map[string]interface{}) + user := this.module.modelUser.getUser(session.GetUserId()) + if user == nil { + code = comm.ErrorCode{Code: pb.ErrorCode_UserSessionNobeing} + return + } + result["user"] = user + return +} + +func (this *apiComp) AddRes(session comm.IUserSession, result map[string]interface{}, req *pb.UserAddResReq) (code pb.ErrorCode) { + rsp := &pb.UserAddResResp{} + + defer func() { + if err := session.SendMsg(string(this.module.GetType()), UserSubTypeAddRes, rsp); err != nil { + code = pb.ErrorCode_SystemError + return + } + }() + + if u, ok := result["user"]; ok { + user := u.(*pb.DBUser) + count := req.Count + + switch req.ResType { + case comm.ResGold: + count += user.Gold + case comm.ResExp: + count += user.Exp + } + code = this.module.AddAttributeValue(session.GetUserId(), req.ResType, count) + if code != pb.ErrorCode_Success { + return + } + + rsp.ResType = req.ResType + rsp.Count = count + } + + return +} diff --git a/pb/proto/user/user_msg.proto b/pb/proto/user/user_msg.proto index 3f57901d9..791486aae 100644 --- a/pb/proto/user/user_msg.proto +++ b/pb/proto/user/user_msg.proto @@ -28,4 +28,15 @@ message UserCreateReq { string NickName = 1; //昵称 } -message UserCreateRsp {} \ No newline at end of file +message UserCreateRsp {} + +//添加用户资源 +message UserAddResReq { + string resType = 1; //资源类型 + int32 count = 2; //资源数量 +} + +message UserAddResResp { + string resType = 1; //资源类型 + int32 count = 2; //资源数量 +} diff --git a/pb/user_msg.pb.go b/pb/user_msg.pb.go index 8462c6ff1..ddaa8ce3a 100644 --- a/pb/user_msg.pb.go +++ b/pb/user_msg.pb.go @@ -366,6 +366,117 @@ func (*UserCreateRsp) Descriptor() ([]byte, []int) { return file_user_user_msg_proto_rawDescGZIP(), []int{6} } +//添加用户资源 +type UserAddResReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ResType string `protobuf:"bytes,1,opt,name=resType,proto3" json:"resType"` //资源类型 + Count int32 `protobuf:"varint,2,opt,name=count,proto3" json:"count"` //资源数量 +} + +func (x *UserAddResReq) Reset() { + *x = UserAddResReq{} + if protoimpl.UnsafeEnabled { + mi := &file_user_user_msg_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UserAddResReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UserAddResReq) ProtoMessage() {} + +func (x *UserAddResReq) ProtoReflect() protoreflect.Message { + mi := &file_user_user_msg_proto_msgTypes[7] + 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 UserAddResReq.ProtoReflect.Descriptor instead. +func (*UserAddResReq) Descriptor() ([]byte, []int) { + return file_user_user_msg_proto_rawDescGZIP(), []int{7} +} + +func (x *UserAddResReq) GetResType() string { + if x != nil { + return x.ResType + } + return "" +} + +func (x *UserAddResReq) GetCount() int32 { + if x != nil { + return x.Count + } + return 0 +} + +type UserAddResResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ResType string `protobuf:"bytes,1,opt,name=resType,proto3" json:"resType"` //资源类型 + Count int32 `protobuf:"varint,2,opt,name=count,proto3" json:"count"` //资源数量 +} + +func (x *UserAddResResp) Reset() { + *x = UserAddResResp{} + if protoimpl.UnsafeEnabled { + mi := &file_user_user_msg_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UserAddResResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UserAddResResp) ProtoMessage() {} + +func (x *UserAddResResp) ProtoReflect() protoreflect.Message { + mi := &file_user_user_msg_proto_msgTypes[8] + 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 UserAddResResp.ProtoReflect.Descriptor instead. +func (*UserAddResResp) Descriptor() ([]byte, []int) { + return file_user_user_msg_proto_rawDescGZIP(), []int{8} +} + +func (x *UserAddResResp) GetResType() string { + if x != nil { + return x.ResType + } + return "" +} + +func (x *UserAddResResp) GetCount() int32 { + if x != nil { + return x.Count + } + return 0 +} + var File_user_user_msg_proto protoreflect.FileDescriptor var file_user_user_msg_proto_rawDesc = []byte{ @@ -394,8 +505,16 @@ var file_user_user_msg_proto_rawDesc = []byte{ 0x2b, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x0f, 0x0a, 0x0d, - 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x73, 0x70, 0x42, 0x06, 0x5a, - 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x73, 0x70, 0x22, 0x3f, 0x0a, + 0x0d, 0x55, 0x73, 0x65, 0x72, 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x52, 0x65, 0x71, 0x12, 0x18, + 0x0a, 0x07, 0x72, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x72, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x40, + 0x0a, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, + 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x72, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -410,7 +529,7 @@ func file_user_user_msg_proto_rawDescGZIP() []byte { return file_user_user_msg_proto_rawDescData } -var file_user_user_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_user_user_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_user_user_msg_proto_goTypes = []interface{}{ (*UserLoginReq)(nil), // 0: UserLoginReq (*UserLoginResp)(nil), // 1: UserLoginResp @@ -419,19 +538,21 @@ var file_user_user_msg_proto_goTypes = []interface{}{ (*UserLoadRsp)(nil), // 4: UserLoadRsp (*UserCreateReq)(nil), // 5: UserCreateReq (*UserCreateRsp)(nil), // 6: UserCreateRsp - (*DBUser)(nil), // 7: DBUser - (ErrorCode)(0), // 8: ErrorCode - (*CacheUser)(nil), // 9: CacheUser + (*UserAddResReq)(nil), // 7: UserAddResReq + (*UserAddResResp)(nil), // 8: UserAddResResp + (*DBUser)(nil), // 9: DBUser + (ErrorCode)(0), // 10: ErrorCode + (*CacheUser)(nil), // 11: CacheUser } var file_user_user_msg_proto_depIdxs = []int32{ - 7, // 0: UserLoginResp.data:type_name -> DBUser - 8, // 1: UserRegisterRsp.Code:type_name -> ErrorCode - 9, // 2: UserLoadRsp.data:type_name -> CacheUser - 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 + 9, // 0: UserLoginResp.data:type_name -> DBUser + 10, // 1: UserRegisterRsp.Code:type_name -> ErrorCode + 11, // 2: UserLoadRsp.data:type_name -> CacheUser + 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_user_user_msg_proto_init() } @@ -526,6 +647,30 @@ func file_user_user_msg_proto_init() { return nil } } + file_user_user_msg_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UserAddResReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_user_user_msg_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UserAddResResp); 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{ @@ -533,7 +678,7 @@ func file_user_user_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_user_user_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 7, + NumMessages: 9, NumExtensions: 0, NumServices: 0, },