上传机器人代码

This commit is contained in:
liwei1dao 2023-12-20 16:52:18 +08:00
parent 02c5a0224b
commit 1d55ce2d9e
8 changed files with 325 additions and 16 deletions

View File

@ -0,0 +1,54 @@
package robot
import (
"errors"
"fmt"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
//用户模块 机器人
type ModuleRobot_Dailytask struct {
task []*pb.DBDailytaskGroupProgress
}
func (this *ModuleRobot_Dailytask) Init() (err error) {
return
}
//接收到消息
func (this *ModuleRobot_Dailytask) Receive(robot IRobot, stype string, message proto.Message) (err error) {
switch stype {
case "info":
resp := message.(*pb.DailytaskInfoResp)
this.task = resp.Task
break
}
return
}
func (this *ModuleRobot_Dailytask) OncePipeline(robot IRobot) (err error) {
var (
errdata *pb.ErrorData
)
if _, errdata = robot.SendMessage("dailytask", "info", &pb.DailytaskInfoReq{}); errdata != nil {
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
return
}
return
}
//机器人执行流
func (this *ModuleRobot_Dailytask) DoPipeline(robot IRobot) (err error) {
return
}
//做任务
func (this *ModuleRobot_Dailytask) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
return
}

View File

@ -0,0 +1,54 @@
package robot
import (
"errors"
"fmt"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
//用户模块 机器人
type ModuleRobot_Dragon struct {
dragons []*pb.DBDragon
}
func (this *ModuleRobot_Dragon) Init() (err error) {
return
}
//接收到消息
func (this *ModuleRobot_Dragon) Receive(robot IRobot, stype string, message proto.Message) (err error) {
switch stype {
case "getlist":
resp := message.(*pb.DragonGetListResp)
this.dragons = resp.Dragons
break
}
return
}
func (this *ModuleRobot_Dragon) OncePipeline(robot IRobot) (err error) {
var (
errdata *pb.ErrorData
)
if _, errdata = robot.SendMessage("dragon", "getlist", &pb.DragonGetListReq{}); errdata != nil {
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
return
}
return
}
//机器人执行流
func (this *ModuleRobot_Dragon) DoPipeline(robot IRobot) (err error) {
return
}
//做任务
func (this *ModuleRobot_Dragon) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
return
}

View File

@ -0,0 +1,54 @@
package robot
import (
"errors"
"fmt"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
//用户模块 机器人
type ModuleRobot_Integral struct {
boos *pb.DBIntegralBoss
}
func (this *ModuleRobot_Integral) Init() (err error) {
return
}
//接收到消息
func (this *ModuleRobot_Integral) Receive(robot IRobot, stype string, message proto.Message) (err error) {
switch stype {
case "getlist":
resp := message.(*pb.IntegralGetListResp)
this.boos = resp.Data
break
}
return
}
func (this *ModuleRobot_Integral) OncePipeline(robot IRobot) (err error) {
var (
errdata *pb.ErrorData
)
if _, errdata = robot.SendMessage("integral", "getlist", &pb.IntegralGetListReq{}); errdata != nil {
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
return
}
return
}
//机器人执行流
func (this *ModuleRobot_Integral) DoPipeline(robot IRobot) (err error) {
return
}
//做任务
func (this *ModuleRobot_Integral) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
return
}

View File

@ -0,0 +1,76 @@
package robot
import (
"errors"
"fmt"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
//用户模块 机器人
type ModuleRobot_Mail struct {
mails []*pb.DBMailData
}
func (this *ModuleRobot_Mail) Init() (err error) {
return
}
//接收到消息
func (this *ModuleRobot_Mail) Receive(robot IRobot, stype string, message proto.Message) (err error) {
switch stype {
case "getlist":
resp := message.(*pb.MailGetListResp)
this.mails = resp.Mails
break
case "getusermailattachment":
resp := message.(*pb.MailGetUserMailAttachmentResp)
for _, v := range this.mails {
if v.ObjId == resp.Mail.ObjId {
v.Reward = resp.Mail.Reward
break
}
}
break
}
return
}
func (this *ModuleRobot_Mail) OncePipeline(robot IRobot) (err error) {
var (
errdata *pb.ErrorData
)
if _, errdata = robot.SendMessage("mail", "getlist", &pb.MailGetListReq{}); errdata != nil {
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
return
}
return
}
//机器人执行流
func (this *ModuleRobot_Mail) DoPipeline(robot IRobot) (err error) {
var (
errdata *pb.ErrorData
)
for _, v := range this.mails {
if !v.Reward {
if _, errdata = robot.SendMessage("mail", "getusermailattachment", &pb.MailGetUserMailAttachmentReq{
ObjID: v.ObjId,
}); errdata != nil {
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
return
}
break
}
}
return
}
//做任务
func (this *ModuleRobot_Mail) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
return
}

View File

@ -0,0 +1,54 @@
package robot
import (
"errors"
"fmt"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
//用户模块 机器人
type ModuleRobot_Storyline struct {
info *pb.DBStoryline
}
func (this *ModuleRobot_Storyline) Init() (err error) {
return
}
//接收到消息
func (this *ModuleRobot_Storyline) Receive(robot IRobot, stype string, message proto.Message) (err error) {
switch stype {
case "info":
resp := message.(*pb.StorylineInfoResp)
this.info = resp.Info
break
}
return
}
func (this *ModuleRobot_Storyline) OncePipeline(robot IRobot) (err error) {
var (
errdata *pb.ErrorData
)
if _, errdata = robot.SendMessage("storyline", "info", &pb.StorylineInfoReq{}); errdata != nil {
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
return
}
return
}
//机器人执行流
func (this *ModuleRobot_Storyline) DoPipeline(robot IRobot) (err error) {
return
}
//做任务
func (this *ModuleRobot_Storyline) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
return
}

View File

@ -22,6 +22,7 @@ import (
type RobotStatistics struct { type RobotStatistics struct {
message string message string
time int64 time int64
reqsize int64
} }
type Robot struct { type Robot struct {
@ -85,6 +86,11 @@ func (this *Robot) Init(addr string, client IClient) (err error) {
this.modules[comm.ModuleSmithy] = new(ModuleRobot_Smithy) this.modules[comm.ModuleSmithy] = new(ModuleRobot_Smithy)
this.modules[comm.ModuleFriend] = new(ModuleRobot_Friend) this.modules[comm.ModuleFriend] = new(ModuleRobot_Friend)
this.modules[comm.ModulePasson] = new(ModuleRobot_Passon) this.modules[comm.ModulePasson] = new(ModuleRobot_Passon)
this.modules[comm.ModuleStoryLine] = new(ModuleRobot_Storyline)
this.modules[comm.ModuleDailytask] = new(ModuleRobot_Dailytask)
this.modules[comm.ModuleDragon] = new(ModuleRobot_Dragon)
this.modules[comm.ModuleIntegral] = new(ModuleRobot_Integral)
this.modules[comm.ModuleMail] = new(ModuleRobot_Mail)
for _, v := range this.modules { for _, v := range this.modules {
v.Init() v.Init()
@ -192,10 +198,10 @@ func (this *Robot) SendMessage(mtype, stype string, msg proto.Message) (resp pro
log.Error("[机器人 Message]", log.Field{Key: "t", Value: time.Since(stime).Milliseconds()}, log.Field{Key: "Account", Value: this.account}, log.Field{Key: "message", Value: fmt.Sprintf("%s.%s", mtype, stype)}, log.Field{Key: "errdata", Value: errdata.String()}) log.Error("[机器人 Message]", log.Field{Key: "t", Value: time.Since(stime).Milliseconds()}, log.Field{Key: "Account", Value: this.account}, log.Field{Key: "message", Value: fmt.Sprintf("%s.%s", mtype, stype)}, log.Field{Key: "errdata", Value: errdata.String()})
} }
} }
this.statistics = append(this.statistics, &RobotStatistics{ this.statistics = append(this.statistics, &RobotStatistics{
message: fmt.Sprintf("%s.%s", mtype, stype), message: fmt.Sprintf("%s.%s", mtype, stype),
time: time.Since(stime).Milliseconds(), time: time.Since(stime).Milliseconds(),
reqsize: int64(len(data.Value)),
}) })
time.Sleep(time.Millisecond * time.Duration(50+rand.Int31n(300))) time.Sleep(time.Millisecond * time.Duration(50+rand.Int31n(300)))
} else { } else {

View File

@ -81,10 +81,12 @@ func (this *statisticalComp) RobotFinishedTest(robot *Robot) {
//输出报表 //输出报表
func (this *statisticalComp) OutReport() { func (this *statisticalComp) OutReport() {
var ( var (
messages map[string][]int64 = make(map[string][]int64) messagestime map[string][]int64 = make(map[string][]int64)
requestsize map[string]int64 = make(map[string]int64)
receive map[string]int32 = make(map[string]int32) receive map[string]int32 = make(map[string]int32)
receiveSize map[string]int64 = make(map[string]int64) receiveSize map[string]int64 = make(map[string]int64)
totalmessage int32 totalmessage int32
totalrequestSize int64
totalreceive int32 totalreceive int32
totalreceiveSize int64 totalreceiveSize int64
ok bool ok bool
@ -93,10 +95,13 @@ func (this *statisticalComp) OutReport() {
for _, datas := range this.robotdata { for _, datas := range this.robotdata {
for _, v := range datas { for _, v := range datas {
totalmessage++ totalmessage++
if _, ok = messages[v.message]; !ok { if _, ok = messagestime[v.message]; !ok {
messages[v.message] = make([]int64, 0) messagestime[v.message] = make([]int64, 0)
} }
messages[v.message] = append(messages[v.message], v.time) messagestime[v.message] = append(messagestime[v.message], v.time)
requestsize[v.message] += v.reqsize
totalrequestSize += v.reqsize
} }
} }
for k, v := range this.receiveMsg { for k, v := range this.receiveMsg {
@ -118,15 +123,19 @@ func (this *statisticalComp) OutReport() {
file.WriteString(fmt.Sprintf("成功数量: %d\n", this.succclientNum)) file.WriteString(fmt.Sprintf("成功数量: %d\n", this.succclientNum))
file.WriteString(fmt.Sprintf("失败数量: %d\n", this.failclientNum)) file.WriteString(fmt.Sprintf("失败数量: %d\n", this.failclientNum))
file.WriteString(fmt.Sprintf("最大同时在线人数: %d\n", this.maxonlineNum)) file.WriteString(fmt.Sprintf("最大同时在线人数: %d\n", this.maxonlineNum))
file.WriteString(fmt.Sprintf("压测执行时长: %.2f秒\n", this.end.Sub(this.start).Seconds()))
file.WriteString(fmt.Sprintf("消息总请求数: %d\n", totalmessage)) file.WriteString(fmt.Sprintf("消息总请求数: %d\n", totalmessage))
file.WriteString(fmt.Sprintf("消息总接收数: %d 接收消息总大小:%s\n", totalreceive, utils.FormatByesSize(totalreceiveSize))) file.WriteString(fmt.Sprintf("消息总请求大小: %s\n", utils.FormatByesSize(totalrequestSize)))
file.WriteString(fmt.Sprintf("消息总接收数: %d\n", totalreceive))
file.WriteString(fmt.Sprintf("消息总接收大小: %s\n", utils.FormatByesSize(totalreceiveSize)))
file.WriteString(fmt.Sprintf("压测执行时长: %.2f秒\n", this.end.Sub(this.start).Seconds()))
file.WriteString(fmt.Sprintf("QPS: %.2f\n", float64(totalmessage)/this.end.Sub(this.start).Seconds())) file.WriteString(fmt.Sprintf("QPS: %.2f\n", float64(totalmessage)/this.end.Sub(this.start).Seconds()))
file.WriteString("---消息压测详情----------------------------------------------------------------------------------------------------\n") file.WriteString("---消息压测详情----------------------------------------------------------------------------------------------------\n")
for message, data := range messages { for message, data := range messagestime {
sort.Slice(data, func(i, j int) bool { sort.Slice(data, func(i, j int) bool {
return data[i] < data[j] return data[i] < data[j]
}) })
reqsize := requestsize[message]
respsize := receiveSize[message]
max := data[len(data)-1] max := data[len(data)-1]
min := data[0] min := data[0]
sum := int64(0) sum := int64(0)
@ -140,11 +149,12 @@ func (this *statisticalComp) OutReport() {
} else { } else {
median = float64(data[len(data)/2]) median = float64(data[len(data)/2])
} }
file.WriteString(fmt.Sprintf("消息名:%-20s 请求次数:%-5d 耗时最小:%-5dms 耗时最大:%-5dms 平均耗时:%-5.2fms 中位耗时:%-5.2fms \n", message, len(data), min, max, avg, median)) file.WriteString(fmt.Sprintf("消息名:%-30s 请求次数:%-5d 请求数据:%-10s --%-2.2f%% 接收数据:%-10s --%-2.2f%% 耗时最小:%-5dms 耗时最大:%-5dms 平均耗时:%-5.2fms 中位耗时:%-5.2fms \n", message, len(data), utils.FormatByesSize(reqsize), 100*(float32(reqsize)/float32(totalrequestSize)), utils.FormatByesSize(respsize), 100*(float32(respsize)/float32(totalreceiveSize)), min, max, avg, median))
} }
file.WriteString("---消息压测接收回包消息统计----------------------------------------------------------------------------------------------------\n")
for k, v := range receive { for k, v := range receive {
file.WriteString(fmt.Sprintf("消息名:%-20s 请求次数:%-5d 请求总大小:%s\n", k, v, utils.FormatByesSize(receiveSize[k]))) if _, ok = messagestime[k]; !ok {
file.WriteString(fmt.Sprintf("消息名:%-30s 推送次数:%-5d 数据大小:%-5s --%-2.2f%% \n", k, v, utils.FormatByesSize(receiveSize[k]), 100*(float32(receiveSize[k])/float32(totalreceiveSize))))
}
} }
} }

View File

@ -28,6 +28,7 @@ type msghandle struct {
// 组件参数 // 组件参数
type CompOptions struct { type CompOptions struct {
MaxTime int32
} }
func (this *CompOptions) LoadConfig(settings map[string]interface{}) (err error) { func (this *CompOptions) LoadConfig(settings map[string]interface{}) (err error) {
@ -155,7 +156,7 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag
reply.Reply = session.Polls() reply.Reply = session.Polls()
// log.Debugf("[Handle Api] t:%v m:%s uid:%s req:%v reply:%v", time.Since(stime), method, args.UserId, msg, reply) // log.Debugf("[Handle Api] t:%v m:%s uid:%s req:%v reply:%v", time.Since(stime), method, args.UserId, msg, reply)
nt := time.Since(stime).Milliseconds() nt := time.Since(stime).Milliseconds()
if nt < 100 { if this.options.MaxTime == 0 || nt < int64(this.options.MaxTime) {
log.Debug("[Handle Api]", log.Debug("[Handle Api]",
log.Field{Key: "t", Value: time.Since(stime).Milliseconds()}, log.Field{Key: "t", Value: time.Since(stime).Milliseconds()},
log.Field{Key: "m", Value: method}, log.Field{Key: "m", Value: method},