修复机器人测试逻辑
This commit is contained in:
parent
db0df37526
commit
6943458a0d
@ -31,6 +31,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var account = flag.String("account", "", "account")
|
var account = flag.String("account", "", "account")
|
||||||
|
var sid = flag.Int32("sid", 0, "区服ID")
|
||||||
var create = flag.Bool("create", false, "account") //false 不创建新账号
|
var create = flag.Bool("create", false, "account") //false 不创建新账号
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -45,7 +46,7 @@ var runCmd = &cobra.Command{
|
|||||||
opts := robot.DefaultOpts()
|
opts := robot.DefaultOpts()
|
||||||
opts.Create = *create
|
opts.Create = *create
|
||||||
opts.Account = *account
|
opts.Account = *account
|
||||||
|
opts.ServerId = *sid
|
||||||
r := robot.NewRobot(opts)
|
r := robot.NewRobot(opts)
|
||||||
r.Run()
|
r.Run()
|
||||||
},
|
},
|
||||||
|
@ -113,7 +113,7 @@ func (r *Robot) FriendAgree(friendIds []string) {
|
|||||||
req := &pb.FriendAgreeReq{
|
req := &pb.FriendAgreeReq{
|
||||||
FriendIds: friendIds,
|
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)
|
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||||
err := r.SendToClient(head, req)
|
err := r.SendToClient(head, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
type LoginParam struct {
|
type LoginParam struct {
|
||||||
Account string `json:"account"`
|
Account string `json:"account"`
|
||||||
ServerId int `json:"serverId"`
|
ServerId int32 `json:"serverId"`
|
||||||
TimeStamp int64 `json:"timestamp"`
|
TimeStamp int64 `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ type Options struct {
|
|||||||
Account string //玩家账号
|
Account string //玩家账号
|
||||||
Create bool
|
Create bool
|
||||||
Secretkey string //秘钥串
|
Secretkey string //秘钥串
|
||||||
ServerId int
|
ServerId int32 //区服ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultOpts() *Options {
|
func DefaultOpts() *Options {
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
type Robot struct {
|
type Robot struct {
|
||||||
ws *websocket.Conn
|
ws *websocket.Conn
|
||||||
opts *Options
|
opts *Options
|
||||||
user *pb.Cache_UserData
|
user *pb.DB_UserData
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRobot(opts *Options) *Robot {
|
func NewRobot(opts *Options) *Robot {
|
||||||
@ -39,7 +39,7 @@ func (r *Robot) Run() {
|
|||||||
log.Printf("websocket %s \n", r.opts.WsUrl)
|
log.Printf("websocket %s \n", r.opts.WsUrl)
|
||||||
|
|
||||||
if r.opts.Create { //创建新用户
|
if r.opts.Create { //创建新用户
|
||||||
r.AccountRegister(r.opts.Account)
|
r.AccountRegister(r.opts.Account, int32(r.opts.ServerId))
|
||||||
} else {
|
} else {
|
||||||
r.AccountLogin()
|
r.AccountLogin()
|
||||||
}
|
}
|
||||||
@ -80,11 +80,11 @@ func (r *Robot) handleMsg(msg *pb.UserMessage) {
|
|||||||
//在这里添加玩家成功登录以后的测试方法
|
//在这里添加玩家成功登录以后的测试方法
|
||||||
func (r *Robot) onUserLoaded() {
|
func (r *Robot) onUserLoaded() {
|
||||||
//user
|
//user
|
||||||
// r.CreateUser("乐谷4")
|
// r.CreateUser("乐谷616")
|
||||||
|
|
||||||
//friend
|
//friend
|
||||||
// r.FriendApply("629f147e3d276120561bfa18")
|
// r.FriendApply("0_62aa9427e2979698b080ec78")
|
||||||
// r.FriendAgree([]string{})
|
r.FriendAgree([]string{"0_62a9afd994fe03b7aaee6773"})
|
||||||
// r.FriendRefuse([]string{})
|
// r.FriendRefuse([]string{})
|
||||||
// r.FriendApplyList()
|
// r.FriendApplyList()
|
||||||
// r.FriendList()
|
// 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 == "" {
|
if account == "" {
|
||||||
log.Fatal("account value is empty")
|
log.Fatal("account value is empty")
|
||||||
}
|
}
|
||||||
//http
|
//http
|
||||||
regReq := &pb.UserRegisterReq{Account: account}
|
regReq := &pb.UserRegisterReq{Account: account, Sid: sid}
|
||||||
jsonByte, _ := json.Marshal(regReq)
|
jsonByte, _ := json.Marshal(regReq)
|
||||||
req, err := http.NewRequest("POST", r.opts.RegUrl, bytes.NewReader(jsonByte))
|
req, err := http.NewRequest("POST", r.opts.RegUrl, bytes.NewReader(jsonByte))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -30,7 +30,7 @@ func (r *Robot) handleLogin(msg *pb.UserMessage) {
|
|||||||
r.user = rsp.Data
|
r.user = rsp.Data
|
||||||
r.onUserLoaded()
|
r.onUserLoaded()
|
||||||
} else {
|
} else {
|
||||||
r.AccountRegister(r.opts.Account) //请求Http接口,模拟创建新账号
|
r.AccountRegister(r.opts.Account, int32(r.opts.ServerId)) //请求Http接口,模拟创建新账号
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user