From b7ad761d9655130094a2f317f958402fa990bec9 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 7 Dec 2022 11:06:13 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=B7=B3=E8=BF=87=E4=B8=BB=E7=BA=BF?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/mainline/module.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/mainline/module.go b/modules/mainline/module.go index 33a698d79..e1d151c54 100644 --- a/modules/mainline/module.go +++ b/modules/mainline/module.go @@ -133,7 +133,7 @@ func (this *Mainline) CheckPoint(uid string) bool { func (this *Mainline) ModifyMainlineDataByNanduID(uid string, nandu, id int32) (code pb.ErrorCode) { conf := this.configure.GetMainlineConfigData(id, nandu) - if conf != nil { + if conf == nil { code = pb.ErrorCode_ConfigNoFound // 找不到配置 return } @@ -142,17 +142,19 @@ func (this *Mainline) ModifyMainlineDataByNanduID(uid string, nandu, id int32) ( // 获取当前的章节数据 jumpCap := conf.Chapter // 先加所有难度小于1 的章节 - for ndIndex := 1; ndIndex < int(nandu)-1; ndIndex++ { + for ndIndex := 1; ndIndex <= int(nandu)-1; ndIndex++ { max := this.configure.GetMaxMainlineChapter() for i := 1; i <= int(max); i++ { + confCap := this.configure.GetMainlineChapter(int32(i)) + //_conf := this.configure.GetMainlineConfigData(int32(i), int32(ndIndex)) _data := &pb.DBMainline{} _data.Id = primitive.NewObjectID().Hex() - _data.ChapterId = conf.Chapter - _data.MainlineId = conf.Id + _data.ChapterId = int32(i) + _data.MainlineId = confCap.Id _mData := make(map[string]interface{}, 0) _data.Uid = uid _data.Intensity = int32(ndIndex) // 难度1 - confCap := this.configure.GetMainlineChapter(int32(i)) + for _, v := range confCap.Episode { _data.BranchID = append(_data.BranchID, v) } @@ -163,12 +165,12 @@ func (this *Mainline) ModifyMainlineDataByNanduID(uid string, nandu, id int32) ( } } // 加当前难度 的章节数据 - for i := 1; i < int(jumpCap-1); i++ { + for i := 1; i <= int(jumpCap-1); i++ { confCap := this.configure.GetMainlineChapter(int32(i)) _data := &pb.DBMainline{} _data.Id = primitive.NewObjectID().Hex() - _data.ChapterId = conf.Chapter - _data.MainlineId = conf.Id + _data.ChapterId = int32(i) + _data.MainlineId = confCap.Id _mData := make(map[string]interface{}, 0) _data.Uid = uid _data.Intensity = int32(nandu) // 难度1 @@ -186,9 +188,12 @@ func (this *Mainline) ModifyMainlineDataByNanduID(uid string, nandu, id int32) ( _mData := make(map[string]interface{}, 0) _data.Uid = uid _data.Intensity = int32(nandu) // 难度1 - // for _, v := range confCap.Episode { - // _data.BranchID = append(_data.BranchID, v) - // } + confCap := this.configure.GetMainlineChapter(int32(conf.Chapter)) + for _, v := range confCap.Episode { + if v <= id { + _data.BranchID = append(_data.BranchID, v) + } + } _mData[_data.Id] = _data this.modelMainline.addNewChapter(uid, _mData) From 158ea726cfadea3e07e08cf1a9449543da1235a8 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 7 Dec 2022 11:40:41 +0800 Subject: [PATCH 2/3] =?UTF-8?q?web=20=E9=82=AE=E4=BB=B6=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/web/api_creatmail.go | 46 ++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/modules/web/api_creatmail.go b/modules/web/api_creatmail.go index fbaca003e..04fe61f69 100644 --- a/modules/web/api_creatmail.go +++ b/modules/web/api_creatmail.go @@ -5,11 +5,19 @@ import ( "go_dreamfactory/lego/sys/gin/engine" "go_dreamfactory/pb" "net/http" + "time" + + "go.mongodb.org/mongo-driver/bson/primitive" ) type CrateMailReq struct { - pb.DBMailData - Sign string `json:"sign"` + Uid string // uid + Title string // 邮件标题 + Contex string // 邮件内容 支持自定义 + Items []*pb.UserAssets // 附件 + Cid string // 多语言表id + Param []string // 自定义参数 + Sign string `json:"sign"` } //创建邮件 @@ -23,15 +31,13 @@ func (this *Api_Comp) CreateMail(c *engine.Context) { data interface{} ) defer c.JSON(http.StatusOK, &Respond{Code: code, Message: msg, Data: data}) - if sign := gin.ParamSign(this.options.Key, map[string]interface{}{ - "Uid": req.Uid, - "Title": req.Title, - "Contex": req.Contex, - "CreateTime": req.CreateTime, - "DueTime": req.DueTime, - "Check": req.Check, - "Reward": req.Reward, - "Items": req.Items, + if sign := gin.ParamSign(this.options.Key, map[string]interface{}{ + "Uid": req.Uid, + "Title": req.Title, + "Contex": req.Contex, + "Items": req.Items, + "Cid": req.Cid, + "Param": req.Param, }); sign != req.Sign { this.module.Errorf("LoginByCaptchaReq SignError sgin:%s", sign) code = pb.ErrorCode_SignError @@ -43,7 +49,23 @@ func (this *Api_Comp) CreateMail(c *engine.Context) { msg = pb.GetErrorCodeMsg(code) return } - if err = this.module.modelMail.CreateGMMail(&req.DBMailData); err != nil { + mail := &pb.DBMailData{ + ObjId: primitive.NewObjectID().Hex(), + Uid: req.Uid, + Title: req.Title, + Contex: req.Contex, + CreateTime: uint64(time.Now().Unix()), + DueTime: uint64(time.Now().Unix() + 30*24*3600), + Check: false, + Reward: false, + Items: req.Items, + Cid: req.Cid, + Param: req.Param, + } + if len(req.Items) > 0 { + mail.Reward = true + } + if err = this.module.modelMail.CreateGMMail(mail); err != nil { this.module.Errorf("LoginByCaptchaReq CreateMail err:%v", err) code = pb.ErrorCode_DBError msg = pb.GetErrorCodeMsg(code) From a6b30ad1f2ac38d757ef5e4ef196f3f98a51e6b0 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 7 Dec 2022 19:19:54 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=B7=A5=E5=85=B7=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/gourmet/api_getlist.go | 6 +++ modules/web/api_creatmail.go | 8 ++-- stress/robot/robot.go | 42 +++++++++++++++++++++ stress/server/dispose.go | 2 +- stress/server/golink/websocket_link.go | 51 ++++++++++++-------------- 5 files changed, 77 insertions(+), 32 deletions(-) diff --git a/modules/gourmet/api_getlist.go b/modules/gourmet/api_getlist.go index b02ee7dc0..689bd9416 100644 --- a/modules/gourmet/api_getlist.go +++ b/modules/gourmet/api_getlist.go @@ -32,5 +32,11 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.GourmetGetListRe // 任务统计 this.module.ModuleRtask.SendToRtask(session, comm.Rtype136, _gourmet.TotalTime) + resp := &pb.GourmetCreateOrderReq{} + resp.Order = append(resp.Order, &pb.OrderCook{ + FoodType: 1001, + FoodCount: 10, + }) + this.CreateOrder(session, resp) return } diff --git a/modules/web/api_creatmail.go b/modules/web/api_creatmail.go index 04fe61f69..23a641588 100644 --- a/modules/web/api_creatmail.go +++ b/modules/web/api_creatmail.go @@ -11,11 +11,11 @@ import ( ) type CrateMailReq struct { - Uid string // uid - Title string // 邮件标题 - Contex string // 邮件内容 支持自定义 + Uid string `json:"uid"` // uid + Title string `json:"title"` // 邮件标题 + Contex string `json:"contex"` // 邮件内容 支持自定义 Items []*pb.UserAssets // 附件 - Cid string // 多语言表id + Cid string `json:"cid"` // 多语言表id Param []string // 自定义参数 Sign string `json:"sign"` } diff --git a/stress/robot/robot.go b/stress/robot/robot.go index 56fbc4456..2fb8e522f 100644 --- a/stress/robot/robot.go +++ b/stress/robot/robot.go @@ -364,3 +364,45 @@ func (r Robot) AddGrormetItem() bool { func (r *Robot) SetAccount(account string) { r.account = account } +func (r Robot) GourmetOrder() int64 { + var byteLen int64 + mainType := "gourmet" + subType := "createorder" + msg := &pb.UserMessage{MainType: mainType, SubType: subType} + + rsp := &pb.GourmetCreateOrderReq{} + rsp.Order = append(rsp.Order, &pb.OrderCook{ + FoodType: 1001, + FoodCount: 10, + }) + msg.Sec = r.BuildSecStr() + if comm.ProtoMarshal(rsp, msg) { + data, _ := proto.Marshal(msg) + err := r.ws.WriteMessage(websocket.BinaryMessage, data) + if err != nil { + fmt.Printf("WriteMessage err:%v", err) + } + } + + for { + var msg *pb.UserMessage = &pb.UserMessage{} + _, data, err := r.ws.ReadMessage() + if err != nil { + fmt.Printf("readMessage err:%v", err) + continue + } + + if err = proto.Unmarshal(data, msg); err != nil { + fmt.Printf("unmarshal err:%v", err) + } + if msg.MainType == mainType && msg.SubType == subType { + byteLen += int64(len(data)) + resp := &pb.GourmetCreateOrderResp{} + if !comm.ProtoUnmarshal(msg, resp) { //反序列化失败 + break + } + break + } + } + return byteLen +} diff --git a/stress/server/dispose.go b/stress/server/dispose.go index ed5bc6ac6..344ff7fda 100644 --- a/stress/server/dispose.go +++ b/stress/server/dispose.go @@ -59,7 +59,7 @@ func Dispose(ctx context.Context, concurrency, totalNumber uint64, request *mode head := &pb.UserMessage{MainType: "user", SubType: "login"} // 先登录 r.SendToClient(head, &pb.UserLoginReq{}) - r.AddGrormetItem() + //r.AddGrormetItem() go golink.WebSocket(ctx, i, ch, totalNumber, &wg, request, r) case 2: // 并发建立长链接 diff --git a/stress/server/golink/websocket_link.go b/stress/server/golink/websocket_link.go index 3254d21be..b8fdcf58c 100644 --- a/stress/server/golink/websocket_link.go +++ b/stress/server/golink/websocket_link.go @@ -3,17 +3,12 @@ package golink import ( "context" - "fmt" "sync" "time" - "go_dreamfactory/comm" - "go_dreamfactory/pb" "go_dreamfactory/stress/helper" "go_dreamfactory/stress/model" "go_dreamfactory/stress/robot" - - "github.com/golang/protobuf/proto" ) const ( @@ -87,29 +82,31 @@ func webSocketRequest(chanID uint64, ch chan<- *model.RequestResults, i uint64, //startTime := time.Now() // r.GetRandUser() // 获取随机在线玩家数据 - r.GetGourmetList() - - for { - var msg *pb.UserMessage = &pb.UserMessage{} - data, err := r.GetMessagedata() - if err != nil { - fmt.Printf("readMessage err:%v", err) - isSucceed = false - break - } - if err = proto.Unmarshal(data, msg); err != nil { - fmt.Printf("unmarshal err:%v", err) - } - if msg.MainType == "gourmet" && msg.SubType == "getlist" { - byteLen += int64(len(data)) - isSucceed = true - resp := &pb.GourmetGetListResp{} - if !comm.ProtoUnmarshal(msg, resp) { //反序列化失败 - break - } - break - } + byteLen = r.GourmetOrder() + if byteLen > 0 { + isSucceed = true } + // for { + // var msg *pb.UserMessage = &pb.UserMessage{} + // data, err := r.GetMessagedata() + // if err != nil { + // fmt.Printf("readMessage err:%v", err) + // isSucceed = false + // break + // } + // if err = proto.Unmarshal(data, msg); err != nil { + // fmt.Printf("unmarshal err:%v", err) + // } + // if msg.MainType == "gourmet" && msg.SubType == "getlist" { + // byteLen += int64(len(data)) + // isSucceed = true + // resp := &pb.GourmetGetListResp{} + // if !comm.ProtoUnmarshal(msg, resp) { //反序列化失败 + // break + // } + // break + // } + // } requestTime := uint64(helper.DiffNano(startTime)) requestResults := &model.RequestResults{