update robot
This commit is contained in:
parent
01cd864ba1
commit
8d0a0a0043
@ -4,209 +4,77 @@ import (
|
|||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/modules/friend"
|
"go_dreamfactory/modules/friend"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Robot) handleFriendMsg(msg *pb.UserMessage) {
|
var (
|
||||||
switch msg.SubType {
|
//friend
|
||||||
case friend.Friend_SubType_List:
|
friend_builders = []*builder{
|
||||||
r.handleFriendList(msg)
|
{
|
||||||
case friend.Friend_SubType_Apply:
|
//list
|
||||||
r.handleFriendApply(msg)
|
mainType: string(comm.SM_FriendModule),
|
||||||
case friend.Friend_SubType_ApplyList:
|
subType: friend.Friend_SubType_List,
|
||||||
r.handleFriendApplyList(msg)
|
req: &pb.Friend_List_Req{},
|
||||||
case friend.Friend_SubType_Agree:
|
rsp: &pb.Friend_List_Rsp{},
|
||||||
r.handleFriendAgree(msg)
|
enabled: true,
|
||||||
case friend.Friend_SubType_Refuse:
|
}, {
|
||||||
r.handleFriendRefuse(msg)
|
//blacklist
|
||||||
case friend.Friend_SubType_Blacklist:
|
mainType: string(comm.SM_FriendModule),
|
||||||
r.handleFriendBlacklist(msg)
|
subType: friend.Friend_SubType_Blacklist,
|
||||||
case friend.Friend_SubType_AddBlack:
|
req: &pb.Friend_BlackList_Req{},
|
||||||
r.handleFriendAddBlack(msg)
|
rsp: &pb.Friend_BlackList_Rsp{},
|
||||||
case friend.Friend_SubType_DelBlack:
|
}, {
|
||||||
r.handleFriendDelBlack(msg)
|
//search
|
||||||
case friend.Friend_SubType_Search:
|
mainType: string(comm.SM_FriendModule),
|
||||||
r.handleFriendSearch(msg)
|
subType: friend.Friend_SubType_Search,
|
||||||
}
|
req: &pb.Friend_Search_Req{
|
||||||
|
NickName: "", //设置测试参数
|
||||||
|
},
|
||||||
|
rsp: &pb.Friend_Search_Rsp{},
|
||||||
|
}, {
|
||||||
|
//apply
|
||||||
|
mainType: string(comm.SM_FriendModule),
|
||||||
|
subType: friend.Friend_SubType_Apply,
|
||||||
|
req: &pb.Friend_Apply_Req{},
|
||||||
|
rsp: &pb.Friend_Apply_Rsp{},
|
||||||
|
enabled: true,
|
||||||
|
}, {
|
||||||
|
//applylist
|
||||||
|
mainType: string(comm.SM_FriendModule),
|
||||||
|
subType: friend.Friend_SubType_ApplyList,
|
||||||
|
req: &pb.Friend_ApplyList_Req{},
|
||||||
|
rsp: &pb.Friend_ApplyList_Rsp{},
|
||||||
|
}, {
|
||||||
|
//agree
|
||||||
|
mainType: string(comm.SM_FriendModule),
|
||||||
|
subType: friend.Friend_SubType_Agree,
|
||||||
|
req: &pb.Friend_Agree_Req{},
|
||||||
|
rsp: &pb.Friend_Agree_Rsp{},
|
||||||
|
}, {
|
||||||
|
//refuse
|
||||||
|
mainType: string(comm.SM_FriendModule),
|
||||||
|
subType: friend.Friend_SubType_Refuse,
|
||||||
|
req: &pb.Friend_Agree_Req{},
|
||||||
|
rsp: &pb.Friend_Agree_Rsp{},
|
||||||
|
}, {
|
||||||
|
//addblack
|
||||||
|
mainType: string(comm.SM_FriendModule),
|
||||||
|
subType: friend.Friend_SubType_AddBlack,
|
||||||
|
req: &pb.Friend_BlackAdd_Req{
|
||||||
|
FriendId: "",
|
||||||
|
},
|
||||||
|
rsp: &pb.Friend_BlackAdd_Rsp{},
|
||||||
|
}, {
|
||||||
|
//delblack
|
||||||
|
mainType: string(comm.SM_FriendModule),
|
||||||
|
subType: friend.Friend_SubType_DelBlack,
|
||||||
|
req: &pb.Friend_DelBlack_Req{},
|
||||||
|
rsp: &pb.Friend_DelBlack_Rsp{},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
//好友列表
|
//声明加入到构建器并发起请求
|
||||||
func (r *Robot) FriendList() {
|
func (r *Robot) RunFriend() {
|
||||||
req := &pb.Friend_List_Req{}
|
r.addBuilders(friend_builders)
|
||||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_List}
|
r.handleReq()
|
||||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
|
||||||
err := r.SendToClient(head, req)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Robot) handleFriendList(msg *pb.UserMessage) {
|
|
||||||
rsp := &pb.Friend_List_Rsp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
printReply(msg, rsp)
|
|
||||||
}
|
|
||||||
|
|
||||||
//好友搜索
|
|
||||||
func (r *Robot) FriendSearch(nickName string) {
|
|
||||||
req := &pb.Friend_Search_Req{
|
|
||||||
NickName: nickName,
|
|
||||||
}
|
|
||||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Search}
|
|
||||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
|
||||||
err := r.SendToClient(head, req)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Robot) handleFriendSearch(msg *pb.UserMessage) {
|
|
||||||
rsp := &pb.Friend_Search_Rsp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
printReply(msg, rsp)
|
|
||||||
}
|
|
||||||
|
|
||||||
//好友申请
|
|
||||||
func (r *Robot) FriendApply(friendId string) {
|
|
||||||
req := &pb.Friend_Apply_Req{
|
|
||||||
FriendId: friendId,
|
|
||||||
}
|
|
||||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Apply}
|
|
||||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
|
||||||
err := r.SendToClient(head, req)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Robot) handleFriendApply(msg *pb.UserMessage) {
|
|
||||||
rsp := &pb.Friend_Apply_Rsp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
printReply(msg, rsp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 申请列表
|
|
||||||
func (r *Robot) FriendApplyList() {
|
|
||||||
req := &pb.Friend_ApplyList_Req{}
|
|
||||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_ApplyList}
|
|
||||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
|
||||||
err := r.SendToClient(head, req)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Robot) handleFriendApplyList(msg *pb.UserMessage) {
|
|
||||||
rsp := &pb.Friend_ApplyList_Rsp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
printReply(msg, rsp)
|
|
||||||
}
|
|
||||||
|
|
||||||
//同意
|
|
||||||
func (r *Robot) FriendAgree(friendIds []string) {
|
|
||||||
req := &pb.Friend_Agree_Req{
|
|
||||||
FriendIds: friendIds,
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Robot) handleFriendAgree(msg *pb.UserMessage) {
|
|
||||||
rsp := &pb.Friend_Agree_Rsp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
printReply(msg, rsp)
|
|
||||||
}
|
|
||||||
|
|
||||||
//拒绝
|
|
||||||
func (r *Robot) FriendRefuse(friendIds []string) {
|
|
||||||
req := &pb.Friend_Refuse_Req{
|
|
||||||
FriendIds: friendIds,
|
|
||||||
}
|
|
||||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Refuse}
|
|
||||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
|
||||||
err := r.SendToClient(head, req)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Robot) handleFriendRefuse(msg *pb.UserMessage) {
|
|
||||||
rsp := &pb.Friend_Refuse_Rsp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
printReply(msg, rsp)
|
|
||||||
}
|
|
||||||
|
|
||||||
//黑名单列表
|
|
||||||
func (r *Robot) FriendBlacklist() {
|
|
||||||
req := &pb.Friend_BlackList_Req{}
|
|
||||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Blacklist}
|
|
||||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
|
||||||
err := r.SendToClient(head, req)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Robot) handleFriendBlacklist(msg *pb.UserMessage) {
|
|
||||||
rsp := &pb.Friend_BlackList_Rsp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
printReply(msg, rsp)
|
|
||||||
}
|
|
||||||
|
|
||||||
//添加黑名单
|
|
||||||
func (r *Robot) FriendAddBlack(friendId string) {
|
|
||||||
req := &pb.Friend_BlackAdd_Req{FriendId: friendId}
|
|
||||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_AddBlack}
|
|
||||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
|
||||||
err := r.SendToClient(head, req)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Robot) handleFriendAddBlack(msg *pb.UserMessage) {
|
|
||||||
rsp := &pb.Friend_BlackAdd_Rsp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
printReply(msg, rsp)
|
|
||||||
}
|
|
||||||
|
|
||||||
//删除黑名单
|
|
||||||
func (r *Robot) FriendDelBlack(friendId string) {
|
|
||||||
req := &pb.Friend_DelBlack_Req{
|
|
||||||
FriendId: friendId,
|
|
||||||
}
|
|
||||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_DelBlack}
|
|
||||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
|
||||||
err := r.SendToClient(head, req)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Robot) handleFriendDelBlack(msg *pb.UserMessage) {
|
|
||||||
rsp := &pb.Friend_DelBlack_Rsp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
printReply(msg, rsp)
|
|
||||||
}
|
}
|
||||||
|
26
cmd/robot/hero.go
Normal file
26
cmd/robot/hero.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package robot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/modules/hero"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
//hero
|
||||||
|
hero_builders = []*builder{
|
||||||
|
{
|
||||||
|
mainType: string(comm.SM_HeroModule),
|
||||||
|
subType: hero.Hero_SubType_List,
|
||||||
|
req: &pb.Hero_List_Req{},
|
||||||
|
rsp: &pb.Hero_List_Rsp{},
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
//声明加入到构建器并发起请求
|
||||||
|
func (r *Robot) RunHero() {
|
||||||
|
r.addBuilders(hero_builders)
|
||||||
|
r.handleReq()
|
||||||
|
}
|
@ -1,33 +0,0 @@
|
|||||||
package robot
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go_dreamfactory/comm"
|
|
||||||
"go_dreamfactory/pb"
|
|
||||||
"log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (r *Robot) handlePackMsg(msg *pb.UserMessage) {
|
|
||||||
switch msg.SubType {
|
|
||||||
case "queryuserpackresp":
|
|
||||||
r.handleQueryUserPack(msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//添加好友
|
|
||||||
func (r *Robot) QueryUserPack() {
|
|
||||||
req := &pb.Items_Getlist_Req{IType: 1}
|
|
||||||
head := &pb.UserMessage{MainType: "pack", SubType: "queryuserpackreq"}
|
|
||||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
|
||||||
err := r.SendToClient(head, req)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Robot) handleQueryUserPack(msg *pb.UserMessage) {
|
|
||||||
rsp := &pb.Items_Getlist_Resp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
printReply(msg, rsp)
|
|
||||||
}
|
|
@ -2,6 +2,8 @@ package robot
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/modules/user"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/utils"
|
"go_dreamfactory/utils"
|
||||||
"log"
|
"log"
|
||||||
@ -32,23 +34,19 @@ func (r *Robot) BuildSecStr() string {
|
|||||||
|
|
||||||
//处理登录请求
|
//处理登录请求
|
||||||
func (r *Robot) AccountLogin() {
|
func (r *Robot) AccountLogin() {
|
||||||
//登录
|
log.Printf("区服:[%d] 账号:[%s] login...", r.opts.ServerId, r.opts.Account)
|
||||||
// log.Printf("client secret key:%s", sec)
|
builders := []*builder{
|
||||||
loginReg := &pb.UserLoginReq{
|
{
|
||||||
|
mainType: string(comm.SM_UserModule),
|
||||||
|
subType: user.User_SubType_Login,
|
||||||
|
req: &pb.UserLoginReq{
|
||||||
Account: r.opts.Account,
|
Account: r.opts.Account,
|
||||||
Sid: r.opts.ServerId,
|
Sid: r.opts.ServerId,
|
||||||
|
},
|
||||||
|
rsp: &pb.UserLoginResp{},
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
r.addBuilders(builders)
|
||||||
head := &pb.UserMessage{
|
r.handleReq()
|
||||||
MainType: "user",
|
|
||||||
SubType: "login",
|
|
||||||
Sec: r.BuildSecStr(),
|
|
||||||
}
|
|
||||||
defer traceFunc(head.MainType, head.SubType, "0", loginReg)
|
|
||||||
err := r.SendToClient(head, loginReg)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("send err:%v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("区服:[%d] 账号:[%s] login...", r.opts.ServerId, r.opts.Account)
|
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,21 @@
|
|||||||
package robot
|
package robot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
//统一通知处理
|
var notify_builders = []*builder{
|
||||||
func (r *Robot) handleNotifyMsg(msg *pb.UserMessage) {
|
{
|
||||||
switch msg.SubType {
|
//create
|
||||||
case comm.SubType_ErrorNotify:
|
mainType: comm.MainType_Notify,
|
||||||
r.handleError(msg)
|
subType: comm.SubType_ErrorNotify,
|
||||||
default:
|
rsp: &pb.ErrorNotify{},
|
||||||
fmt.Printf("subType: %s not define", msg.SubType)
|
enabled: true,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理错误
|
//声明加入到构建器并发起请求
|
||||||
func (r *Robot) handleError(msg *pb.UserMessage) {
|
func (r *Robot) RunNotify() {
|
||||||
rsp := &pb.ErrorNotify{}
|
r.addBuilders(notify_builders)
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
printReply(msg, rsp)
|
|
||||||
}
|
}
|
||||||
|
24
cmd/robot/pack.go
Normal file
24
cmd/robot/pack.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package robot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
//申明测试接口及请求和响应参数
|
||||||
|
var pack_builders = []*builder{
|
||||||
|
{
|
||||||
|
//create
|
||||||
|
mainType: string(comm.SM_PackModule),
|
||||||
|
subType: "queryuserpackreq",
|
||||||
|
// req: &pb.Pack_Getlist_Req{IType: 1},
|
||||||
|
rsp: &pb.UserCreateRsp{},
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
//声明加入到构建器并发起请求
|
||||||
|
func (r *Robot) RunPack() {
|
||||||
|
r.addBuilders(pack_builders)
|
||||||
|
r.handleReq()
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
# Robot使用
|
# Robot使用
|
||||||
|
|
||||||
## 命令行
|
## 命令行
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
#使用已存在的账号测试接口
|
#使用已存在的账号测试接口
|
||||||
go run cmd.go run --account yourAccount
|
go run cmd.go run --account yourAccount
|
||||||
@ -13,48 +14,39 @@ go run cmd.go run --account newAccount --create true
|
|||||||
|
|
||||||
@[TOC]
|
@[TOC]
|
||||||
|
|
||||||
|
|
||||||
### 添加测试接口
|
### 添加测试接口
|
||||||
|
|
||||||
* 请求的方法
|
* 声明测试接口
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// 好友申请,参数根据实际业务添加
|
var user_builders = []*builder{
|
||||||
func (r *Robot) FriendApply(friendIds []string) {
|
{
|
||||||
...
|
//create
|
||||||
|
mainType: string(comm.SM_UserModule),
|
||||||
|
subType: user.User_SubType_Create,
|
||||||
|
req: &pb.UserCreateReq{ //设置请求参数
|
||||||
|
NickName: "测试",
|
||||||
|
},
|
||||||
|
rsp: &pb.UserCreateRsp{},
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
* 响应的方法
|
### 声明加入到构建器并发起请求
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Robot) handleFriendApply(msg *pb.UserMessage) {
|
func (r *Robot) RunUser() {
|
||||||
...
|
r.addBuilders(user_builders)
|
||||||
|
r.handleReq()
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### 添加subType,调用响应方法
|
### 添加用户登录之后需要测试的接口
|
||||||
|
|
||||||
```go
|
|
||||||
//根据实际情况添加subtype
|
|
||||||
func (r *Robot) handleFriendMsg(msg *pb.UserMessage) {
|
|
||||||
switch msg.SubType {
|
|
||||||
case "apply":
|
|
||||||
//调用响应
|
|
||||||
r.handleFriendApply(msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 修改请求方法调用
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Robot) onUserLoaded() {
|
func (r *Robot) onUserLoaded() {
|
||||||
switch msg.MainType {
|
//添加用户登录之后需要测试的接口
|
||||||
case "user":
|
r.RunUser()
|
||||||
r.handleUserMsg(msg)
|
|
||||||
case "friend":
|
|
||||||
r.handleFriendMsg(msg)
|
|
||||||
...
|
|
||||||
}
|
}
|
||||||
```
|
```
|
@ -9,6 +9,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
@ -19,6 +20,7 @@ type Robot struct {
|
|||||||
ws *websocket.Conn
|
ws *websocket.Conn
|
||||||
opts *Options
|
opts *Options
|
||||||
user *pb.DB_UserData
|
user *pb.DB_UserData
|
||||||
|
builders []*builder
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRobot(opts *Options) *Robot {
|
func NewRobot(opts *Options) *Robot {
|
||||||
@ -37,7 +39,6 @@ func NewRobot(opts *Options) *Robot {
|
|||||||
func (r *Robot) Run() {
|
func (r *Robot) Run() {
|
||||||
log.Print("Robot running...")
|
log.Print("Robot running...")
|
||||||
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, int32(r.opts.ServerId))
|
r.AccountRegister(r.opts.Account, int32(r.opts.ServerId))
|
||||||
} else {
|
} else {
|
||||||
@ -59,48 +60,80 @@ func (r *Robot) Run() {
|
|||||||
if err = proto.Unmarshal(data, msg); err != nil {
|
if err = proto.Unmarshal(data, msg); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
r.handleMsg(msg)
|
r.handleRsp(msg)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
select {}
|
select {}
|
||||||
}
|
}
|
||||||
|
|
||||||
//模块处理
|
type builder struct {
|
||||||
func (r *Robot) handleMsg(msg *pb.UserMessage) {
|
mainType string
|
||||||
switch msg.MainType {
|
subType string
|
||||||
case "user":
|
req proto.Message
|
||||||
r.handleUserMsg(msg)
|
rsp proto.Message
|
||||||
case "friend":
|
enabled bool
|
||||||
r.handleFriendMsg(msg)
|
start time.Time
|
||||||
case "pack":
|
requested bool //请求标识 true已发
|
||||||
r.handlePackMsg(msg)
|
}
|
||||||
case comm.MainType_Notify:
|
|
||||||
r.handleNotifyMsg(msg)
|
func (r *Robot) addBuilders(builders []*builder) {
|
||||||
default:
|
for _, b := range builders {
|
||||||
log.Fatal("module route no exist")
|
if b.enabled {
|
||||||
|
r.builders = append(r.builders, b)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//在这里添加玩家成功登录以后的测试方法
|
//执行请求
|
||||||
func (r *Robot) onUserLoaded() {
|
func (r *Robot) handleReq() {
|
||||||
//user
|
for _, b := range r.builders {
|
||||||
// r.CreateUser("乐谷6171")
|
if b.req != nil && !b.requested {
|
||||||
|
b.requested = true
|
||||||
|
b.start = time.Now()
|
||||||
|
head := &pb.UserMessage{MainType: b.mainType, SubType: b.subType}
|
||||||
|
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), b.req)
|
||||||
|
err := r.SendToClient(head, b.req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//friend
|
//执行响应
|
||||||
// r.FriendApply("1_62aa8f30d25fb8c1a7d90b50")
|
func (r *Robot) handleRsp(msg *pb.UserMessage) {
|
||||||
// r.FriendAgree([]string{"0_62a9afd994fe03b7aaee6773"})
|
|
||||||
// r.FriendRefuse([]string{"0_62aa9427e2979698b080ec78"})
|
|
||||||
// r.FriendApplyList()
|
|
||||||
// r.FriendList()
|
|
||||||
// r.FriendBlacklist()
|
|
||||||
// r.FriendAddBlack("0_62b01623e4c60c3db8bfe6da")
|
|
||||||
// r.FriendDelBlack("0_62b01623e4c60c3db8bfe6da")
|
|
||||||
// r.FriendSearch("乐谷5")
|
|
||||||
|
|
||||||
//pack
|
for i, b := range r.builders {
|
||||||
// r.QueryUserPack()
|
if b.enabled && (msg.MainType == b.mainType &&
|
||||||
|
msg.SubType == b.subType) {
|
||||||
|
if !comm.ProtoUnmarshal(msg, b.rsp) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
printReply(msg, b)
|
||||||
|
|
||||||
|
if msg.MainType == "user" && msg.SubType == "login" {
|
||||||
|
r.loginCallback(b.rsp)
|
||||||
|
} else {
|
||||||
|
if b.requested {
|
||||||
|
r.builders = append(r.builders[:i], r.builders[i+1:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//登录回调
|
||||||
|
func (r *Robot) loginCallback(rsp proto.Message) {
|
||||||
|
r.builders = append(r.builders[:0], r.builders[1:]...)
|
||||||
|
lr := rsp.(*pb.UserLoginResp)
|
||||||
|
if lr.Data != nil {
|
||||||
|
r.user = lr.Data
|
||||||
|
r.onUserLoaded()
|
||||||
|
} else {
|
||||||
|
r.AccountRegister(r.opts.Account, int32(r.opts.ServerId)) //请求Http接口,模拟创建新账号
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Robot) SendToClient(msg *pb.UserMessage, rsp proto.Message) error {
|
func (r *Robot) SendToClient(msg *pb.UserMessage, rsp proto.Message) error {
|
||||||
@ -113,6 +146,24 @@ func (r *Robot) SendToClient(msg *pb.UserMessage, rsp proto.Message) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//在这里添加玩家成功登录以后的测试方法
|
||||||
|
//次方法在用户登录成功后调用
|
||||||
|
func (r *Robot) onUserLoaded() {
|
||||||
|
//notify
|
||||||
|
r.RunNotify()
|
||||||
|
//user
|
||||||
|
// r.RunUser()
|
||||||
|
|
||||||
|
//friend
|
||||||
|
// r.RunFriend()
|
||||||
|
|
||||||
|
//pack
|
||||||
|
// r.RunPack()
|
||||||
|
|
||||||
|
//hero
|
||||||
|
r.RunHero()
|
||||||
|
}
|
||||||
|
|
||||||
//注册账号
|
//注册账号
|
||||||
func (r *Robot) AccountRegister(account string, sid int32) {
|
func (r *Robot) AccountRegister(account string, sid int32) {
|
||||||
if account == "" {
|
if account == "" {
|
||||||
@ -160,11 +211,17 @@ func (r *Robot) AccountRegister(account string, sid int32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//打印响应
|
//打印响应
|
||||||
func printReply(msg *pb.UserMessage, rsp interface{}) {
|
func printReply(msg *pb.UserMessage, builder *builder) {
|
||||||
if m, ok := rsp.(*pb.ErrorNotify); ok {
|
if m, ok := builder.rsp.(*pb.ErrorNotify); ok {
|
||||||
log.Printf("rsp [%s.%s] [%v:%v]", msg.MainType, msg.SubType, int32(m.Code), m.Data)
|
var tt time.Duration
|
||||||
|
if builder.start.IsZero() {
|
||||||
|
tt = time.Duration(0)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("rsp [%s.%s] [%v]", msg.MainType, msg.SubType, rsp)
|
tt = time.Since(builder.start)
|
||||||
|
}
|
||||||
|
log.Printf("rsp [%v] [%s.%s] [%v:%v]", tt, m.ReqMainType, m.ReqSubType, int32(m.Code), m.Data)
|
||||||
|
} else {
|
||||||
|
log.Printf("rsp [%v] [%s.%s] [%v]", time.Since(builder.start), msg.MainType, msg.SubType, builder.rsp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,58 +4,24 @@ import (
|
|||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/modules/user"
|
"go_dreamfactory/modules/user"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Robot) handleUserMsg(msg *pb.UserMessage) {
|
//申明测试接口及请求和响应参数
|
||||||
switch msg.SubType {
|
var user_builders = []*builder{
|
||||||
case "login":
|
{
|
||||||
r.handleLogin(msg)
|
//create
|
||||||
case "create":
|
mainType: string(comm.SM_UserModule),
|
||||||
r.handleCreateUser(msg)
|
subType: user.User_SubType_Create,
|
||||||
|
req: &pb.UserCreateReq{ //设置请求参数
|
||||||
|
NickName: "测试",
|
||||||
|
},
|
||||||
|
rsp: &pb.UserCreateRsp{},
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
//声明加入到构建器并发起请求
|
||||||
|
func (r *Robot) RunUser() {
|
||||||
//处理登录响应数据
|
r.addBuilders(user_builders)
|
||||||
func (r *Robot) handleLogin(msg *pb.UserMessage) {
|
r.handleReq()
|
||||||
rsp := &pb.UserLoginResp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
printReply(msg, rsp)
|
|
||||||
|
|
||||||
//是否有登录数据返回
|
|
||||||
if rsp != nil {
|
|
||||||
r.user = rsp.Data
|
|
||||||
r.onUserLoaded()
|
|
||||||
} else {
|
|
||||||
r.AccountRegister(r.opts.Account, int32(r.opts.ServerId)) //请求Http接口,模拟创建新账号
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//创角
|
|
||||||
func (r *Robot) CreateUser(NickName string) {
|
|
||||||
req := &pb.UserCreateReq{
|
|
||||||
NickName: NickName,
|
|
||||||
}
|
|
||||||
|
|
||||||
head := &pb.UserMessage{
|
|
||||||
MainType: string(comm.SM_UserModule),
|
|
||||||
SubType: user.User_SubType_Create,
|
|
||||||
}
|
|
||||||
|
|
||||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
|
||||||
err := r.SendToClient(head, req)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Robot) handleCreateUser(msg *pb.UserMessage) {
|
|
||||||
rsp := &pb.UserCreateRsp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
printReply(msg, rsp)
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ const (
|
|||||||
hero_levelgrow = "game_herolevelgrow.json" //英雄成长系数
|
hero_levelgrow = "game_herolevelgrow.json" //英雄成长系数
|
||||||
hero_starup = "game_herostarup.json" //
|
hero_starup = "game_herostarup.json" //
|
||||||
hero_levelup = "game_herolevelup.json" //英雄等级基础属性
|
hero_levelup = "game_herolevelup.json" //英雄等级基础属性
|
||||||
hero_exp = "game_exp.json"
|
hero_exp = "game_heroexp.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
///配置管理组件
|
///配置管理组件
|
||||||
|
@ -80,3 +80,7 @@ func (this *Hero) GetHeroList(uid string) []*pb.DB_HeroData {
|
|||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *Hero) AddCard(uId string, cardId int32, add int32) (code pb.ErrorCode) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user