This commit is contained in:
liwei1dao 2022-12-06 11:03:49 +08:00
commit 974cb15287
27 changed files with 337 additions and 769 deletions

View File

@ -0,0 +1,44 @@
[
{
"id": 1,
"msg": "功能列表",
"route": "sys.funclist",
"params": "{}"
},
{
"id": 2,
"msg": "",
"route": "",
"params": ""
},
{
"id": 3,
"msg": "",
"route": "",
"params": ""
},
{
"id": 4,
"msg": "",
"route": "",
"params": ""
},
{
"id": 5,
"msg": "",
"route": "",
"params": ""
},
{
"id": 6,
"msg": "",
"route": "",
"params": ""
},
{
"id": 7,
"msg": "",
"route": "",
"params": ""
}
]

View File

@ -167,12 +167,8 @@ type (
ChangeCondi(uid string, data map[int32]*pb.RtaskData) error
//任务触发
SendToRtask(session IUserSession, rtaskType TaskType, params ...int32) (code pb.ErrorCode)
// 初始化条件数据
InitCondiData(uid string) error
// 获取任务条件记录
GetCondiData(uid string) *pb.DBRtaskRecord
// bingo任务
BingoRtask(session IUserSession, groupId, rtaskId int32) error
}
//好友

View File

@ -62,7 +62,7 @@ func (this *Gateway) Init(service core.IService, module core.IModule, options co
// Start 模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务
func (this *Gateway) Start() (err error) {
log.Debugf("dddd")
_name2Func := map[string]any{
// 注册用户绑定uid接口 登录成功后触发
string(comm.Rpc_GatewayAgentBind): this.agentMgr.Bind,

View File

@ -244,7 +244,7 @@ func (this *Hero) GetSpecifiedHero(session comm.IUserSession, heroConfId string,
//Event-------------------------------------------------------------------------------------------------玩家离线
func (this *Hero) EventUserOffline(session comm.IUserSession) {
err := this.modelHero.RemoveUserHeroInfo(session)
this.Debugf("EventUserOffline:%s err:%v", session, err)
this.Debugf("EventUserOffline:%s err:%v", session.ToString(), err)
}
// 批量创建多个英雄

View File

@ -40,7 +40,7 @@ func (this *DB_Comp) Start() (err error) {
}
func (this *DB_Comp) run() {
timer := time.NewTicker(time.Second * 2)
timer := time.NewTicker(time.Second * 1)
defer timer.Stop()
for {
select {

View File

@ -1,98 +0,0 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
)
// 做任务
func (this *apiComp) ApplyCheck(session comm.IUserSession, req *pb.RtaskApplyReq) (code pb.ErrorCode) {
if req.RtaskId == 0 || req.RtaskSubId == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) Apply(session comm.IUserSession, req *pb.RtaskApplyReq) (code pb.ErrorCode, data proto.Message) {
if code = this.ApplyCheck(session, req); code != pb.ErrorCode_Success {
return
}
// 获取当前玩家任务
rtask := this.moduleRtask.modelRtask.GetRtask(session.GetUserId())
if rtask == nil {
code = pb.ErrorCode_RtaskNoRtask
return
}
// 获取当前任务配置
conf := this.moduleRtask.configure.getRtaskById(req.RtaskId)
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
log.Errorf("rdtask %v no found", req.RtaskId)
return
}
var (
frtaskArr *pb.FrtaskIds
ok bool
)
// 获取当前组下已完成的任务
if frtaskArr, ok = rtask.FrtaskIds[conf.Group]; !ok {
frtaskArr = &pb.FrtaskIds{}
}
//验证该任务是否已完成
if _, ok := utils.Findx(frtaskArr.RtaskIds, req.RtaskId); ok {
code = pb.ErrorCode_RtaskFinished
return
}
sideConf := this.moduleRtask.configure.getRtaskSidById(req.RtaskSubId)
if sideConf == nil {
code = pb.ErrorCode_ConfigNoFound
log.Errorf("rdtask_side %v no found", req.RtaskSubId)
return
}
if len(sideConf.EndTid) == 0 {
code = pb.ErrorCode_ConfigurationException
return
}
// 没有设置选项,表示任务完成
if sideConf.EndTid[0] == -1 && len(sideConf.ChooseId) == 0 {
frtaskArr.RtaskIds = append(frtaskArr.RtaskIds, req.RtaskId)
if rtask.FrtaskIds == nil {
rtask.FrtaskIds = make(map[int32]*pb.FrtaskIds)
}
rtask.FrtaskIds[conf.Group] = frtaskArr
update := map[string]interface{}{
"frtaskIds": rtask.FrtaskIds,
}
if err := this.moduleRtask.modelRtask.Change(session.GetUserId(), update); err != nil {
code = pb.ErrorCode_SystemError
return
}
if err := this.moduleRtask.modelRtask.updateUserRtaskId(session.GetUserId(), req.RtaskId); err != nil {
this.moduleRtask.Errorf("update rtaskId err: %v", err)
}
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeApply, &pb.RtaskApplyResp{
RtaskId: req.RtaskId,
}); err != nil {
code = pb.ErrorCode_SystemError
}
return
}

View File

@ -1,123 +0,0 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) BattleFinishCheck(session comm.IUserSession, req *pb.RtaskBattleFinishReq) (code pb.ErrorCode) {
if req.RtaskId == 0 || req.RtaskSubId == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) BattleFinish(session comm.IUserSession, req *pb.RtaskBattleFinishReq) (code pb.ErrorCode, data proto.Message) {
if code = this.BattleFinishCheck(session, req); code != pb.ErrorCode_Success {
return
}
this.moduleRtask.Debugf("随机任务请求 rtaskID:%v 完成 subtaskID:%v chooseID:%v", req.RtaskId, req.RtaskSubId, req.ChooseId)
// 获取当前任务配置
conf := this.moduleRtask.configure.getRtaskById(req.RtaskId)
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
// 获取支线任务配置
sideConf := this.moduleRtask.configure.getRtaskSidById(req.RtaskSubId)
if sideConf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
// 获取玩家的任务
rtask := &pb.DBRtask{}
if err := this.moduleRtask.modelRtask.Get(session.GetUserId(), rtask); err != nil {
return
}
var (
frtaskArr *pb.FrtaskIds //完成的任务
ok bool
)
// 查找任务组
if frtaskArr, ok = rtask.FrtaskIds[conf.Group]; !ok {
frtaskArr = &pb.FrtaskIds{}
}
//验证该任务是否已完成
if _, ok := utils.Findx(frtaskArr.RtaskIds, req.RtaskId); ok {
code = pb.ErrorCode_RtaskFinished
return
}
// 校验完成条件
var checkCondi bool
for _, v := range sideConf.EndTid {
if err, ok := this.moduleRtask.modelRtask.checkCondi(session.GetUserId(), v); !ok {
if err != nil {
this.moduleRtask.Errorln(err.Error())
}
this.moduleRtask.Debugf("条件未达成 condiID:%v rtaskId:%v subRtaskId:%v chooseID:%v", v, req.RtaskId, req.RtaskSubId, req.ChooseId)
break
}
checkCondi = true
}
if !checkCondi {
code = pb.ErrorCode_RtaskCondiNoReach
return
}
// 更新完成的任务
frtaskArr.RtaskIds = append(frtaskArr.RtaskIds, req.RtaskId)
if rtask.FrtaskIds == nil {
rtask.FrtaskIds = make(map[int32]*pb.FrtaskIds)
}
rtask.FrtaskIds[conf.Group] = frtaskArr
update := map[string]interface{}{
"frtaskIds": rtask.FrtaskIds,
}
if err := this.moduleRtask.modelRtask.Change(session.GetUserId(), update); err != nil {
code = pb.ErrorCode_SystemError
return
}
// userexpand update
if err := this.moduleRtask.modelRtask.updateUserRtaskId(session.GetUserId(), req.RtaskId); err != nil {
this.moduleRtask.Errorf("update user rtaskId err %v", err)
}
// 发奖
for _, v := range sideConf.Reward {
if v.ChooseId == req.ChooseId {
this.moduleRtask.DispenseRes(session, v.Reward, true)
}
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeBattleFinish,
&pb.RtaskBattleFinishResp{
RtaskId: req.RtaskId,
RtaskSubId: req.RtaskSubId,
}); err != nil {
code = pb.ErrorCode_SystemError
}
rsp := &pb.RtaskFinishPush{
RtaskId: req.RtaskId,
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), "finish", rsp); err != nil {
code = pb.ErrorCode_SystemError
}
this.moduleRtask.Debugf("随机任务完成 rtaskID:%v subtaskID:%v chooseID:%v", req.RtaskId, req.RtaskSubId, req.ChooseId)
return
}

View File

@ -1,73 +0,0 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) BattleStartCheck(session comm.IUserSession, req *pb.RtaskBattleStartReq) (code pb.ErrorCode) {
if req.BattleConfId == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) BattleStart(session comm.IUserSession, req *pb.RtaskBattleStartReq) (code pb.ErrorCode, data proto.Message) {
if code = this.BattleStartCheck(session, req); code != pb.ErrorCode_Success {
return
}
battleConf := this.moduleRtask.configure.getRtaskBattleById(req.BattleConfId)
if battleConf == nil {
code = pb.ErrorCode_ConfigNoFound
log.Errorf("rdtask_battle %v no found", req.BattleConfId)
return
}
iBattle, err := this.moduleRtask.modelRtask.service.GetModule(comm.ModuleBattle)
if err != nil {
code = pb.ErrorCode_SystemError
return
}
if b, y := iBattle.(comm.IBattle); y {
var (
record *pb.DBBattleRecord
resp *pb.RtaskBattleStartResp
)
code, record = b.CreatePveBattle(session, &pb.BattlePVEReq{
Ptype: pb.PlayType_rtask,
Format: &pb.BattleFormation{
Leadpos: req.Leadpos,
Format: req.Teamids,
},
Mformat: battleConf.FormatList,
})
if code != pb.ErrorCode_Success {
return
}
if record != nil {
resp = &pb.RtaskBattleStartResp{
Info: &pb.BattleInfo{
Id: record.Id,
Btype: record.Btype,
Ptype: record.Ptype,
RedCompId: record.RedCompId,
Redflist: record.Redflist,
BlueCompId: record.BlueCompId,
Buleflist: record.Buleflist,
},
}
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeBattleStart, resp); err != nil {
code = pb.ErrorCode_SystemError
}
}
return
}

View File

@ -1,31 +0,0 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) ChooseCheck(session comm.IUserSession, req *pb.RtaskChooseReq) (code pb.ErrorCode) {
if req.ChooseId == 0 || req.RtaskId == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
// Deprecated: Use
func (this *apiComp) Choose(session comm.IUserSession, req *pb.RtaskChooseReq) (code pb.ErrorCode, data proto.Message) {
if code = this.ChooseCheck(session, req); code != pb.ErrorCode_Success {
return
}
rsp := &pb.RtaskChooseResp{
RtaskId: req.RtaskId,
ChooseId: req.ChooseId,
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeChoose, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}

View File

@ -1,39 +0,0 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) ListCheck(session comm.IUserSession, req *pb.RtasklistReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) List(session comm.IUserSession, req *pb.RtasklistReq) (code pb.ErrorCode, data proto.Message) {
// 获取当前玩家随机任务
rtask := this.moduleRtask.modelRtask.GetRtask(session.GetUserId())
if rtask == nil {
code = pb.ErrorCode_RtaskNoRtask
return
}
ids := make([]int32, 0)
// 查询分组ID对应的任务
if v, ok := rtask.FrtaskIds[req.GroupId]; ok {
ids = v.RtaskIds
}
rsp := &pb.RtasklistResp{
RtaskIds: ids,
GroupId: req.GroupId,
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeList, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}

View File

@ -1,71 +0,0 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) GetRewardCheck(session comm.IUserSession, req *pb.RtaskGetRewardReq) (code pb.ErrorCode) {
if req.RtaskId == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) GetReward(session comm.IUserSession, req *pb.RtaskGetRewardReq) (code pb.ErrorCode, data proto.Message) {
if code = this.GetRewardCheck(session, req); code != pb.ErrorCode_Success {
return
}
// 获取支线任务配置
sideConf := this.moduleRtask.configure.getRtaskSidById(req.RtaskSubId)
if sideConf == nil {
code = pb.ErrorCode_ConfigNoFound
this.moduleRtask.Errorf("uid:%v rdtask_side:%v config no found", session.GetUserId(), req.RtaskSubId)
return
}
//校验是否最后一个任务
if sideConf.NextTid != 0 {
code = pb.ErrorCode_RtaskNoLastOne
return
}
// 获取当前玩家
rtask := this.moduleRtask.modelRtask.GetRtask(session.GetUserId())
if rtask == nil {
code = pb.ErrorCode_RtaskNoRtask
return
}
// 是否已领取奖励
if rtask.IsReward {
code = pb.ErrorCode_RtaskRewarded
return
}
//发奖励
for _, v := range sideConf.Reward {
code = this.moduleRtask.DispenseRes(session, v.Reward, true)
this.moduleRtask.Infof("uid:%v 发奖励:%v code:%v", session.GetUserId(), v.Reward, code)
}
// 更新奖励领取状态
update := map[string]interface{}{
"isReward": true,
}
if err := this.moduleRtask.modelRtask.Change(session.GetUserId(), update); err != nil {
code = pb.ErrorCode_SystemError
return
}
rsp := &pb.RtaskGetRewardResp{
RtaskId: req.RtaskId,
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeReward, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}

View File

@ -8,11 +8,7 @@ import (
)
const (
gameRtask = "game_rdtask.json"
gameRtaskChoose = "game_rdtaskchoose.json"
gameTaskCond = "game_rdtaskcondi.json"
gameRtaskSide = "game_rdtaskside.json"
gameRtaskBattle = "game_rdtaskbattle.json"
)
type configureComp struct {
@ -22,31 +18,11 @@ type configureComp struct {
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MCompConfigure.Init(service, module, comp, options)
err = this.LoadMultiConfigure(map[string]interface{}{
gameRtask: cfg.NewGameRdtask,
gameRtaskChoose: cfg.NewGameRdtaskChoose,
gameTaskCond: cfg.NewGameRdtaskCondi,
gameRtaskSide: cfg.NewGameRdtaskSide,
gameRtaskBattle: cfg.NewGameRdtaskBattle,
})
return
}
func (this *configureComp) getRtaskCfg() (data *cfg.GameRdtask, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(gameRtask); err != nil {
return
} else {
if data, ok = v.(*cfg.GameRdtask); !ok {
err = fmt.Errorf("%T no is *cfg.GameRdtaskAll", v)
return
}
}
return
}
func (this *configureComp) getRtaskCondiCfg() (data *cfg.GameRdtaskCondi, err error) {
var (
v interface{}
@ -63,78 +39,6 @@ func (this *configureComp) getRtaskCondiCfg() (data *cfg.GameRdtaskCondi, err er
return
}
func (this *configureComp) getRtaskChoose() (data *cfg.GameRdtaskChoose, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(gameRtaskChoose); err != nil {
return
} else {
if data, ok = v.(*cfg.GameRdtaskChoose); !ok {
err = fmt.Errorf("%T is *cfg.getRtaskChoose", v)
return
}
}
return
}
func (this *configureComp) getRtaskSide() (data *cfg.GameRdtaskSide, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(gameRtaskSide); err != nil {
return
} else {
if data, ok = v.(*cfg.GameRdtaskSide); !ok {
err = fmt.Errorf("%T is *cfg.GameRdtaskSide", v)
return
}
}
return
}
func (this *configureComp) getRtaskBattle() (data *cfg.GameRdtaskBattle, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(gameRtaskBattle); err != nil {
return
} else {
if data, ok = v.(*cfg.GameRdtaskBattle); !ok {
err = fmt.Errorf("%T is *cfg.GameRdtaskBattle", v)
return
}
}
return
}
// 获取选项配置
func (this *configureComp) getRtaskChooseCfg(id int32) *cfg.GameRdtaskChooseData {
cfg, err := this.getRtaskChoose()
if err != nil {
return nil
}
if data, ok := cfg.GetDataMap()[id]; ok {
return data
}
return nil
}
func (this *configureComp) getRtaskSidById(id int32) *cfg.GameRdtaskSideData {
cfg, err := this.getRtaskSide()
if err != nil {
return nil
}
if data, ok := cfg.GetDataMap()[id]; ok {
return data
}
return nil
}
// 查询任务类型
func (this *configureComp) getRtaskTypeById(typeId int32) (data *cfg.GameRdtaskCondiData, err error) {
@ -165,30 +69,3 @@ func (this *configureComp) getRtaskCondis(typeId int32) (list []*cfg.GameRdtaskC
return
}
// 任务
func (this *configureComp) getRtaskById(taskId int32) (data *cfg.GameRdtaskData) {
cfg, err := this.getRtaskCfg()
if err != nil {
return
}
if cfg != nil {
if data, ok := cfg.GetDataMap()[taskId]; ok {
return data
}
}
return nil
}
// 战斗配置
func (this *configureComp) getRtaskBattleById(id int32) (data *cfg.GameRdtaskBattleData) {
cfg, err := this.getRtaskBattle()
if err != nil {
return
}
if cfg != nil {
if data, ok := cfg.GetDataMap()[id]; ok {
return data
}
}
return nil
}

View File

@ -87,7 +87,12 @@ func (this *ModelRtask) checkCondi(uid string, condiId int32) (err error, ok boo
errors.Errorf("condiID: %v", condiId)
return
}
if ok, err = condi.verify(uid, condi.cfg); !ok {
conf, err:= this.moduleRtask.configure.getRtaskTypeById(condiId)
if err!= nil {
errors.Errorf("conf not found condiID: %v", condiId)
return
}
if ok, err = condi.verify(uid, conf); !ok {
err = errors.WithMessagef(err, "uid: %v do rtask [condiId:%v] condition not reach", uid, condiId)
return
}

View File

@ -15,7 +15,6 @@ import (
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
"go_dreamfactory/utils"
"sort"
"github.com/pkg/errors"
)
@ -24,7 +23,7 @@ var _ comm.IRtask = (*ModuleRtask)(nil)
// 限定条件
type rtaskCondi struct {
cfg *cfg.GameRdtaskCondiData
condId int32 //任务条件配置ID
verify verifyHandle //校验任务条件
find condiFindHandle //检索任务条件
update updateDataHandle //更新任务数据
@ -94,77 +93,66 @@ func (this *ModuleRtask) initRtaskVerifyHandle() {
switch comm.TaskType(typeCfg.Type) {
case comm.Rtype1:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verfiyRtype1,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype2:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype2,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype3:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype3,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype4:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype4,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype5:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype5,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype6:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype6,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype8:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verfiyRtype8,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype9:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verfiyRtype9,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype10:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verfiyRtype10,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype11, comm.Rtype84, comm.Rtype85:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.lessEqualFirstParam,
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype18:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.greatEqualFirstParam,
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
update: this.modelRtaskRecord.addUpdate,
@ -177,35 +165,30 @@ func (this *ModuleRtask) initRtaskVerifyHandle() {
comm.Rtype62, comm.Rtype64, comm.Rtype69, comm.Rtype72, comm.Rtype88, comm.Rtype104,
comm.Rtype96, comm.Rtype105, comm.Rtype128, comm.Rtype130, comm.Rtype131:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.lessEqualFirstParam,
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
update: this.modelRtaskRecord.addUpdate,
})
case comm.Rtype20:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype20,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype22, comm.Rtype109:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtaskRecord.verifyFirstEqualParam,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype63:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
verify: this.modelRtask.verifyRtype63,
})
case comm.Rtype16, comm.Rtype17,
comm.Rtype35, comm.Rtype44,
comm.Rtype59, comm.Rtype61, comm.Rtype70:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.equalParams,
verify: this.modelRtaskRecord.verifyFromDb,
update: this.modelRtaskRecord.overrideUpdate,
@ -218,7 +201,6 @@ func (this *ModuleRtask) initRtaskVerifyHandle() {
comm.Rtype52, comm.Rtype55, comm.Rtype56,
comm.Rtype65, comm.Rtype66, comm.Rtype67, comm.Rtype68, comm.Rtype140:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.lessThanParams,
verify: this.modelRtaskRecord.verifyFromDb,
update: this.modelRtaskRecord.addUpdate,
@ -255,24 +237,25 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
condis []*rtaskCondi
)
for _, codi := range this.configure.getRtaskCondis(int32(rtaskType)) {
v, ok := this.handleMap[codi.Id]
for _, codiConf := range this.configure.getRtaskCondis(int32(rtaskType)) {
v, ok := this.handleMap[codiConf.Id]
if !ok {
this.Warn("未注册事件处理器", log.Fields{"uid": uid, "condiId": codi.Id})
this.Warn("未注册事件处理器", log.Fields{"uid": uid, "condiId": codiConf.Id})
code = pb.ErrorCode_RtaskCondiNoFound
return
}
if v.find == nil {
this.Warn("未设置find Handle", log.Fields{"uid": uid, "condiId": codi.Id})
this.Warn("未设置find Handle", log.Fields{"uid": uid, "condiId": codiConf.Id})
return
}
if condiId, err = v.find(v.cfg, params...); condiId == 0 {
if condiId, err = v.find(codiConf, params...); condiId == 0 {
if err != nil {
this.Warnln(errors.WithMessage(err, uid).Error())
}
} else {
v.condId = codiConf.Id
condis = append(condis, v)
}
@ -280,18 +263,25 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
// update
for _, v := range condis {
conf, err:= this.configure.getRtaskTypeById(v.condId)
if err!= nil {
this.Errorln(err)
code = pb.ErrorCode_RtaskCondiNoFound
return
}
if v.update != nil {
if err := v.update(uid, v.cfg, params...); err != nil {
if err := v.update(uid, conf, params...); err != nil {
code = pb.ErrorCode_DBError
}
}
//任务完成则推送
if code := this.CheckCondi(uid, v.cfg.Id); code == pb.ErrorCode_Success {
if code := this.CheckCondi(uid, conf.Id); code == pb.ErrorCode_Success {
module, err := this.service.GetModule(comm.ModuleWorldtask)
if err == nil {
if worldtask, ok := module.(comm.IWorldtask); ok {
if err := worldtask.TaskcondNotify(session, v.cfg.Id); err != nil {
if err := worldtask.TaskcondNotify(session, conf.Id); err != nil {
var customErr = new(comm.CustomError)
if errors.As(err, &customErr) {
notifyErr := &pb.NotifyErrorNotifyPush{
@ -307,7 +297,7 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
notifyErr.Code = pb.ErrorCode_UserSessionNobeing
session.SendMsg(string(comm.ModuleWorldtask), "finish", notifyErr)
} else {
log.Error("任务条件达成通知", log.Fields{"uid": uid, "condId": v.cfg.Id, "err": err.Error()})
log.Error("任务条件达成通知", log.Fields{"uid": uid, "condId": conf.Id, "err": err.Error()})
}
}
}
@ -335,75 +325,11 @@ func (this *ModuleRtask) RemoveCondi(uid string, condiId int32) (err error) {
return
}
// 初始化任务条件数据
// Deprecated
func (this *ModuleRtask) InitCondiData(uid string) error {
return this.modelRtaskRecord.initCondiData(uid)
}
// 获取玩家任务条件记录
func (this *ModuleRtask) GetCondiData(uid string) *pb.DBRtaskRecord {
return this.modelRtaskRecord.getRecord(uid)
}
// Bingo命令更新随机任务
func (this *ModuleRtask) BingoRtask(session comm.IUserSession, groupId, rtaskId int32) error {
rtask := &pb.DBRtask{}
if err := this.modelRtask.Get(session.GetUserId(), rtask); err != nil {
return err
}
var (
frtaskArr *pb.FrtaskIds //完成的任务
ok bool
)
// 查找任务组
if frtaskArr, ok = rtask.FrtaskIds[groupId]; !ok {
frtaskArr = &pb.FrtaskIds{}
}
gr, err := this.configure.getRtaskCfg()
if err != nil {
return err
}
var rgs []*cfg.GameRdtaskData
for _, v := range gr.GetDataList() {
if v.Group == groupId {
rgs = append(rgs, v)
}
}
sort.SliceStable(rgs, func(i, j int) bool {
return rgs[i].Id < rgs[j].Id
})
for _, v := range rgs {
if v.Id <= rtaskId {
if _, ok := utils.Findx(frtaskArr.RtaskIds, v.Id); !ok {
frtaskArr.RtaskIds = append(frtaskArr.RtaskIds, v.Id)
}
}
}
if rtask.FrtaskIds == nil {
rtask.FrtaskIds = make(map[int32]*pb.FrtaskIds)
}
rtask.FrtaskIds[groupId] = frtaskArr
update := map[string]interface{}{
"frtaskIds": rtask.FrtaskIds,
}
if err := this.modelRtask.Change(session.GetUserId(), update); err != nil {
return err
}
if err := session.SendMsg(string(this.GetType()), "finishids",
&pb.RtaskFinishIdsPush{RtaskId: frtaskArr.RtaskIds, GroupId: groupId}); err != nil {
return err
}
return nil
}
// 远程条件校验
func (this *ModuleRtask) RemoteCheckCondi(uid string, condiId int32, rsp *pb.DBRtaskRecord) error {
if rsp == nil {

View File

@ -7,6 +7,8 @@ import (
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type ModelTaskActive struct {
@ -18,6 +20,10 @@ func (this *ModelTaskActive) Init(service core.IService, module core.IModule, co
this.TableName = comm.TableTaskActive
err = this.MCompModel.Init(service, module, comp, options)
this.moduleTask = module.(*ModuleTask)
// 加索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
@ -62,7 +68,7 @@ func (this *ModelTaskActive) noReceiveTaskActive(uid string, taskTag comm.TaskTa
list := []*pb.DBTaskActive{}
if err := this.GetList(uid, &list); err != nil {
this.moduleTask.Errorf("getUserActiveList err:%v", err)
return false,err
return false, err
}
for _, v := range list {
if v.Tag == int32(taskTag) && v.Received == 0 {

View File

@ -12,6 +12,8 @@ import (
"github.com/pkg/errors"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type ModelTask struct {
@ -26,6 +28,9 @@ func (this *ModelTask) Init(service core.IService, module core.IModule, comp cor
this.moduleTask = module.(*ModuleTask)
this.EventApp = event_v2.NewApp()
this.EventApp.Listen(comm.EventTaskChanged, this.doTaskHandle)
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}

View File

@ -10,6 +10,7 @@ import (
"go_dreamfactory/utils"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
// 记录一些扩展数据
@ -22,6 +23,9 @@ func (this *ModelExpand) Init(service core.IService, module core.IModule, comp c
this.TableName = comm.TableUserExpand
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*User)
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
@ -35,7 +39,7 @@ func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err
} else {
if err = model.Get(uid, result); err != nil && mongo.ErrNoDocuments != err {
this.module.Error("Cross Get", log.Fields{"uid": uid})
return result,err
return result, err
}
}
} else {

View File

@ -12,6 +12,8 @@ import (
"time"
"github.com/spf13/cast"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type ModelSetting struct {
@ -23,6 +25,9 @@ func (this *ModelSetting) Init(service core.IService, module core.IModule, comp
this.TableName = comm.TableSetting
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*User)
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}

View File

@ -11,6 +11,7 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
// 签到
@ -23,6 +24,9 @@ func (this *ModelSign) Init(service core.IService, module core.IModule, comp cor
this.TableName = comm.TableSign
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*User)
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}

View File

@ -17,6 +17,7 @@ import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type ModelUser struct {
@ -32,6 +33,14 @@ func (this *ModelUser) Init(service core.IService, module core.IModule, comp cor
this.EventApp = event_v2.NewApp()
this.EventApp.Listen(comm.EventUserChanged, this.ChangeExp)
this.EventApp.Listen(comm.EventUserChanged, this.ChangeLevel)
// 通过uid创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "name", Value: bsonx.Int32(1)}},
})
return
}
@ -113,7 +122,7 @@ func (this *ModelUser) updateUserAttr(uid string, data map[string]interface{}) e
func (this *ModelUser) isLoginFirst(timestamp int64) bool {
now := configure.Now()
if timestamp == 0 || timestamp > now.Unix() {
this.module.Debugf("lastlogin time great now")
//this.module.Debugf("lastlogin time great now")
return false
}
tt := time.Unix(timestamp, 0)

View File

@ -2,16 +2,15 @@ package robot
import (
"bytes"
"crypto/rand"
"encoding/json"
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"io"
"math/big"
"math/rand"
"os"
"strconv"
"go_dreamfactory/pb"
"time"
"github.com/gorilla/websocket"
"github.com/sirupsen/logrus"
@ -203,6 +202,13 @@ func (r *Robot) MessageRsp(mainType, subType string) (bool, int64) {
return false, byteLen
}
//fmt.Printf("接收消息=====loginData:%v,userExpand:%v\n", resp.Data, resp.Ex)
return true, byteLen
} else if msg.MainType == "goutmet" && msg.SubType == "getranduser" {
resp := &pb.GourmetGetRandUserResp{}
if !comm.ProtoUnmarshal(msg, resp) {
return false, byteLen
}
return true, byteLen
}
return false, byteLen
@ -235,13 +241,38 @@ func (r *Robot) Login() error {
return nil
}
func (r Robot) GetRandUser() bool {
mainType := "goutmet"
subType := "getlist"
msg := &pb.UserMessage{MainType: mainType, SubType: subType}
rsp := &pb.GourmetGetRandUserReq{
People: 3,
}
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 i := 0; i < 100; i++ {
if b, _ := r.MessageRsp(mainType, subType); b {
return true
}
}
return true
}
func (r *Robot) Create() bool {
mainType := "user"
subType := "create"
msg := &pb.UserMessage{MainType: mainType, SubType: subType}
n2, _ := rand.Int(rand.Reader, big.NewInt(1000000))
rand.Seed(time.Now().UnixNano())
n2 := rand.Int63n(9000000)
name := strconv.Itoa(int(n2.Int64() + 100000))
name := strconv.Itoa(int(n2) + 100000)
rsp := &pb.UserCreateReq{
NickName: name,
Figure: 100,
@ -256,10 +287,70 @@ func (r *Robot) Create() bool {
}
}
for {
for i := 0; i < 100; i++ { // 防止丢包
if b, _ := r.MessageRsp(mainType, subType); b {
return true
}
}
return false
}
// 获取美食家信息列表数据
func (r Robot) GetGourmetList() int64 {
var byteLen int64
mainType := "goutmet"
subType := "getranduser"
msg := &pb.UserMessage{MainType: mainType, SubType: subType}
rsp := &pb.GourmetGetRandUserReq{
People: 3,
}
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 i := 0; i < 100; i++ {
var msg *pb.UserMessage = &pb.UserMessage{}
_, data, err := r.ws.ReadMessage()
if err != nil {
fmt.Printf("readMessage err:%v", err)
continue
}
byteLen += int64(len(data))
if err = proto.Unmarshal(data, msg); err != nil {
fmt.Printf("unmarshal err:%v", err)
}
if msg.MainType == "goutmet" && msg.SubType == "getlist" {
resp := &pb.GourmetGetListResp{}
if !comm.ProtoUnmarshal(msg, resp) { //反序列化失败
break
}
break
}
}
return byteLen
}
// addItem
func (r Robot) AddGrormetItem() {
mainType := "gm"
subType := "cmd"
msg := &pb.UserMessage{MainType: mainType, SubType: subType}
rsp := &pb.GMCmdReq{
Cmod: "bingo:item,50001,100",
}
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)
}
}
}

View File

@ -23,7 +23,7 @@ var (
)
func init() {
keepAlive = true
keepAlive = false
}
// WebSocket webSocket go link
@ -61,6 +61,8 @@ end:
// 保持连接
chWaitFor := make(chan int, 0)
<-chWaitFor
//time.Sleep(15 * time.Millisecond)
//return
}
return
}
@ -69,7 +71,6 @@ end:
func webSocketRequest(chanID uint64, ch chan<- *model.RequestResults, i uint64, request *model.Request,
r *robot.Robot) {
var (
startTime = time.Now()
isSucceed = false
errCode = model.HTTPOk
byteLen int64 // 协议传输字节数
@ -78,16 +79,20 @@ func webSocketRequest(chanID uint64, ch chan<- *model.RequestResults, i uint64,
head := &pb.UserMessage{MainType: "user", SubType: "login"}
r.SendToClient(head, &pb.UserLoginReq{})
for {
if b, len := r.MessageRsp("user", "login"); b {
byteLen += len
isSucceed = true
//errCode, isSucceed = request.GetVerifyWebSocket()(request, "webSocket.pb", r.GetMessagedata())
break
}
}
r.Create()
// 美食馆增加道具
r.AddGrormetItem()
// for {
// if b, len := r.MessageRsp("user", "login"); b {
// byteLen += len
// isSucceed = true
// //errCode, isSucceed = request.GetVerifyWebSocket()(request, "webSocket.pb", r.GetMessagedata())
// break
// }
// }
// r.Create()
startTime := time.Now()
// r.GetRandUser() // 获取随机在线玩家数据
byteLen = r.GetGourmetList()
requestTime := uint64(helper.DiffNano(startTime))
requestResults := &model.RequestResults{
ID: "",

View File

@ -52,7 +52,7 @@ func InitLog() {
if err := log.OnInit(op.Setting.Sys["log"]); err != nil {
panic(fmt.Sprintf("Sys log Init err:%v", err))
} else {
log.Infof("ddddd Sys log Init success !")
log.Infof("stress Sys log Init success !")
}
}
@ -71,6 +71,7 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy
requestTime uint64 // 请求总时间
maxTime uint64 // 最大时长
minTime uint64 // 最小时长
curTime uint64 // 当前消耗时常
successNum uint64 // 成功处理数code为0
failureNum uint64 // 处理失败数code不为0 0
chanIDLen int // 并发数
@ -90,8 +91,9 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy
endTime := uint64(time.Now().UnixNano())
mutex.Lock()
go calculateData(concurrent, processingTime, endTime-statTime, maxTime, minTime, successNum, failureNum,
chanIDLen, errCode, receivedBytes)
chanIDLen, errCode, receivedBytes, curTime)
mutex.Unlock()
case <-stopChan:
// 处理完成
return
@ -102,6 +104,7 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy
for data := range ch {
mutex.Lock()
// fmt.Println("处理一条数据", data.ID, data.Time, data.IsSucceed, data.ErrCode)
curTime = data.Time
processingTime = processingTime + data.Time
if maxTime <= data.Time {
maxTime = data.Time
@ -131,22 +134,21 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy
}
requestTimeList = append(requestTimeList, data.Time)
mutex.Unlock()
}
// 数据全部接受完成,停止定时输出统计数据
stopChan <- true
endTime := uint64(time.Now().UnixNano())
requestTime = endTime - statTime
calculateData(concurrent, processingTime, requestTime, maxTime, minTime, successNum, failureNum, chanIDLen, errCode,
receivedBytes)
receivedBytes, curTime)
log.Infof("\n\n")
log.Infof("************************* 结果 stat ****************************")
log.Infof("处理协程数量:", concurrent)
log.Infof("处理协程数量:%d", concurrent)
// fmt.Println("处理协程数量:", concurrent, "程序处理总时长:", log("%.3f", float64(processingTime/concurrent)/1e9), "秒")
log.Infof("请求总数(并发数*请求数 -c * -n):", successNum+failureNum, "总请求时间:",
fmt.Sprintf("%.3f", float64(requestTime)/1e9),
"秒", "successNum:", successNum, "failureNum:", failureNum)
log.Infof(fmt.Sprintf("请求总数(并发数*请求数 -c * -n):%d, 总请求时间:%s,秒, successNum:%d,failureNum:%d", successNum+failureNum, fmt.Sprintf("%.3f", float64(requestTime)/1e9), successNum, failureNum))
printTop(requestTimeList)
log.Infof("************************* 结果 end ****************************")
log.Infof("\n\n")
@ -160,15 +162,15 @@ func printTop(requestTimeList []uint64) {
all := tools.MyUint64List{}
all = requestTimeList
sort.Sort(all)
log.Infof("tp90:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.90)]/1e6)))
log.Infof("tp95:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.95)]/1e6)))
log.Infof("tp99:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.99)]/1e6)))
// log.Infof("tp90:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.90)]/1e6)))
// log.Infof("tp95:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.95)]/1e6)))
// log.Infof("tp99:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.99)]/1e6)))
}
// calculateData 计算数据
func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, successNum, failureNum uint64,
chanIDLen int, errCode *sync.Map, receivedBytes int64) {
chanIDLen int, errCode *sync.Map, receivedBytes int64, curTime uint64) {
if processingTime == 0 {
processingTime = 1
}
@ -190,7 +192,7 @@ func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, su
// 纳秒=>毫秒
maxTimeFloat = float64(maxTime) / 1e6
minTimeFloat = float64(minTime) / 1e6
requestTimeFloat = float64(requestTime) / 1e9
requestTimeFloat = float64(curTime) / 1e6 // float64(requestTime) / 1e9
// 打印的时长都为毫秒
table(successNum, failureNum, errCode, qps, averageTime, maxTimeFloat, minTimeFloat, requestTimeFloat, chanIDLen,
receivedBytes)
@ -200,10 +202,11 @@ func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, su
func header() {
log.Infof("\n\n")
// 打印的时长都为毫秒 总请数
log.Infof("─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────┬────────┬────────")
log.Infof(" 耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│下载字节│字节每秒│ 状态码")
log.Infof("─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────┼────────┼────────")
log.Infof(" ─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────┬────────┬────────")
log.Infof(" 耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时 │最短耗时│平均耗时│下载字节│字节每秒 │ 状态码")
log.Infof(" ─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────┼────────┼────────")
return
}
// table 打印表格
@ -212,8 +215,8 @@ func table(successNum, failureNum uint64, errCode *sync.Map,
var (
speed int64
)
if requestTimeFloat > 0 {
speed = int64(float64(receivedBytes) / requestTimeFloat)
if averageTime > 0 {
speed = int64(float64(receivedBytes) / averageTime * 1e6 / 8 / 1024)
} else {
speed = 0
}

View File

@ -9,12 +9,8 @@ import (
"go_dreamfactory/stress/model"
"go_dreamfactory/stress/server"
"go_dreamfactory/stress/server/statistics"
"io/ioutil"
"runtime"
"strings"
"time"
"gopkg.in/yaml.v2"
)
// array 自定义数组参数
@ -77,37 +73,16 @@ type Options struct {
Setting core.ServiceSttings //服务参数配置
}
func newOptions(path string) *Options {
options := &Options{}
yamlFile, err := ioutil.ReadFile(path)
if err != nil {
panic(fmt.Sprintf("读取服务配置【%s】文件失败err:%v:", options.ConfPath, err))
}
err = yaml.Unmarshal(yamlFile, &options.Setting)
if err != nil {
panic(fmt.Sprintf("读取服务配置【%s】文件失败err:%v:", options.ConfPath, err))
}
return options
}
//go:generate go build main.go
func main() {
runtime.GOMAXPROCS(cpuNumber)
//runtime.GOMAXPROCS(cpuNumber)
flag.Parse()
statistics.InitLog()
// op := newOptions("./conf/stress_1.yaml")
// if err := log.OnInit(op.Setting.Sys["log"]); err != nil {
// panic(fmt.Sprintf("Sys log Init err:%v", err))
// } else {
// log.Infof("Sys log Init success !")
// }
// log.Debugf("ddddd")
//go run .\main.go -c 10 -n 10 -u ws://10.0.5.101:7891/gateway
concurrency = 1
concurrency = 12
totalNumber = 1
debugStr = "false"
requestURL = "ws://10.0.0.9:7891/gateway"
requestURL = "ws://10.0.0.85:7891/gateway"
verify = "pb"
if concurrency == 0 || totalNumber == 0 || (requestURL == "" && path == "") {
fmt.Printf("示例: go run main.go -c 1 -n 1 -u https://www.baidu.com/ \n")

View File

@ -0,0 +1,42 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
package cfg
type GameTestFlow struct {
_dataMap map[int32]*GameTestFlowData
_dataList []*GameTestFlowData
}
func NewGameTestFlow(_buf []map[string]interface{}) (*GameTestFlow, error) {
_dataList := make([]*GameTestFlowData, 0, len(_buf))
dataMap := make(map[int32]*GameTestFlowData)
for _, _ele_ := range _buf {
if _v, err2 := DeserializeGameTestFlowData(_ele_); err2 != nil {
return nil, err2
} else {
_dataList = append(_dataList, _v)
dataMap[_v.Id] = _v
}
}
return &GameTestFlow{_dataList:_dataList, _dataMap:dataMap}, nil
}
func (table *GameTestFlow) GetDataMap() map[int32]*GameTestFlowData {
return table._dataMap
}
func (table *GameTestFlow) GetDataList() []*GameTestFlowData {
return table._dataList
}
func (table *GameTestFlow) Get(key int32) *GameTestFlowData {
return table._dataMap[key]
}

View File

@ -0,0 +1,41 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
package cfg
import "errors"
type GameTestFlowData struct {
Id int32
Msg string
Route string
Params string
}
const TypeId_GameTestFlowData = -1087831770
func (*GameTestFlowData) GetTypeId() int32 {
return -1087831770
}
func (_v *GameTestFlowData)Deserialize(_buf map[string]interface{}) (err error) {
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["id"].(float64); !_ok_ { err = errors.New("id error"); return }; _v.Id = int32(_tempNum_) }
{ var _ok_ bool; if _v.Msg, _ok_ = _buf["msg"].(string); !_ok_ { err = errors.New("msg error"); return } }
{ var _ok_ bool; if _v.Route, _ok_ = _buf["route"].(string); !_ok_ { err = errors.New("route error"); return } }
{ var _ok_ bool; if _v.Params, _ok_ = _buf["params"].(string); !_ok_ { err = errors.New("params error"); return } }
return
}
func DeserializeGameTestFlowData(_buf map[string]interface{}) (*GameTestFlowData, error) {
v := &GameTestFlowData{}
if err := v.Deserialize(_buf); err == nil {
return v, nil
} else {
return nil, err
}
}

View File

@ -58,17 +58,14 @@ type Tables struct {
Playerlv *GamePlayerlv
Facemod *GameFacemod
Msgdistrib *GameMsgdistrib
TestFlow *GameTestFlow
Opencond *GameOpencond
Stroy *GameStroy
Pagoda *GamePagoda
PagodaTaskReward *GamePagodaTaskReward
SeasonLoop *GameSeasonLoop
PagodaSeasonReward *GamePagodaSeasonReward
Rdtask *GameRdtask
RdtaskCondi *GameRdtaskCondi
RdtaskChoose *GameRdtaskChoose
RdtaskSide *GameRdtaskSide
RdtaskBattle *GameRdtaskBattle
KungfuUnlock *GameKungfuUnlock
KungfuMasterworker *GameKungfuMasterworker
Gourmet *GameGourmet
@ -135,8 +132,6 @@ type Tables struct {
PrivilegeCard *GamePrivilegeCard
Privilege *GamePrivilege
WorldTask *GameWorldTask
TaskCond *GameTaskCond
TaskType *GameTaskType
Teaching *GameTeaching
HeroStrategy *GameHeroStrategy
FightGlobalEvent *GameFightGlobalEvent
@ -440,6 +435,12 @@ func NewTables(loader JsonLoader) (*Tables, error) {
if tables.Msgdistrib, err = NewGameMsgdistrib(buf) ; err != nil {
return nil, err
}
if buf, err = loader("game_testflow") ; err != nil {
return nil, err
}
if tables.TestFlow, err = NewGameTestFlow(buf) ; err != nil {
return nil, err
}
if buf, err = loader("game_opencond") ; err != nil {
return nil, err
}
@ -476,36 +477,12 @@ func NewTables(loader JsonLoader) (*Tables, error) {
if tables.PagodaSeasonReward, err = NewGamePagodaSeasonReward(buf) ; err != nil {
return nil, err
}
if buf, err = loader("game_rdtask") ; err != nil {
return nil, err
}
if tables.Rdtask, err = NewGameRdtask(buf) ; err != nil {
return nil, err
}
if buf, err = loader("game_rdtaskcondi") ; err != nil {
return nil, err
}
if tables.RdtaskCondi, err = NewGameRdtaskCondi(buf) ; err != nil {
return nil, err
}
if buf, err = loader("game_rdtaskchoose") ; err != nil {
return nil, err
}
if tables.RdtaskChoose, err = NewGameRdtaskChoose(buf) ; err != nil {
return nil, err
}
if buf, err = loader("game_rdtaskside") ; err != nil {
return nil, err
}
if tables.RdtaskSide, err = NewGameRdtaskSide(buf) ; err != nil {
return nil, err
}
if buf, err = loader("game_rdtaskbattle") ; err != nil {
return nil, err
}
if tables.RdtaskBattle, err = NewGameRdtaskBattle(buf) ; err != nil {
return nil, err
}
if buf, err = loader("game_kungfuunlock") ; err != nil {
return nil, err
}
@ -902,18 +879,6 @@ func NewTables(loader JsonLoader) (*Tables, error) {
if tables.WorldTask, err = NewGameWorldTask(buf) ; err != nil {
return nil, err
}
if buf, err = loader("game_taskcond") ; err != nil {
return nil, err
}
if tables.TaskCond, err = NewGameTaskCond(buf) ; err != nil {
return nil, err
}
if buf, err = loader("game_tasktype") ; err != nil {
return nil, err
}
if tables.TaskType, err = NewGameTaskType(buf) ; err != nil {
return nil, err
}
if buf, err = loader("game_teaching") ; err != nil {
return nil, err
}