79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/core/cbase"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
/*
|
|
服务网关组件 用于接收网关服务发送过来的消息
|
|
*/
|
|
|
|
func NewMatchComp() comm.ISC_MatchComp {
|
|
comp := new(SCompMatch)
|
|
return comp
|
|
}
|
|
|
|
// 服务网关组件
|
|
type SCompMatch struct {
|
|
cbase.ServiceCompBase
|
|
options *CompOptions
|
|
service comm.IService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口
|
|
msghandles map[string]func(agrs map[string]interface{}) (err error) //处理函数的管理对象
|
|
}
|
|
|
|
// 设置服务组件名称 方便业务模块中获取此组件对象
|
|
func (this *SCompMatch) GetName() core.S_Comps {
|
|
return comm.SC_ServiceMatchComp
|
|
}
|
|
|
|
func (this *SCompMatch) NewOptions() (options core.ICompOptions) {
|
|
return new(CompOptions)
|
|
}
|
|
|
|
// 组件初始化函数
|
|
func (this *SCompMatch) Init(service core.IService, comp core.IServiceComp, options core.ICompOptions) (err error) {
|
|
err = this.ServiceCompBase.Init(service, comp, options)
|
|
this.options = options.(*CompOptions)
|
|
this.service = service.(comm.IService)
|
|
this.msghandles = make(map[string]func(agrs map[string]interface{}) (err error))
|
|
return err
|
|
}
|
|
|
|
// 组件启动时注册rpc服务监听
|
|
func (this *SCompMatch) Start() (err error) {
|
|
this.service.RegisterFunctionName(string(comm.RPC_SuccMatchNotice), this.SuccMatchNotice) //注册用户登录通知
|
|
err = this.ServiceCompBase.Start()
|
|
return
|
|
}
|
|
|
|
func (this *SCompMatch) RegisterMatchPool(poolName string, handle func(agrs map[string]interface{}) (err error)) {
|
|
this.msghandles[poolName] = handle
|
|
}
|
|
|
|
// RPC_NoticeUserClose 接收用户登录通知
|
|
func (this *SCompMatch) SuccMatchNotice(ctx context.Context, args *pb.SuccMatchNoticeReq, reply *pb.SuccMatchNoticeResp) (err error) {
|
|
msghandle, ok := this.msghandles[args.Poolname]
|
|
if ok {
|
|
var (
|
|
msg proto.Message
|
|
player map[string]interface{} = make(map[string]interface{})
|
|
)
|
|
|
|
for k, v := range args.Players {
|
|
if msg, err = v.UnmarshalNew(); err != nil {
|
|
return
|
|
}
|
|
player[k] = msg
|
|
}
|
|
//执行处理流
|
|
err = msghandle(player)
|
|
}
|
|
return nil
|
|
}
|