用户资源接口

This commit is contained in:
zhaocy 2022-06-30 17:45:47 +08:00
parent 31fc23c945
commit 9743f02396
6 changed files with 233 additions and 17 deletions

View File

@ -24,7 +24,7 @@ var (
fmt.Printf("%d- %v\n", (i + 1), v)
}
},
enabled: true,
// enabled: true,
}, {
mainType: string(comm.ModuleHero),
subType: hero.HeroSubTypeInfo,

View File

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

View File

@ -12,6 +12,7 @@ const (
UserSubTypeLogin = "login"
UserSubTypeLogout = "logout"
UserSubTypeCreate = "create"
UserSubTypeAddRes = "addres" //添加用户资源 金币、宝石等
)
type apiComp struct {

49
modules/user/api_res.go Normal file
View File

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

View File

@ -28,4 +28,15 @@ message UserCreateReq {
string NickName = 1; //
}
message UserCreateRsp {}
message UserCreateRsp {}
//
message UserAddResReq {
string resType = 1; //
int32 count = 2; //
}
message UserAddResResp {
string resType = 1; //
int32 count = 2; //
}

View File

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