修复机器人测试逻辑

This commit is contained in:
zhaocy 2022-06-16 13:38:23 +08:00
parent db0df37526
commit 6943458a0d
6 changed files with 14 additions and 13 deletions

View File

@ -31,6 +31,7 @@ func init() {
}
var account = flag.String("account", "", "account")
var sid = flag.Int32("sid", 0, "区服ID")
var create = flag.Bool("create", false, "account") //false 不创建新账号
func main() {
@ -45,7 +46,7 @@ var runCmd = &cobra.Command{
opts := robot.DefaultOpts()
opts.Create = *create
opts.Account = *account
opts.ServerId = *sid
r := robot.NewRobot(opts)
r.Run()
},

View File

@ -113,7 +113,7 @@ func (r *Robot) FriendAgree(friendIds []string) {
req := &pb.FriendAgreeReq{
FriendIds: friendIds,
}
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Apply}
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Agree}
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
err := r.SendToClient(head, req)
if err != nil {

View File

@ -13,7 +13,7 @@ import (
type LoginParam struct {
Account string `json:"account"`
ServerId int `json:"serverId"`
ServerId int32 `json:"serverId"`
TimeStamp int64 `json:"timestamp"`
}

View File

@ -6,7 +6,7 @@ type Options struct {
Account string //玩家账号
Create bool
Secretkey string //秘钥串
ServerId int
ServerId int32 //区服ID
}
func DefaultOpts() *Options {

View File

@ -18,7 +18,7 @@ import (
type Robot struct {
ws *websocket.Conn
opts *Options
user *pb.Cache_UserData
user *pb.DB_UserData
}
func NewRobot(opts *Options) *Robot {
@ -39,7 +39,7 @@ func (r *Robot) Run() {
log.Printf("websocket %s \n", r.opts.WsUrl)
if r.opts.Create { //创建新用户
r.AccountRegister(r.opts.Account)
r.AccountRegister(r.opts.Account, int32(r.opts.ServerId))
} else {
r.AccountLogin()
}
@ -80,11 +80,11 @@ func (r *Robot) handleMsg(msg *pb.UserMessage) {
//在这里添加玩家成功登录以后的测试方法
func (r *Robot) onUserLoaded() {
//user
// r.CreateUser("乐谷4")
// r.CreateUser("乐谷616")
//friend
// r.FriendApply("629f147e3d276120561bfa18")
// r.FriendAgree([]string{})
// r.FriendApply("0_62aa9427e2979698b080ec78")
r.FriendAgree([]string{"0_62a9afd994fe03b7aaee6773"})
// r.FriendRefuse([]string{})
// r.FriendApplyList()
// r.FriendList()
@ -107,12 +107,12 @@ func (r *Robot) SendToClient(msg *pb.UserMessage, rsp proto.Message) error {
}
//注册账号
func (r *Robot) AccountRegister(account string) {
func (r *Robot) AccountRegister(account string, sid int32) {
if account == "" {
log.Fatal("account value is empty")
}
//http
regReq := &pb.UserRegisterReq{Account: account}
regReq := &pb.UserRegisterReq{Account: account, Sid: sid}
jsonByte, _ := json.Marshal(regReq)
req, err := http.NewRequest("POST", r.opts.RegUrl, bytes.NewReader(jsonByte))
if err != nil {

View File

@ -30,7 +30,7 @@ func (r *Robot) handleLogin(msg *pb.UserMessage) {
r.user = rsp.Data
r.onUserLoaded()
} else {
r.AccountRegister(r.opts.Account) //请求Http接口模拟创建新账号
r.AccountRegister(r.opts.Account, int32(r.opts.ServerId)) //请求Http接口模拟创建新账号
}
}