数据校验

This commit is contained in:
meixiongfeng 2022-07-13 11:32:06 +08:00
parent cfc9a018f0
commit e40621b335
5 changed files with 42 additions and 11 deletions

View File

@ -23,7 +23,7 @@ var (
fmt.Printf("%d- %v\n", (i + 1), v)
}
},
enabled: true,
//enabled: true,
}, {
desc: "主线详情",
mainType: string(comm.ModuleStory),
@ -32,8 +32,8 @@ var (
ChapterId: 1,
StoryId: 1,
},
rsp: &pb.StoryChallengeResp{},
// enabled: true,
rsp: &pb.StoryChallengeResp{},
enabled: true,
},
}
)

View File

@ -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 { //序列化每一个模块的参数对象 完成模块的初始化 过程

View File

@ -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)
_map := make(map[string]*pb.DBStory)
_map[_data.Id] = _data
//this.module.modelStory.addNewChapter(session.GetUserId(), _map)
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,6 +82,8 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallenge
}
}
// TODO 调用战斗逻辑
// 挑战成功
curChapter.StoryId += 1 // 临时数据 后面配置表完善查找
if bBranch {
curChapter.BranchID = append(curChapter.BranchID, int32(req.ChapterId)) // 记录分支关卡
}

View File

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

View File

@ -9,7 +9,7 @@ import (
)
func (this *apiComp) AddResCheck(session comm.IUserSession, req *pb.UserAddResReq) (code pb.ErrorCode) {
if req.Res.A == "" || req.Res.T == "" || req.Res.N > 0 {
if req.Res.A == "" || req.Res.T == "" || req.Res.N <= 0 {
code = pb.ErrorCode_ReqParameterError
}
return