robot统一通知处理
This commit is contained in:
parent
028727449b
commit
cab6a2d07b
@ -33,7 +33,6 @@ func (r *Robot) BuildSecStr() string {
|
|||||||
//处理登录请求
|
//处理登录请求
|
||||||
func (r *Robot) AccountLogin() {
|
func (r *Robot) AccountLogin() {
|
||||||
//登录
|
//登录
|
||||||
// sec := r.BuildSecStr()
|
|
||||||
// log.Printf("client secret key:%s", sec)
|
// log.Printf("client secret key:%s", sec)
|
||||||
loginReg := &pb.UserLoginReq{
|
loginReg := &pb.UserLoginReq{
|
||||||
Account: r.opts.Account,
|
Account: r.opts.Account,
|
||||||
@ -43,6 +42,7 @@ func (r *Robot) AccountLogin() {
|
|||||||
head := &pb.UserMessage{
|
head := &pb.UserMessage{
|
||||||
MainType: "user",
|
MainType: "user",
|
||||||
SubType: "login",
|
SubType: "login",
|
||||||
|
Sec: r.BuildSecStr(),
|
||||||
}
|
}
|
||||||
defer traceFunc(head.MainType, head.SubType, "0", loginReg)
|
defer traceFunc(head.MainType, head.SubType, "0", loginReg)
|
||||||
err := r.SendToClient(head, loginReg)
|
err := r.SendToClient(head, loginReg)
|
||||||
|
26
cmd/robot/notify.go
Normal file
26
cmd/robot/notify.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package robot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
//统一通知处理
|
||||||
|
func (r *Robot) handleNotifyMsg(msg *pb.UserMessage) {
|
||||||
|
switch msg.SubType {
|
||||||
|
case comm.SubType_ErrorNotify:
|
||||||
|
r.handleError(msg)
|
||||||
|
default:
|
||||||
|
fmt.Printf("subType: %s not define", msg.SubType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//处理错误
|
||||||
|
func (r *Robot) handleError(msg *pb.UserMessage) {
|
||||||
|
rsp := &pb.ErrorNotify{}
|
||||||
|
if !comm.ProtoUnmarshal(msg, rsp) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
printReply(msg, rsp)
|
||||||
|
}
|
@ -75,6 +75,8 @@ func (r *Robot) handleMsg(msg *pb.UserMessage) {
|
|||||||
r.handleFriendMsg(msg)
|
r.handleFriendMsg(msg)
|
||||||
case "pack":
|
case "pack":
|
||||||
r.handlePackMsg(msg)
|
r.handlePackMsg(msg)
|
||||||
|
case comm.MainType_Notify:
|
||||||
|
r.handleNotifyMsg(msg)
|
||||||
default:
|
default:
|
||||||
log.Fatal("module route no exist")
|
log.Fatal("module route no exist")
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
)
|
)
|
||||||
@ -22,6 +21,12 @@ const (
|
|||||||
Service_Worker = "worker"
|
Service_Worker = "worker"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//ERR
|
||||||
|
const (
|
||||||
|
MainType_Notify = "notify" //通知
|
||||||
|
SubType_ErrorNotify = "errornotify" //错误通知
|
||||||
|
)
|
||||||
|
|
||||||
//模块名定义处
|
//模块名定义处
|
||||||
const (
|
const (
|
||||||
SM_GateModule core.M_Modules = "gateway" //gate模块 网关服务模块
|
SM_GateModule core.M_Modules = "gateway" //gate模块 网关服务模块
|
||||||
|
@ -76,12 +76,15 @@ locp:
|
|||||||
} else {
|
} else {
|
||||||
err = this.secAuth(msg)
|
err = this.secAuth(msg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
this.messageDistribution(msg)
|
if err := this.messageDistribution(msg); err != nil {
|
||||||
|
go this.Close()
|
||||||
|
break locp
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
data, _ := anypb.New(&pb.ErrorNotify{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: pb.ErrorCode_SecKeyInvalid})
|
data, _ := anypb.New(&pb.ErrorNotify{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: pb.ErrorCode_SecKeyInvalid})
|
||||||
if err = this.WriteMsg(&pb.UserMessage{
|
if err = this.WriteMsg(&pb.UserMessage{
|
||||||
MainType: "notify",
|
MainType: comm.MainType_Notify,
|
||||||
SubType: "errornotify",
|
SubType: comm.SubType_ErrorNotify,
|
||||||
Data: data,
|
Data: data,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
go this.Close()
|
go this.Close()
|
||||||
@ -201,7 +204,7 @@ func (this *Agent) Close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//分发用户消息
|
//分发用户消息
|
||||||
func (this *Agent) messageDistribution(msg *pb.UserMessage) {
|
func (this *Agent) messageDistribution(msg *pb.UserMessage) error {
|
||||||
reply := &pb.RPCMessageReply{}
|
reply := &pb.RPCMessageReply{}
|
||||||
log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
|
log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
|
||||||
if err := this.gateway.Service().RpcCall(context.Background(), comm.Service_Worker, string(comm.Rpc_GatewayRoute), &pb.AgentMessage{
|
if err := this.gateway.Service().RpcCall(context.Background(), comm.Service_Worker, string(comm.Rpc_GatewayRoute), &pb.AgentMessage{
|
||||||
@ -213,14 +216,16 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) {
|
|||||||
Message: msg.Data,
|
Message: msg.Data,
|
||||||
}, reply); err != nil {
|
}, reply); err != nil {
|
||||||
log.Errorf("agent:%s uId:%s MessageDistribution err:%v", this.sessionId, this.uId, err)
|
log.Errorf("agent:%s uId:%s MessageDistribution err:%v", this.sessionId, this.uId, err)
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
if reply.Code != pb.ErrorCode_Success {
|
if reply.Code != pb.ErrorCode_Success {
|
||||||
data, _ := anypb.New(&pb.ErrorNotify{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: reply.Code})
|
data, _ := anypb.New(&pb.ErrorNotify{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: reply.Code})
|
||||||
this.WriteMsg(&pb.UserMessage{
|
err := this.WriteMsg(&pb.UserMessage{
|
||||||
MainType: "notify",
|
MainType: comm.MainType_Notify,
|
||||||
SubType: "errornotify",
|
SubType: comm.SubType_ErrorNotify,
|
||||||
Data: data,
|
Data: data,
|
||||||
})
|
})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user