This commit is contained in:
meixiongfeng 2022-07-04 17:35:37 +08:00
commit 30dadce861
12 changed files with 85 additions and 32 deletions

View File

@ -48,7 +48,7 @@ var (
subType: friend.FriendSubTypeApplyList,
req: &pb.FriendApplyListReq{},
rsp: &pb.FriendApplyListResp{},
enabled: true,
// enabled: true,
}, {
//agree
mainType: string(comm.ModuleFriend),
@ -66,7 +66,7 @@ var (
FriendIds: []string{"0_62c28bcb69b7d416cf9eb8c9"},
},
rsp: &pb.FriendRefuseResp{},
enabled: true,
// enabled: true,
}, {
//addblack
mainType: string(comm.ModuleFriend),

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

@ -14,10 +14,10 @@ var user_builders = []*TestCase{
mainType: string(comm.ModuleUser),
subType: user.UserSubTypeCreate,
req: &pb.UserCreateReq{ //设置请求参数
NickName: "乐谷748",
NickName: "乐谷7411",
},
rsp: &pb.UserCreateResp{},
// enabled: true,
enabled: true,
}, {
Desc: "添加资源",
mainType: string(comm.ModuleUser),

View File

@ -213,7 +213,6 @@ func (this *MCompModel) Get(uid string, data interface{}) (err error) {
return
}
if err == redis.RedisNil {
//query from mgo
if err = this.DB.FindOne(core.SqlTable(this.TableName), bson.M{"uid": uid}).Decode(data); err != nil {
return
}

View File

@ -57,18 +57,23 @@ func (this *ModelHero) initHero(uid string, heroCfgId int32) *pb.DBHero {
func (this *ModelHero) initHeroSkill(hero *pb.DBHero) []*pb.SkillData {
heroCfg := this.moduleHero.configure.GetHero(hero.HeroID)
if heroCfg != nil {
skills := []*pb.SkillData{{
SkillID: heroCfg.Skill1,
SkillLv: 1,
}, {
SkillID: heroCfg.Skill2,
SkillLv: 1,
}, {
SkillID: heroCfg.Skill3,
SkillLv: 1,
}}
if heroCfg.Skill != 0 {
hero.CaptainSkill = heroCfg.Skill
}
skills := []*pb.SkillData{}
if heroCfg.Skill1 != 0 {
skills = append(skills, &pb.SkillData{SkillID: heroCfg.Skill1, SkillLv: 1})
}
if heroCfg.Skill2 != 0 {
skills = append(skills, &pb.SkillData{SkillID: heroCfg.Skill2, SkillLv: 1})
}
if heroCfg.Skill3 != 0 {
skills = append(skills, &pb.SkillData{SkillID: heroCfg.Skill3, SkillLv: 1})
}
hero.NormalSkill = skills
hero.CaptainSkill = heroCfg.Skill
}
return nil

View File

@ -10,6 +10,7 @@ import (
)
func (this *apiComp) CreateCheck(session comm.IUserSession, req *pb.UserCreateReq) (code pb.ErrorCode) {
//暂时只处理昵称
if req.NickName == "" {
code = pb.ErrorCode_ReqParameterError
}
@ -22,8 +23,6 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
if code = this.CreateCheck(session, req); code != pb.ErrorCode_Success {
return
}
var err error
defer utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), UserSubTypeCreate, req, nil)
defer func() {
err := session.SendMsg(string(this.module.GetType()), UserSubTypeCreate, &pb.UserCreateResp{})
@ -32,16 +31,28 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
}
}()
self := &pb.DBUser{}
err = this.module.modelUser.Get(session.GetUserId(), self)
if err != nil {
code = pb.ErrorCode_DBError
//获取用户
self := this.module.modelUser.GetUser(session.GetUserId())
if self == nil {
code = pb.ErrorCode_UserSessionNobeing
return
}
//已否已创角
if self.Created {
code = pb.ErrorCode_RoleCreated
return
}
//查询昵称是否重复
if ok := this.module.modelUser.NickNameIsExist(req.NickName); !ok {
code = pb.ErrorCode_NameExist
return
}
update := map[string]interface{}{
"name": req.NickName,
"created": true,
"name": req.NickName, //设置昵称
"created": true, //创角标识
}
//设置初始金币
@ -49,7 +60,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
update["gold"] = cast.ToInt32(val)
}
err = this.module.modelUser.Change(session.GetUserId(), update)
err := this.module.modelUser.Change(session.GetUserId(), update)
if err != nil {
code = pb.ErrorCode_DBError
return

View File

@ -44,7 +44,7 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod
}()
//从mgo查询user
user, err = this.module.modelUser.User_FindByAccount(req.Sid, req.Account)
user, err = this.module.modelUser.FindByAccount(req.Sid, req.Account)
if err != nil {
if err != mongo.ErrNoDocuments {
log.Errorf("User_FindByAccount err %v", err)

View File

@ -11,6 +11,7 @@ import (
uuid "github.com/satori/go.uuid"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
)
const ( //Redis
@ -27,7 +28,7 @@ func (this *ModelUser) Init(service core.IService, module core.IModule, comp cor
return
}
func (this *ModelUser) User_FindByAccount(sid int32, account string) (*pb.DBUser, error) {
func (this *ModelUser) FindByAccount(sid int32, account string) (*pb.DBUser, error) {
filter := bson.M{
"sid": sid,
"binduid": account,
@ -38,11 +39,23 @@ func (this *ModelUser) User_FindByAccount(sid int32, account string) (*pb.DBUser
return nd, err
}
//查询昵称
func (this *ModelUser) NickNameIsExist(name string) bool {
if err := this.DB.FindOne(TableUser, bson.M{"name": name}).Err(); err != nil {
if err == mongo.ErrNoDocuments { //无记录
return true
}
}
return false
}
func (this *ModelUser) User_Create(user *pb.DBUser) (err error) {
_id := primitive.NewObjectID().Hex()
user.Id = _id
user.Uid = fmt.Sprintf("%d_%s", user.Sid, _id)
user.Uuid = uuid.NewV4().String()
user.Lv = 1 //初始等级
user.Ctime = time.Now().Unix()
return this.Add(user.Uid, user)
}

View File

@ -49,6 +49,7 @@ const (
ErrorCode_GoldNoEnough ErrorCode = 1003 // 金币不足
ErrorCode_DiamondNoEnough ErrorCode = 1004 // 钻石不足
ErrorCode_RoleCreated ErrorCode = 1005 //已创角
ErrorCode_NameExist ErrorCode = 1006 //昵称已存在
// friend
ErrorCode_FriendNotSelf ErrorCode = 1100 //不能是自己
ErrorCode_FriendSelfMax ErrorCode = 1101 //超出好友最大数量
@ -113,6 +114,7 @@ var (
1003: "GoldNoEnough",
1004: "DiamondNoEnough",
1005: "RoleCreated",
1006: "NameExist",
1100: "FriendNotSelf",
1101: "FriendSelfMax",
1102: "FriendTargetMax",
@ -170,6 +172,7 @@ var (
"GoldNoEnough": 1003,
"DiamondNoEnough": 1004,
"RoleCreated": 1005,
"NameExist": 1006,
"FriendNotSelf": 1100,
"FriendSelfMax": 1101,
"FriendTargetMax": 1102,
@ -234,7 +237,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, 0x88, 0x09, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
0x6f, 0x2a, 0x98, 0x09, 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,
0x1b, 0x0a, 0x17, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
@ -265,6 +268,7 @@ var file_errorcode_proto_rawDesc = []byte{
0x45, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0xeb, 0x07, 0x12, 0x14, 0x0a, 0x0f, 0x44, 0x69, 0x61,
0x6d, 0x6f, 0x6e, 0x64, 0x4e, 0x6f, 0x45, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0xec, 0x07, 0x12,
0x10, 0x0a, 0x0b, 0x52, 0x6f, 0x6c, 0x65, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x10, 0xed,
0x07, 0x12, 0x0e, 0x0a, 0x09, 0x4e, 0x61, 0x6d, 0x65, 0x45, 0x78, 0x69, 0x73, 0x74, 0x10, 0xee,
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,

View File

@ -29,6 +29,7 @@ enum ErrorCode {
GoldNoEnough = 1003; //
DiamondNoEnough = 1004; //
RoleCreated = 1005; //
NameExist = 1006; //
// friend
FriendNotSelf = 1100; //

View File

@ -24,4 +24,6 @@ message DBUser {
int32 gold = 13; //@go_tags(`bson:"gold"`)
int32 exp = 14; //@go_tags(`bson:"exp"`)
bool created = 15; //@go_tags(`bson:"created"`)
int32 lv = 16; //@go_tags(`bson:"lv"`)
int32 vip = 17; //@go_tags(`bson:"vip"`) vip
}

View File

@ -103,6 +103,8 @@ type DBUser struct {
Gold int32 `protobuf:"varint,13,opt,name=gold,proto3" json:"gold" bson:"gold"` //金币
Exp int32 `protobuf:"varint,14,opt,name=exp,proto3" json:"exp" bson:"exp"` //经验
Created bool `protobuf:"varint,15,opt,name=created,proto3" json:"created" bson:"created"` //创角
Lv int32 `protobuf:"varint,16,opt,name=lv,proto3" json:"lv" bson:"lv"` //等级
Vip int32 `protobuf:"varint,17,opt,name=vip,proto3" json:"vip" bson:"vip"` // vip
}
func (x *DBUser) Reset() {
@ -242,6 +244,20 @@ func (x *DBUser) GetCreated() bool {
return false
}
func (x *DBUser) GetLv() int32 {
if x != nil {
return x.Lv
}
return 0
}
func (x *DBUser) GetVip() int32 {
if x != nil {
return x.Vip
}
return 0
}
var File_user_user_db_proto protoreflect.FileDescriptor
var file_user_user_db_proto_rawDesc = []byte{
@ -252,7 +268,7 @@ var file_user_user_db_proto_rawDesc = []byte{
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49,
0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76,
0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x47, 0x61, 0x74,
0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x22, 0xea, 0x02,
0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x22, 0x8c, 0x03,
0x0a, 0x06, 0x44, 0x42, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18,
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75,
@ -275,8 +291,10 @@ var file_user_user_db_proto_rawDesc = []byte{
0x6c, 0x64, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x67, 0x6f, 0x6c, 0x64, 0x12, 0x10,
0x0a, 0x03, 0x65, 0x78, 0x70, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 0x78, 0x70,
0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x0f, 0x20, 0x01, 0x28,
0x08, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b,
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x08, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x6c, 0x76,
0x18, 0x10, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x6c, 0x76, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x69,
0x70, 0x18, 0x11, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x76, 0x69, 0x70, 0x42, 0x06, 0x5a, 0x04,
0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (