优化userErrCode

This commit is contained in:
wh_zcy 2023-05-25 20:06:39 +08:00
parent 64e9ff0fe7
commit 0fd9bac9f9
5 changed files with 75 additions and 55 deletions

View File

@ -6,6 +6,9 @@ import (
"go_dreamfactory/lego/base" "go_dreamfactory/lego/base"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"google.golang.org/protobuf/proto"
) )
const ( const (
@ -68,3 +71,10 @@ func (this *apiComp) Start() (err error) {
this.chat = module.(comm.IChat) this.chat = module.(comm.IChat)
return return
} }
func (this *apiComp) sendMsg(session comm.IUserSession, subType string, rsp proto.Message) {
if err := session.SendMsg(string(this.module.GetType()), subType, rsp); err != nil {
this.module.Error("User sendMsg err", log.Field{Key: "err", Value: err.Error()})
return
}
}

View File

@ -27,6 +27,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
return return
} }
resp := &pb.UserCreateResp{}
uid := session.GetUserId() uid := session.GetUserId()
//获取用户 //获取用户
self := this.module.modelUser.GetUser(session.GetUserId()) self := this.module.modelUser.GetUser(session.GetUserId())
@ -43,7 +44,8 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
//查询昵称是否重复 //查询昵称是否重复
if ok := this.module.modelUser.NickNameIsExist(req.NickName); !ok { if ok := this.module.modelUser.NickNameIsExist(req.NickName); !ok {
code = pb.ErrorCode_UserNickNameExist resp.Code = pb.ErrorCode_UserNickNameExist
this.sendMsg(session, UserSubTypeCreate, resp)
return return
} }
@ -116,9 +118,8 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
// } // }
// }() // }()
if err := session.SendMsg(string(this.module.GetType()), UserSubTypeCreate, &pb.UserCreateResp{IsSucc: true}); err != nil { resp.IsSucc = true
code = pb.ErrorCode_SystemError this.sendMsg(session, UserSubTypeCreate, resp)
}
if req.Figure != 0 { if req.Figure != 0 {
go this.module.ModuleRtask.TriggerTask(uid, comm.GettaskParam(comm.Rtype72, 1)) go this.module.ModuleRtask.TriggerTask(uid, comm.GettaskParam(comm.Rtype72, 1))

View File

@ -17,15 +17,17 @@ func (this *apiComp) Modifyname(session comm.IUserSession, req *pb.UserModifynam
if code = this.ModifynameCheck(session, req); code != pb.ErrorCode_Success { if code = this.ModifynameCheck(session, req); code != pb.ErrorCode_Success {
return return
} }
uid := session.GetUserId()
resp := &pb.UserModifynameResp{Uid: uid, Name: req.Name}
name := strings.TrimSpace(req.Name) name := strings.TrimSpace(req.Name)
//验证名称 //验证名称
if !this.module.modelUser.NickNameIsExist(name) { if !this.module.modelUser.NickNameIsExist(name) {
code = pb.ErrorCode_UserNickNameExist resp.Code = pb.ErrorCode_UserNickNameExist
this.sendMsg(session, UserSubTypeModifyName, resp)
return return
} }
expand, err := this.module.modelExpand.GetUserExpand(session.GetUserId()) expand, err := this.module.modelExpand.GetUserExpand(uid)
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
@ -37,7 +39,7 @@ func (this *apiComp) Modifyname(session comm.IUserSession, req *pb.UserModifynam
if code != pb.ErrorCode_Success { if code != pb.ErrorCode_Success {
return return
} }
this.module.Infof("修改昵称 uid:%v 消耗:%v code:%v", session.GetUserId(), this.module.globalConf.HeroName, code) this.module.Infof("修改昵称 uid:%v 消耗:%v code:%v", uid, this.module.globalConf.HeroName, code)
} }
//修改名称次数 //修改名称次数
@ -48,24 +50,19 @@ func (this *apiComp) Modifyname(session comm.IUserSession, req *pb.UserModifynam
mc := map[string]interface{}{ mc := map[string]interface{}{
"modifynameCount": left, "modifynameCount": left,
} }
if err := this.module.modelExpand.ChangeUserExpand(session.GetUserId(), mc); err != nil { if err := this.module.modelExpand.ChangeUserExpand(uid, mc); err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
this.module.Errorf("更新昵称失败 uid:%v name:%v err:%v", session.GetUserId(), req.Name, err) this.module.Errorf("更新昵称失败 uid:%v name:%v err:%v", uid, req.Name, err)
return return
} }
// 修改名称 // 修改名称
if code = this.module.modelUser.modifyName(session.GetUserId(), name); code != pb.ErrorCode_Success { if code = this.module.modelUser.modifyName(uid, name); code != pb.ErrorCode_Success {
return return
} }
if err = session.SendMsg(string(this.module.GetType()), UserSubTypeModifyName, &pb.UserModifynameResp{ resp.Count = uint32(left)
Uid: session.GetUserId(), this.sendMsg(session, UserSubTypeModifyName, resp)
Count: uint32(left),
Name: req.Name,
}); err != nil {
code = pb.ErrorCode_SystemError
}
return return
} }

View File

@ -2,10 +2,7 @@ package user
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
) )
// 参数校验 // 参数校验
@ -25,10 +22,3 @@ func (this *apiComp) Sign(session comm.IUserSession, req *pb.UserSignReq) (code
return return
} }
func (this *apiComp) sendMsg(session comm.IUserSession, subType string, rsp proto.Message) {
if err := session.SendMsg(string(this.module.GetType()), subType, rsp); err != nil {
this.module.Error("UserModule sendMsg err", log.Field{Key: "err", Value: err.Error()})
return
}
}

View File

@ -569,7 +569,8 @@ type UserCreateResp struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
IsSucc bool `protobuf:"varint,1,opt,name=IsSucc,proto3" json:"IsSucc"` IsSucc bool `protobuf:"varint,1,opt,name=IsSucc,proto3" json:"IsSucc"`
Code ErrorCode `protobuf:"varint,2,opt,name=code,proto3,enum=ErrorCode" json:"code"`
} }
func (x *UserCreateResp) Reset() { func (x *UserCreateResp) Reset() {
@ -611,6 +612,13 @@ func (x *UserCreateResp) GetIsSucc() bool {
return false return false
} }
func (x *UserCreateResp) GetCode() ErrorCode {
if x != nil {
return x.Code
}
return ErrorCode_Success
}
// 玩家资源变更推送 // 玩家资源变更推送
type UserResChangedPush struct { type UserResChangedPush struct {
state protoimpl.MessageState state protoimpl.MessageState
@ -1281,9 +1289,10 @@ type UserModifynameResp struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid"` Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid"`
Count uint32 `protobuf:"varint,2,opt,name=count,proto3" json:"count"` //剩余修改次数 Count uint32 `protobuf:"varint,2,opt,name=count,proto3" json:"count"` //剩余修改次数
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name"` Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name"`
Code ErrorCode `protobuf:"varint,4,opt,name=code,proto3,enum=ErrorCode" json:"code"`
} }
func (x *UserModifynameResp) Reset() { func (x *UserModifynameResp) Reset() {
@ -1339,6 +1348,13 @@ func (x *UserModifynameResp) GetName() string {
return "" return ""
} }
func (x *UserModifynameResp) GetCode() ErrorCode {
if x != nil {
return x.Code
}
return ErrorCode_Success
}
// 修改头像 // 修改头像
type UserModifyavatarReq struct { type UserModifyavatarReq struct {
state protoimpl.MessageState state protoimpl.MessageState
@ -3089,10 +3105,12 @@ var file_user_user_msg_proto_rawDesc = []byte{
0x52, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x69, 0x52, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x69,
0x67, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x66, 0x69, 0x67, 0x75, 0x67, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x66, 0x69, 0x67, 0x75,
0x72, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x72, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01,
0x28, 0x05, 0x52, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x22, 0x28, 0x0a, 0x0e, 0x55, 0x73, 0x28, 0x05, 0x52, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x22, 0x48, 0x0a, 0x0e, 0x55, 0x73,
0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06,
0x49, 0x73, 0x53, 0x75, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x49, 0x73, 0x49, 0x73, 0x53, 0x75, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x49, 0x73,
0x53, 0x75, 0x63, 0x63, 0x22, 0x96, 0x03, 0x0a, 0x12, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x53, 0x75, 0x63, 0x63, 0x12, 0x1e, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01,
0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04,
0x63, 0x6f, 0x64, 0x65, 0x22, 0x96, 0x03, 0x0a, 0x12, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73,
0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x50, 0x75, 0x73, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x67, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x50, 0x75, 0x73, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x67,
0x6f, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x67, 0x6f, 0x6c, 0x64, 0x12, 0x6f, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x67, 0x6f, 0x6c, 0x64, 0x12,
0x10, 0x0a, 0x03, 0x65, 0x78, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x65, 0x78, 0x10, 0x0a, 0x03, 0x65, 0x78, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x65, 0x78,
@ -3146,12 +3164,14 @@ var file_user_user_msg_proto_rawDesc = []byte{
0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x22, 0x27, 0x0a, 0x11, 0x55, 0x73, 0x65, 0x72, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x22, 0x27, 0x0a, 0x11, 0x55, 0x73, 0x65, 0x72,
0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x6e, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x6e, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a,
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d,
0x65, 0x22, 0x50, 0x0a, 0x12, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x6e, 0x65, 0x22, 0x70, 0x0a, 0x12, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x6e,
0x61, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75,
0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12,
0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e,
0x61, 0x6d, 0x65, 0x22, 0x31, 0x0a, 0x13, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x61, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28,
0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x63,
0x6f, 0x64, 0x65, 0x22, 0x31, 0x0a, 0x13, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x6f, 0x64, 0x69, 0x66,
0x79, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x76, 0x79, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x76,
0x61, 0x74, 0x61, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x61, 0x76,
0x61, 0x74, 0x61, 0x72, 0x49, 0x64, 0x22, 0x44, 0x0a, 0x14, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x6f, 0x61, 0x74, 0x61, 0x72, 0x49, 0x64, 0x22, 0x44, 0x0a, 0x14, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x6f,
@ -3371,25 +3391,27 @@ var file_user_user_msg_proto_depIdxs = []int32{
58, // 3: UserInfoResp.ex:type_name -> DBUserExpand 58, // 3: UserInfoResp.ex:type_name -> DBUserExpand
59, // 4: UserRegisterResp.Code:type_name -> ErrorCode 59, // 4: UserRegisterResp.Code:type_name -> ErrorCode
60, // 5: UserLoadResp.data:type_name -> CacheUser 60, // 5: UserLoadResp.data:type_name -> CacheUser
61, // 6: UserGetSettingResp.setting:type_name -> DBUserSetting 59, // 6: UserCreateResp.code:type_name -> ErrorCode
61, // 7: UserUpdateSettingReq.setting:type_name -> DBUserSetting 61, // 7: UserGetSettingResp.setting:type_name -> DBUserSetting
57, // 8: UserBattlerecordResp.data:type_name -> DBUser 61, // 8: UserUpdateSettingReq.setting:type_name -> DBUserSetting
58, // 9: UserBattlerecordResp.ex:type_name -> DBUserExpand 59, // 9: UserModifynameResp.code:type_name -> ErrorCode
62, // 10: UserBattlerecordResp.pagodaRecord:type_name -> DBPagodaRecord 57, // 10: UserBattlerecordResp.data:type_name -> DBUser
63, // 11: UserBattlerecordResp.huntingRecord:type_name -> DBHuntingRank 58, // 11: UserBattlerecordResp.ex:type_name -> DBUserExpand
64, // 12: UserBattlerecordResp.vikingRecord:type_name -> DBVikingRank 62, // 12: UserBattlerecordResp.pagodaRecord:type_name -> DBPagodaRecord
60, // 13: UserOnlineResp.users:type_name -> CacheUser 63, // 13: UserBattlerecordResp.huntingRecord:type_name -> DBHuntingRank
57, // 14: UserDataListResp.users:type_name -> DBUser 64, // 14: UserBattlerecordResp.vikingRecord:type_name -> DBVikingRank
65, // 15: UserGetServerDataResp.data:type_name -> DBServerData 60, // 15: UserOnlineResp.users:type_name -> CacheUser
66, // 16: UserSignResp.data:type_name -> DBSign 57, // 16: UserDataListResp.users:type_name -> DBUser
66, // 17: UserChangeTipsResp.data:type_name -> DBSign 65, // 17: UserGetServerDataResp.data:type_name -> DBServerData
67, // 18: UserSellResReq.atno:type_name -> UserAtno 66, // 18: UserSignResp.data:type_name -> DBSign
68, // 19: UserSellResResp.atn:type_name -> UserAssets 66, // 19: UserChangeTipsResp.data:type_name -> DBSign
20, // [20:20] is the sub-list for method output_type 67, // 20: UserSellResReq.atno:type_name -> UserAtno
20, // [20:20] is the sub-list for method input_type 68, // 21: UserSellResResp.atn:type_name -> UserAssets
20, // [20:20] is the sub-list for extension type_name 22, // [22:22] is the sub-list for method output_type
20, // [20:20] is the sub-list for extension extendee 22, // [22:22] is the sub-list for method input_type
0, // [0:20] is the sub-list for field type_name 22, // [22:22] is the sub-list for extension type_name
22, // [22:22] is the sub-list for extension extendee
0, // [0:22] is the sub-list for field type_name
} }
func init() { file_user_user_msg_proto_init() } func init() { file_user_user_msg_proto_init() }