diff --git a/cmd/robot/login.go b/cmd/robot/login.go index 63494f0b2..99f167605 100644 --- a/cmd/robot/login.go +++ b/cmd/robot/login.go @@ -9,8 +9,10 @@ import ( "log" "time" + "github.com/Pallinder/go-randomdata" jsoniter "github.com/json-iterator/go" "github.com/nacos-group/nacos-sdk-go/util" + "google.golang.org/protobuf/proto" ) type LoginParam struct { @@ -45,6 +47,21 @@ func (r *Robot) AccountLogin() { }, rsp: &pb.UserLoginResp{}, enabled: true, + next: func(rsp proto.Message, handle func(nextCase *TestCase)) { + if _, ok := rsp.(*pb.UserLoginResp); ok { + nick := randomdata.SillyName() + handle(&TestCase{ + desc: "创角", + mainType: string(comm.ModuleUser), + subType: user.UserSubTypeCreate, + req: &pb.UserCreateReq{ //设置请求参数 + NickName: nick, + }, + rsp: &pb.UserCreateResp{}, + enabled: true, + }) + } + }, }, } r.addBuilders(builders) diff --git a/cmd/robot/robot.go b/cmd/robot/robot.go index 211274578..b6c410f2c 100644 --- a/cmd/robot/robot.go +++ b/cmd/robot/robot.go @@ -189,6 +189,9 @@ func (r *Robot) onUserLoaded() { //task r.RunTask() + + // story + r.RunStory() } //注册账号 diff --git a/cmd/robot/story.go b/cmd/robot/story.go new file mode 100644 index 000000000..e56c5afa9 --- /dev/null +++ b/cmd/robot/story.go @@ -0,0 +1,45 @@ +package robot + +import ( + "fmt" + "go_dreamfactory/comm" + "go_dreamfactory/modules/story" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +var ( + storyBuilders = []*TestCase{ + { + desc: "主线数据", + mainType: string(comm.ModuleStory), + subType: story.StoryGetListResp, + req: &pb.StoryGetListReq{}, + rsp: &pb.StoryGetListResp{}, + print: func(rsp proto.Message) { + out := rsp.(*pb.StoryGetListResp) + for i, v := range out.Data { + fmt.Printf("%d- %v\n", (i + 1), v) + } + }, + //enabled: true, + }, { + desc: "主线详情", + mainType: string(comm.ModuleStory), + subType: story.StoryChallengeResp, + req: &pb.StoryChallengeReq{ + ChapterId: 1, + StoryId: 1, + }, + rsp: &pb.StoryChallengeResp{}, + enabled: true, + }, + } +) + +//声明加入到构建器并发起请求 +func (r *Robot) RunStory() { + r.addBuilders(storyBuilders) + r.batchHandleReq() +} diff --git a/go.mod b/go.mod index 6deb63a2d..dcf8ab70c 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.18 require ( bright v0.0.0 + github.com/Pallinder/go-randomdata v1.2.0 github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 github.com/dengsgo/math-engine v0.0.0-20220213125415-0351c3c75eca github.com/go-playground/validator/v10 v10.10.1 @@ -74,7 +75,6 @@ require ( github.com/hashicorp/serf v0.9.7 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c // indirect - github.com/jinzhu/now v1.1.5 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/juju/ratelimit v1.0.1 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect diff --git a/go.sum b/go.sum index 222a87f5b..96d3f1cd2 100644 --- a/go.sum +++ b/go.sum @@ -49,6 +49,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChimeraCoder/gojson v1.1.0/go.mod h1:nYbTQlu6hv8PETM15J927yM0zGj3njIldp72UT1MqSw= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= +github.com/Pallinder/go-randomdata v1.2.0 h1:DZ41wBchNRb/0GfsePLiSwb0PHZmT67XY00lCDlaYPg= +github.com/Pallinder/go-randomdata v1.2.0/go.mod h1:yHmJgulpD2Nfrm0cR9tI/+oAgRqCQQixsA8HyRZfV9Y= github.com/akutz/memconn v0.1.0 h1:NawI0TORU4hcOMsMr11g7vwlCdkYeLKXBcxWu2W/P8A= github.com/akutz/memconn v0.1.0/go.mod h1:Jo8rI7m0NieZyLI5e2CDlRdRqRRB4S7Xp77ukDjH+Fw= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -367,8 +369,6 @@ github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c/go.mod github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4= github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag= github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= -github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= -github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= diff --git a/lego/core/cbase/servicebase.go b/lego/core/cbase/servicebase.go index da2c3b38f..fe7972353 100644 --- a/lego/core/cbase/servicebase.go +++ b/lego/core/cbase/servicebase.go @@ -99,13 +99,15 @@ func (this *ServiceBase) Run(mod ...core.IModule) { mi: v, closeSig: make(chan bool, 1), } + + log.Warnf("注册模块【%s】 对应的配置信息", v.GetType()) } else { this.modules[v.GetType()] = &defaultModule{ seetring: make(map[string]interface{}), mi: v, closeSig: make(chan bool, 1), } - log.Warnf("注册模块【%s】 没有对应的配置信息", v.GetType()) + //log.Warnf("注册模块【%s】 没有对应的配置信息", v.GetType()) } } for _, v := range this.modules { //序列化每一个模块的参数对象 完成模块的初始化 过程 diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index f184a2c72..be52221c1 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -11,6 +11,8 @@ import ( mengine "github.com/dengsgo/math-engine/engine" "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" ) type ModelHero struct { @@ -22,6 +24,10 @@ func (this *ModelHero) Init(service core.IService, module core.IModule, comp cor err = this.MCompModel.Init(service, module, comp, options) this.moduleHero = module.(*Hero) this.TableName = "hero" + // 通过uid创建索引 + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) return } diff --git a/modules/mail/api.go b/modules/mail/api.go index ad063b9a9..0e0aa3aca 100644 --- a/modules/mail/api.go +++ b/modules/mail/api.go @@ -6,14 +6,6 @@ import ( "go_dreamfactory/lego/core" ) -const ( - QueryUserMailResp = "queryusermailresp" - ReadUserMailResp = "readusermailresp" - GetUserMailAttachmentResp = "getusermailattachmentresp" - DelUserMailResp = "delusermailresp" - GetNewEMailResp = "getnewEmailresp" -) - type apiComp struct { modules.MCompGate service core.IService diff --git a/modules/mail/api_delmail.go b/modules/mail/api_delmail.go index 3c5efcbc5..504c55350 100644 --- a/modules/mail/api_delmail.go +++ b/modules/mail/api_delmail.go @@ -11,7 +11,7 @@ import ( //参数校验 func (this *apiComp) DelMailCheck(session comm.IUserSession, req *pb.MailDelMailReq) (code pb.ErrorCode) { if session.GetUserId() == "" || req.ObjID == "" { - code = pb.ErrorCode_NoLogin + code = pb.ErrorCode_ReqParameterError return } return @@ -23,7 +23,7 @@ func (this *apiComp) DelMail(session comm.IUserSession, req *pb.MailDelMailReq) var err error mailinfo := make([]*pb.DBMailData, 0) defer func() { - session.SendMsg(string(this.module.GetType()), DelUserMailResp, &pb.MailDelMailResp{Mail: mailinfo}) + session.SendMsg(string(this.module.GetType()), "delmail", &pb.MailDelMailResp{Mail: mailinfo}) }() code = this.DelMailCheck(session, req) // check if code != pb.ErrorCode_Success { diff --git a/modules/mail/api_getAttachment.go b/modules/mail/api_getAttachment.go index 72c733ac7..5773360f7 100644 --- a/modules/mail/api_getAttachment.go +++ b/modules/mail/api_getAttachment.go @@ -22,7 +22,7 @@ func (this *apiComp) GetUserMailAttachment(session comm.IUserSession, req *pb.Ma mail *pb.DBMailData ) defer func() { - session.SendMsg(string(this.module.GetType()), GetUserMailAttachmentResp, &pb.MailGetUserMailAttachmentResp{Mail: mail}) + session.SendMsg(string(this.module.GetType()), "getusermailattachment", &pb.MailGetUserMailAttachmentResp{Mail: mail}) }() code = this.GetUserMailAttachmentCheck(session, req) // check diff --git a/modules/mail/api_getmail.go b/modules/mail/api_getmail.go index 56af62a0f..cf610060a 100644 --- a/modules/mail/api_getmail.go +++ b/modules/mail/api_getmail.go @@ -18,7 +18,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.MailGetListReq) var err error mailinfo := make([]*pb.DBMailData, 0) defer func() { - session.SendMsg(string(this.module.GetType()), QueryUserMailResp, &pb.MailGetListResp{Mails: mailinfo}) + session.SendMsg(string(this.module.GetType()), "getlist", &pb.MailGetListResp{Mails: mailinfo}) }() code = this.GetListCheck(session, req) // check if code != pb.ErrorCode_Success { diff --git a/modules/mail/api_readmail.go b/modules/mail/api_readmail.go index 81d222aca..0e4c4be7b 100644 --- a/modules/mail/api_readmail.go +++ b/modules/mail/api_readmail.go @@ -9,7 +9,7 @@ import ( func (this *apiComp) ReadMailCheck(session comm.IUserSession, req *pb.MailReadMailReq) (code pb.ErrorCode) { if session.GetUserId() == "" || req.ObjID == "" { - code = pb.ErrorCode_NoLogin + code = pb.ErrorCode_ReqParameterError return } return @@ -22,7 +22,7 @@ func (this *apiComp) ReadMail(session comm.IUserSession, req *pb.MailReadMailReq mail *pb.DBMailData ) defer func() { - session.SendMsg(string(this.module.GetType()), ReadUserMailResp, &pb.MailReadMailResp{Mail: mail}) + session.SendMsg(string(this.module.GetType()), "readmail", &pb.MailReadMailResp{Mail: mail}) }() code = this.ReadMailCheck(session, req) // check if code != pb.ErrorCode_Success { diff --git a/modules/mail/module.go b/modules/mail/module.go index 088a57d01..c652bc61a 100644 --- a/modules/mail/module.go +++ b/modules/mail/module.go @@ -62,6 +62,6 @@ func (this *Mail) CreateNewMail(uId string, mail *pb.DBMailData) bool { return false } - this.SendMsgToUser(string(this.GetType()), GetNewEMailResp, mail, _cache) + this.SendMsgToUser(string(this.GetType()), "newmail", mail, _cache) return true } diff --git a/modules/story/api_challenge.go b/modules/story/api_challenge.go index 18ba35b79..9af8faae7 100644 --- a/modules/story/api_challenge.go +++ b/modules/story/api_challenge.go @@ -5,6 +5,7 @@ import ( "go_dreamfactory/pb" "sort" + "go.mongodb.org/mongo-driver/bson/primitive" "google.golang.org/protobuf/proto" ) @@ -39,20 +40,35 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallenge if len(list) > 0 { curChapter = list[0] // 取第一条(第一条肯定是最新的) } - if curChapter == nil { - code = pb.ErrorCode_StoryNotFindChapter // 没有找到主线关卡信息 - return - } + // 先校验是不是分支 chaptConfig := this.module.configure.GetStoryChapter(int32(req.ChapterId)) // 根据配置文件找 if chaptConfig == nil { code = pb.ErrorCode_ConfigNoFound return } + if curChapter == nil { + if len(chaptConfig.Fubendata) <= 0 { + code = pb.ErrorCode_ConfigNoFound + return + } + if int32(req.ChapterId) != 1 { + code = pb.ErrorCode_ReqParameterError + return + } + _data := &pb.DBStory{} + _data.Id = primitive.NewObjectID().Hex() + _data.ChapterId = int32(req.ChapterId) + _mData := make(map[string]interface{}, 0) + _mData[_data.Id] = _data + this.module.modelStory.addNewChapter(session.GetUserId(), _mData) + curChapter = _data + //curChapter.StoryId = chaptConfig.Fubendata[0] // 第一次挑战 + } // 根据难度找对应的配置文件 - if chaptConfig.Intensity == "1" { // 这里安临时配置读取 后面会修改 + if chaptConfig.Intensity == "1" { // 这里按临时配置读取 后面会修改 con := this.module.configure.GetStoryEasyChapter(int32(req.StoryId)) // 根据配置文件找 - if con != nil { + if con == nil { code = pb.ErrorCode_ConfigNoFound return } @@ -66,13 +82,16 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallenge } } // TODO 调用战斗逻辑 + // 挑战成功 + curChapter.StoryId += 1 // 临时数据 后面配置表完善查找 if bBranch { curChapter.BranchID = append(curChapter.BranchID, int32(req.ChapterId)) // 记录分支关卡 } if curChapter.ChapterId == int32(req.ChapterId) && curChapter.StoryId == int32(req.StoryId) { update := map[string]interface{}{ - "storyId": req.StoryId, - "branchID": curChapter.BranchID, + "storyId": req.StoryId, + "ChapterId": req.ChapterId, + "branchID": curChapter.BranchID, } err = this.module.modelStory.modifyStoryData(session.GetUserId(), curChapter.Id, update) } diff --git a/modules/story/model_story.go b/modules/story/model_story.go index 057297d7b..8a5132fe9 100644 --- a/modules/story/model_story.go +++ b/modules/story/model_story.go @@ -2,6 +2,7 @@ package story import ( "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" ) @@ -33,3 +34,13 @@ func (this *ModelStory) getStoryList(uid string) (storys []*pb.DBStory, err erro func (this *ModelStory) modifyStoryData(uid string, objid string, data map[string]interface{}) error { return this.moduleStory.modelStory.ChangeList(uid, objid, data) } + +// 增加新的章节数据 +func (this *ModelStory) addNewChapter(uId string, data map[string]interface{}) (err error) { + + if err = this.AddLists(uId, data); err != nil { + log.Errorf("err:%v", err) + return + } + return nil +} diff --git a/services/comp_gateroute.go b/services/comp_gateroute.go index 1d03552f4..10f1c46f0 100644 --- a/services/comp_gateroute.go +++ b/services/comp_gateroute.go @@ -74,7 +74,7 @@ func (this *SCompGateRoute) Start() (err error) { //业务模块注册用户消息处理路由 func (this *SCompGateRoute) RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, handele reflect.Method) { - log.Debugf("注册用户路由【%s】", methodName) + //log.Debugf("注册用户路由【%s】", methodName) this.mrlock.RLock() _, ok := this.msghandles[methodName] this.mrlock.RUnlock() diff --git a/test/module_test.go b/test/module_test.go deleted file mode 100644 index a6bea40cf..000000000 --- a/test/module_test.go +++ /dev/null @@ -1,2 +0,0 @@ -package test -