gateway.modules 代码注释+格式修改
This commit is contained in:
parent
9558e7c4ff
commit
e6f13429bf
@ -212,7 +212,7 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err 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)
|
||||||
servicePath := comm.Service_Worker
|
servicePath := comm.Service_Worker
|
||||||
if rule, ok := this.gateway.GetMsgDistribRule(msg.MainType, msg.SubType); ok {
|
if rule, ok := this.gateway.GetMsgDistribute(msg.MainType, msg.SubType); ok {
|
||||||
servicePath = rule
|
servicePath = rule
|
||||||
} else {
|
} else {
|
||||||
if len(this.wId) > 0 {
|
if len(this.wId) > 0 {
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
/*
|
/*
|
||||||
用户代理对象管理组件
|
用户代理对象管理组件
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type AgentMgrComp struct {
|
type AgentMgrComp struct {
|
||||||
cbase.ModuleCompBase
|
cbase.ModuleCompBase
|
||||||
service base.IRPCXService
|
service base.IRPCXService
|
||||||
|
@ -24,7 +24,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
|
|||||||
}
|
}
|
||||||
|
|
||||||
//获取消息分发规则读取配置表
|
//获取消息分发规则读取配置表
|
||||||
func (this *configureComp) GetMsgDistribRule(mtype, stype string) (rule string, ok bool) {
|
func (this *configureComp) GetMsgDistribute(mtype, stype string) (rule string, ok bool) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
v interface{}
|
v interface{}
|
||||||
|
@ -25,6 +25,6 @@ type (
|
|||||||
Service() base.IRPCXService
|
Service() base.IRPCXService
|
||||||
Connect(a IAgent)
|
Connect(a IAgent)
|
||||||
DisConnect(a IAgent)
|
DisConnect(a IAgent)
|
||||||
GetMsgDistribRule(mtype, stype string) (rule string, ok bool)
|
GetMsgDistribute(mtype, stype string) (rule string, ok bool)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
描述:提供客户端网关路由服务 管理用户socket对象 以及分发用户消息
|
描述:提供客户端网关路由服务 管理用户socket对象 以及分发用户消息
|
||||||
开发:李伟
|
开发:李伟
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func NewModule() core.IModule {
|
func NewModule() core.IModule {
|
||||||
m := new(Gateway)
|
m := new(Gateway)
|
||||||
return m
|
return m
|
||||||
@ -21,53 +22,59 @@ func NewModule() core.IModule {
|
|||||||
|
|
||||||
type Gateway struct {
|
type Gateway struct {
|
||||||
modules.ModuleBase
|
modules.ModuleBase
|
||||||
service base.IRPCXService
|
service base.IRPCXService // rpcx服务接口 主要client->server
|
||||||
wsService *WSServiceComp //websocket 服务组件 提供websocket服务监听
|
wsService *WSServiceComp // websocket服务 监听websocket连接
|
||||||
agentMgr *AgentMgrComp //用户代理对象管理组件 管理用户socket对象
|
agentMgr *AgentMgrComp // 客户端websocket连接管理
|
||||||
configure *configureComp
|
configure *configureComp
|
||||||
}
|
}
|
||||||
|
|
||||||
//模块名
|
// GetType 获取模块服务类型
|
||||||
func (this *Gateway) GetType() core.M_Modules {
|
func (this *Gateway) GetType() core.M_Modules {
|
||||||
return comm.ModuleGate
|
return comm.ModuleGate
|
||||||
}
|
}
|
||||||
|
|
||||||
//模块自定义参数
|
// NewOptions 模块自定义参数
|
||||||
func (this *Gateway) NewOptions() (options core.IModuleOptions) {
|
func (this *Gateway) NewOptions() (options core.IModuleOptions) {
|
||||||
return new(Options)
|
return new(Options)
|
||||||
}
|
}
|
||||||
|
|
||||||
//提供服务对象获取接口
|
// Service 获取rpcx服务接口
|
||||||
func (this *Gateway) Service() base.IRPCXService {
|
func (this *Gateway) Service() base.IRPCXService {
|
||||||
return this.service
|
return this.service
|
||||||
}
|
}
|
||||||
|
|
||||||
//模块初始化函数
|
// Init 模块初始化函数
|
||||||
func (this *Gateway) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
func (this *Gateway) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
||||||
err = this.ModuleBase.Init(service, module, options)
|
err = this.ModuleBase.Init(service, module, options)
|
||||||
this.service = service.(base.IRPCXService)
|
this.service = service.(base.IRPCXService)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务
|
// Start 模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务
|
||||||
func (this *Gateway) Start() (err error) {
|
func (this *Gateway) Start() (err error) {
|
||||||
//注册用户绑定uid接口 登录成功后触发
|
_name2Func := map[string]any{
|
||||||
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentBind), this.agentMgr.Bind)
|
// 注册用户绑定uid接口 登录成功后触发
|
||||||
//注册用户解绑uid接口 登出或则切换账号是触发
|
string(comm.Rpc_GatewayAgentBind): this.agentMgr.Bind,
|
||||||
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentUnBind), this.agentMgr.UnBind)
|
// 注册用户解绑uid接口 登出或则切换账号是触发
|
||||||
//向用户发送消息接口
|
string(comm.Rpc_GatewayAgentUnBind): this.agentMgr.UnBind,
|
||||||
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentSendMsg), this.agentMgr.SendMsgToAgent)
|
// 向用户发送消息接口
|
||||||
//向多个用户对象发送消息接口
|
string(comm.Rpc_GatewayAgentSendMsg): this.agentMgr.SendMsgToAgent,
|
||||||
this.service.RegisterFunctionName(string(comm.Rpc_GatewaySendBatchMsg), this.agentMgr.SendMsgToAgents)
|
// 向多个用户对象发送消息接口
|
||||||
//向所有用户发送消息接口
|
string(comm.Rpc_GatewaySendBatchMsg): this.agentMgr.SendMsgToAgents,
|
||||||
this.service.RegisterFunctionName(string(comm.Rpc_GatewaySendRadioMsg), this.agentMgr.SendMsgToAllAgent)
|
// 向所有用户发送消息接口
|
||||||
//关闭用户socket连接接口
|
string(comm.Rpc_GatewaySendRadioMsg): this.agentMgr.SendMsgToAllAgent,
|
||||||
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentClose), this.agentMgr.CloseAgent)
|
// 关闭用户socket连接接口
|
||||||
|
string(comm.Rpc_GatewayAgentClose): this.agentMgr.CloseAgent,
|
||||||
|
}
|
||||||
|
for name, fn := range _name2Func {
|
||||||
|
this.service.RegisterFunctionName(name, fn)
|
||||||
|
}
|
||||||
err = this.ModuleBase.Start()
|
err = this.ModuleBase.Start()
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//装备组件
|
// OnInstallComp 装备组件
|
||||||
func (this *Gateway) OnInstallComp() {
|
func (this *Gateway) OnInstallComp() {
|
||||||
this.ModuleBase.OnInstallComp()
|
this.ModuleBase.OnInstallComp()
|
||||||
this.agentMgr = this.RegisterComp(new(AgentMgrComp)).(*AgentMgrComp)
|
this.agentMgr = this.RegisterComp(new(AgentMgrComp)).(*AgentMgrComp)
|
||||||
@ -75,19 +82,19 @@ func (this *Gateway) OnInstallComp() {
|
|||||||
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
||||||
}
|
}
|
||||||
|
|
||||||
//有新的连接对象进入
|
// Connect 有新的连接对象进入
|
||||||
func (this *Gateway) Connect(a IAgent) {
|
func (this *Gateway) Connect(a IAgent) {
|
||||||
log.Debugf("[Module.Gateway] have new connect:Ip[%s] SessionId:[%s]", a.IP(), a.SessionId())
|
log.Debugf("[Module.Gateway] have new connect:Ip[%s] SessionId:[%s]", a.IP(), a.SessionId())
|
||||||
this.agentMgr.Connect(a)
|
this.agentMgr.Connect(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
//有用户断开连接
|
// DisConnect 有用户断开连接
|
||||||
func (this *Gateway) DisConnect(a IAgent) {
|
func (this *Gateway) DisConnect(a IAgent) {
|
||||||
log.Debugf("[Module.Gateway] have disConnect:Ip[%s] SessionId:[%s] uid:[%s]", a.IP(), a.SessionId(), a.UserId())
|
log.Debugf("[Module.Gateway] have disConnect:Ip[%s] SessionId:[%s] uid:[%s]", a.IP(), a.SessionId(), a.UserId())
|
||||||
this.agentMgr.DisConnect(a)
|
this.agentMgr.DisConnect(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
//读取消息分发规则
|
// GetMsgDistribute 读取消息分发规则
|
||||||
func (this *Gateway) GetMsgDistribRule(mtype, stype string) (rule string, ok bool) {
|
func (this *Gateway) GetMsgDistribute(mtype, stype string) (rule string, ok bool) {
|
||||||
return this.configure.GetMsgDistribRule(mtype, stype)
|
return this.configure.GetMsgDistribute(mtype, stype)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user