gateway.modules 代码注释+格式修改

This commit is contained in:
wnp 2022-06-29 15:36:15 +08:00
parent 9558e7c4ff
commit e6f13429bf
5 changed files with 37 additions and 29 deletions

View File

@ -212,7 +212,7 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
reply := &pb.RPCMessageReply{}
log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
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
} else {
if len(this.wId) > 0 {

View File

@ -16,6 +16,7 @@ import (
/*
用户代理对象管理组件
*/
type AgentMgrComp struct {
cbase.ModuleCompBase
service base.IRPCXService

View File

@ -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 (
err error
v interface{}

View File

@ -25,6 +25,6 @@ type (
Service() base.IRPCXService
Connect(a IAgent)
DisConnect(a IAgent)
GetMsgDistribRule(mtype, stype string) (rule string, ok bool)
GetMsgDistribute(mtype, stype string) (rule string, ok bool)
}
)

View File

@ -14,6 +14,7 @@ import (
描述:提供客户端网关路由服务 管理用户socket对象 以及分发用户消息
开发:李伟
*/
func NewModule() core.IModule {
m := new(Gateway)
return m
@ -21,53 +22,59 @@ func NewModule() core.IModule {
type Gateway struct {
modules.ModuleBase
service base.IRPCXService
wsService *WSServiceComp //websocket 服务组件 提供websocket服务监听
agentMgr *AgentMgrComp //用户代理对象管理组件 管理用户socket对象
service base.IRPCXService // rpcx服务接口 主要client->server
wsService *WSServiceComp // websocket服务 监听websocket连接
agentMgr *AgentMgrComp // 客户端websocket连接管理
configure *configureComp
}
//模块名
// GetType 获取模块服务类型
func (this *Gateway) GetType() core.M_Modules {
return comm.ModuleGate
}
//模块自定义参数
// NewOptions 模块自定义参数
func (this *Gateway) NewOptions() (options core.IModuleOptions) {
return new(Options)
}
//提供服务对象获取接口
// Service 获取rpcx服务接口
func (this *Gateway) Service() base.IRPCXService {
return this.service
}
//模块初始化函数
// Init 模块初始化函数
func (this *Gateway) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
this.service = service.(base.IRPCXService)
return
}
//模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务
// Start 模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务
func (this *Gateway) Start() (err error) {
_name2Func := map[string]any{
// 注册用户绑定uid接口 登录成功后触发
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentBind), this.agentMgr.Bind)
string(comm.Rpc_GatewayAgentBind): this.agentMgr.Bind,
// 注册用户解绑uid接口 登出或则切换账号是触发
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentUnBind), this.agentMgr.UnBind)
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)
string(comm.Rpc_GatewaySendRadioMsg): this.agentMgr.SendMsgToAllAgent,
// 关闭用户socket连接接口
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentClose), this.agentMgr.CloseAgent)
string(comm.Rpc_GatewayAgentClose): this.agentMgr.CloseAgent,
}
for name, fn := range _name2Func {
this.service.RegisterFunctionName(name, fn)
}
err = this.ModuleBase.Start()
return
}
//装备组件
// OnInstallComp 装备组件
func (this *Gateway) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.agentMgr = this.RegisterComp(new(AgentMgrComp)).(*AgentMgrComp)
@ -75,19 +82,19 @@ func (this *Gateway) OnInstallComp() {
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}
//有新的连接对象进入
// Connect 有新的连接对象进入
func (this *Gateway) Connect(a IAgent) {
log.Debugf("[Module.Gateway] have new connect:Ip[%s] SessionId:[%s]", a.IP(), a.SessionId())
this.agentMgr.Connect(a)
}
//有用户断开连接
// DisConnect 有用户断开连接
func (this *Gateway) DisConnect(a IAgent) {
log.Debugf("[Module.Gateway] have disConnect:Ip[%s] SessionId:[%s] uid:[%s]", a.IP(), a.SessionId(), a.UserId())
this.agentMgr.DisConnect(a)
}
//读取消息分发规则
func (this *Gateway) GetMsgDistribRule(mtype, stype string) (rule string, ok bool) {
return this.configure.GetMsgDistribRule(mtype, stype)
// GetMsgDistribute 读取消息分发规则
func (this *Gateway) GetMsgDistribute(mtype, stype string) (rule string, ok bool) {
return this.configure.GetMsgDistribute(mtype, stype)
}