diff --git a/cmd/robot/friend.go b/cmd/robot/friend.go index 72c3335ea..af4020a95 100644 --- a/cmd/robot/friend.go +++ b/cmd/robot/friend.go @@ -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), diff --git a/cmd/robot/hero.go b/cmd/robot/hero.go index 779d069ea..06bb8f1f0 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 56419ee4c..a71969bd5 100644 --- a/cmd/robot/user.go +++ b/cmd/robot/user.go @@ -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), diff --git a/modules/comp_model.go b/modules/comp_model.go index 76843f096..1f1a92ea0 100644 --- a/modules/comp_model.go +++ b/modules/comp_model.go @@ -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 } diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index c97465a10..d4e67e3c7 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -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 diff --git a/modules/user/api_create.go b/modules/user/api_create.go index db736d749..670156747 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -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 diff --git a/modules/user/api_login.go b/modules/user/api_login.go index 2f900849b..c2743e99b 100644 --- a/modules/user/api_login.go +++ b/modules/user/api_login.go @@ -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) diff --git a/modules/user/model_user.go b/modules/user/model_user.go index 5cc0607e5..9b6331b6d 100644 --- a/modules/user/model_user.go +++ b/modules/user/model_user.go @@ -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) } diff --git a/pb/errorcode.pb.go b/pb/errorcode.pb.go index e385afb8c..7cf712da2 100644 --- a/pb/errorcode.pb.go +++ b/pb/errorcode.pb.go @@ -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, diff --git a/pb/proto/errorcode.proto b/pb/proto/errorcode.proto index 709e4b3ae..d6d66b4f3 100644 --- a/pb/proto/errorcode.proto +++ b/pb/proto/errorcode.proto @@ -29,6 +29,7 @@ enum ErrorCode { GoldNoEnough = 1003; // 金币不足 DiamondNoEnough = 1004; // 钻石不足 RoleCreated = 1005; //已创角 + NameExist = 1006; //昵称已存在 // friend FriendNotSelf = 1100; //不能是自己 diff --git a/pb/proto/user/user_db.proto b/pb/proto/user/user_db.proto index 59afbbc7b..69156cc96 100644 --- a/pb/proto/user/user_db.proto +++ b/pb/proto/user/user_db.proto @@ -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 } \ No newline at end of file diff --git a/pb/user_db.pb.go b/pb/user_db.pb.go index 4424d5ddb..678686ea8 100644 --- a/pb/user_db.pb.go +++ b/pb/user_db.pb.go @@ -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 (