Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
51c3854979
1
bin/json/game_msgdistrib.json
Normal file
1
bin/json/game_msgdistrib.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
[]
|
@ -43,15 +43,15 @@ func newAgent(gateway IGateway, conn *websocket.Conn) *Agent {
|
|||||||
|
|
||||||
//用户代理
|
//用户代理
|
||||||
type Agent struct {
|
type Agent struct {
|
||||||
gateway IGateway
|
gateway IGateway
|
||||||
wsConn *websocket.Conn
|
wsConn *websocket.Conn
|
||||||
sessionId string
|
sessionId string
|
||||||
uId string
|
uId string
|
||||||
wId string
|
wId string
|
||||||
writeChan chan *pb.UserMessage
|
writeChan chan *pb.UserMessage
|
||||||
closeSignal chan bool
|
closeSignal chan bool
|
||||||
state int32 //状态 0 关闭 1 运行 2 关闭中
|
state int32 //状态 0 关闭 1 运行 2 关闭中
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Agent) readLoop() {
|
func (this *Agent) readLoop() {
|
||||||
@ -207,7 +207,15 @@ func (this *Agent) Close() {
|
|||||||
func (this *Agent) messageDistribution(msg *pb.UserMessage) error {
|
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{
|
servicePath := comm.Service_Worker
|
||||||
|
if rule, ok := this.gateway.GetMsgDistribRule(msg.MainType, msg.SubType); ok {
|
||||||
|
servicePath = rule
|
||||||
|
} else {
|
||||||
|
if len(this.wId) > 0 {
|
||||||
|
servicePath = fmt.Sprintf("%s/%s", comm.Service_Worker, this.wId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := this.gateway.Service().RpcCall(context.Background(), servicePath, string(comm.Rpc_GatewayRoute), &pb.AgentMessage{
|
||||||
Ip: this.IP(),
|
Ip: this.IP(),
|
||||||
UserSessionId: this.sessionId,
|
UserSessionId: this.sessionId,
|
||||||
UserId: this.uId,
|
UserId: this.uId,
|
||||||
|
44
modules/gateway/configure_comp.go
Normal file
44
modules/gateway/configure_comp.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package gateway
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/modules"
|
||||||
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
|
|
||||||
|
"go_dreamfactory/lego/core"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
game_msgdistrib = "game_msgdistrib.json"
|
||||||
|
)
|
||||||
|
|
||||||
|
///背包配置管理组件
|
||||||
|
type Configure_Comp struct {
|
||||||
|
modules.MComp_Configure
|
||||||
|
}
|
||||||
|
|
||||||
|
//组件初始化接口
|
||||||
|
func (this *Configure_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
|
this.ModuleCompBase.Init(service, module, comp, options)
|
||||||
|
this.LoadConfigure(game_msgdistrib, cfg.NewGame_msgDistrib)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取消息分发规则读取配置表
|
||||||
|
func (this *Configure_Comp) GetMsgDistribRule(mtype, stype string) (rule string, ok bool) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
v interface{}
|
||||||
|
)
|
||||||
|
if v, err = this.GetConfigure(game_msgdistrib); err != nil {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
for _, v := range v.(*cfg.Game_msgDistrib).GetDataMap() {
|
||||||
|
if v.Mtype == mtype && v.Stype == stype {
|
||||||
|
rule = v.Routrules
|
||||||
|
ok = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -24,5 +24,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)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -24,6 +24,7 @@ type Gateway struct {
|
|||||||
service base.IRPCXService
|
service base.IRPCXService
|
||||||
wsservice_comp *WSService_Comp //websocket 服务组件 提供websocket服务监听
|
wsservice_comp *WSService_Comp //websocket 服务组件 提供websocket服务监听
|
||||||
agentmgr_comp *AgentMgr_Comp //用户代理对象管理组件 管理用户socekt对象
|
agentmgr_comp *AgentMgr_Comp //用户代理对象管理组件 管理用户socekt对象
|
||||||
|
configure_comp *Configure_Comp
|
||||||
}
|
}
|
||||||
|
|
||||||
//模块名
|
//模块名
|
||||||
@ -71,6 +72,7 @@ func (this *Gateway) OnInstallComp() {
|
|||||||
this.ModuleBase.OnInstallComp()
|
this.ModuleBase.OnInstallComp()
|
||||||
this.agentmgr_comp = this.RegisterComp(new(AgentMgr_Comp)).(*AgentMgr_Comp)
|
this.agentmgr_comp = this.RegisterComp(new(AgentMgr_Comp)).(*AgentMgr_Comp)
|
||||||
this.wsservice_comp = this.RegisterComp(new(WSService_Comp)).(*WSService_Comp)
|
this.wsservice_comp = this.RegisterComp(new(WSService_Comp)).(*WSService_Comp)
|
||||||
|
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
|
||||||
}
|
}
|
||||||
|
|
||||||
//有新的连接对象进入
|
//有新的连接对象进入
|
||||||
@ -84,3 +86,8 @@ 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_comp.DisConnect(a)
|
this.agentmgr_comp.DisConnect(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//读取消息分发规则
|
||||||
|
func (this *Gateway) GetMsgDistribRule(mtype, stype string) (rule string, ok bool) {
|
||||||
|
return this.configure_comp.GetMsgDistribRule(mtype, stype)
|
||||||
|
}
|
||||||
|
42
sys/configure/structs/game.msgDistrib.go
Normal file
42
sys/configure/structs/game.msgDistrib.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// This code was generated by a tool.
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
package cfg
|
||||||
|
|
||||||
|
type Game_msgDistrib struct {
|
||||||
|
_dataMap map[string]*Game_msgDistribData
|
||||||
|
_dataList []*Game_msgDistribData
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGame_msgDistrib(_buf []map[string]interface{}) (*Game_msgDistrib, error) {
|
||||||
|
_dataList := make([]*Game_msgDistribData, 0, len(_buf))
|
||||||
|
dataMap := make(map[string]*Game_msgDistribData)
|
||||||
|
for _, _ele_ := range _buf {
|
||||||
|
if _v, err2 := NewGame_msgDistribData(_ele_); err2 != nil {
|
||||||
|
return nil, err2
|
||||||
|
} else {
|
||||||
|
_dataList = append(_dataList, _v)
|
||||||
|
dataMap[_v.Mtype] = _v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &Game_msgDistrib{_dataList:_dataList, _dataMap:dataMap}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (table *Game_msgDistrib) GetDataMap() map[string]*Game_msgDistribData {
|
||||||
|
return table._dataMap
|
||||||
|
}
|
||||||
|
|
||||||
|
func (table *Game_msgDistrib) GetDataList() []*Game_msgDistribData {
|
||||||
|
return table._dataList
|
||||||
|
}
|
||||||
|
|
||||||
|
func (table *Game_msgDistrib) Get(key string) *Game_msgDistribData {
|
||||||
|
return table._dataMap[key]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
29
sys/configure/structs/game.msgDistribData.go
Normal file
29
sys/configure/structs/game.msgDistribData.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// This code was generated by a tool.
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
package cfg
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
type Game_msgDistribData struct {
|
||||||
|
Mtype string
|
||||||
|
Stype string
|
||||||
|
Routrules string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Game_msgDistribData) GetTypeId() int {
|
||||||
|
return -758961622
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGame_msgDistribData(_buf map[string]interface{}) (_v *Game_msgDistribData, err error) {
|
||||||
|
_v = &Game_msgDistribData{}
|
||||||
|
{ var _ok_ bool; if _v.Mtype, _ok_ = _buf["mtype"].(string); !_ok_ { err = errors.New("mtype error"); return } }
|
||||||
|
{ var _ok_ bool; if _v.Stype, _ok_ = _buf["stype"].(string); !_ok_ { err = errors.New("stype error"); return } }
|
||||||
|
{ var _ok_ bool; if _v.Routrules, _ok_ = _buf["routrules"].(string); !_ok_ { err = errors.New("routrules error"); return } }
|
||||||
|
return
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user