69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
package comm
|
|
|
|
import (
|
|
"go_dreamfactory/pb"
|
|
"reflect"
|
|
|
|
"github.com/liwei1dao/lego/core"
|
|
"github.com/liwei1dao/lego/sys/log"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
const (
|
|
SC_ServiceGateRouteComp core.S_Comps = "SC_GateRouteComp" //s_comps.ISC_GateRouteComp
|
|
)
|
|
|
|
const (
|
|
SM_GateModule core.M_Modules = "gateway" //gate模块 网关服务模块
|
|
SM_WebModule core.M_Modules = "web" //web模块
|
|
SM_LoginModule core.M_Modules = "user" //用户模块
|
|
SM_PackModule core.M_Modules = "pack" //背包模块
|
|
)
|
|
|
|
const ( //Rpc
|
|
Rpc_GatewayRoute core.Rpc_Key = "Rpc_GatewayRoute" //网关路由
|
|
Rpc_GatewayAgentBuild core.Rpc_Key = "Rpc_GatewayAgentBuild" //代理绑定 绑定用户Id
|
|
Rpc_GatewayAgentUnBuild core.Rpc_Key = "Rpc_GatewayAgentUnBuild" //代理解绑 解绑用户Id
|
|
Rpc_GatewayAgentSendMsg core.Rpc_Key = "Rpc_GatewayAgentSendMsg" //代理发送消息 向用户发送消息
|
|
Rpc_GatewaySendBatchMsg core.Rpc_Key = "Rpc_GatewaySendBatchMsg" //向多个用户发送消息
|
|
Rpc_GatewaySendRadioMsg core.Rpc_Key = "Rpc_GatewaySendRadioMsg" //广播消息
|
|
Rpc_GatewayAgentClose core.Rpc_Key = "Rpc_GatewayAgentClose" //代理关闭 关闭用户连接
|
|
)
|
|
|
|
type ISC_GateRouteComp interface {
|
|
core.IServiceComp
|
|
RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method)
|
|
}
|
|
|
|
//用户会话
|
|
type IUserSession interface {
|
|
GetSessionId() string
|
|
GetUserId() string
|
|
GetIP() string
|
|
GetGatewayServiceId() string
|
|
Build(uid string) (err error)
|
|
UnBuild(ServiceMethod string, msg proto.Message) (err error)
|
|
SendMsg(mainType, subType string, code pb.ErrorCode, msg proto.Message) (err error)
|
|
Close() (err error)
|
|
ToString() string
|
|
}
|
|
|
|
func ProtoDecode(msg *pb.UserMessage, req proto.Message) (ok bool) {
|
|
err := proto.Unmarshal(msg.Data, req)
|
|
if err != nil {
|
|
log.Errorf("%s.%s %v", msg.MainType, msg.SubType, err)
|
|
return
|
|
}
|
|
return true
|
|
}
|
|
|
|
func ProtoEncode(rsp proto.Message, msg *pb.UserMessage) (ok bool) {
|
|
data, err := proto.Marshal(rsp)
|
|
if err != nil {
|
|
log.Errorf("%s.%s %v", msg.MainType, msg.SubType, err)
|
|
return
|
|
}
|
|
msg.Data = data
|
|
return true
|
|
}
|