155 lines
4.3 KiB
Go
155 lines
4.3 KiB
Go
package matchpool
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/core/cbase"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
/*
|
|
模块名:匹配池
|
|
开发:李伟
|
|
描述:集合项目中所有匹配玩法
|
|
*/
|
|
type MatchPool struct {
|
|
cbase.ModuleBase
|
|
options *Options
|
|
service comm.IService
|
|
pools *poolsComp
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &MatchPool{}
|
|
}
|
|
|
|
func (this *MatchPool) GetType() core.M_Modules {
|
|
return comm.ModuleMatchPool
|
|
}
|
|
|
|
// NewOptions 模块自定义参数
|
|
func (this *MatchPool) NewOptions() (options core.IModuleOptions) {
|
|
return new(Options)
|
|
}
|
|
|
|
func (this *MatchPool) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
if err = this.ModuleBase.Init(service, module, options); err != nil {
|
|
return
|
|
}
|
|
this.service = service.(comm.IService)
|
|
this.options = options.(*Options)
|
|
return
|
|
}
|
|
|
|
func (this *MatchPool) Start() (err error) {
|
|
if err = this.ModuleBase.Start(); err != nil {
|
|
return
|
|
}
|
|
this.service.RegisterFunctionName(string(comm.RPC_JoinMatchPools), this.JoinMatchPools)
|
|
this.service.RegisterFunctionName(string(comm.RPC_CancelMatch), this.CancelMatch)
|
|
return
|
|
}
|
|
|
|
func (this *MatchPool) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.pools = this.RegisterComp(new(poolsComp)).(*poolsComp)
|
|
}
|
|
|
|
//加入匹配池
|
|
func (this *MatchPool) JoinMatchPools(ctx context.Context, req *pb.JoinMatchPoolReq, resp *pb.JoinMatchPoolResp) (err error) {
|
|
this.Debug("JoinMatchPools", log.Field{Key: "req", Value: req.String()})
|
|
this.pools.joinPools(req)
|
|
return
|
|
}
|
|
|
|
//取消匹配
|
|
func (this *MatchPool) CancelMatch(ctx context.Context, req *pb.CancelMatchReq, resp *pb.CancelMatchResp) (err error) {
|
|
this.Debug("CancelMatch", log.Field{Key: "req", Value: req.String()})
|
|
this.pools.cancelMatch(req)
|
|
return
|
|
}
|
|
|
|
func (this *MatchPool) MatchNotice(req *pb.SuccMatchNoticeReq) {
|
|
var (
|
|
err error
|
|
)
|
|
if err = this.service.RpcCall(context.Background(),
|
|
comm.Service_Worker,
|
|
string(comm.RPC_SuccMatchNotice),
|
|
req,
|
|
&pb.RPCParkourMatchSuccResp{},
|
|
); err != nil {
|
|
this.Error("MatchNotice err!", log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
}
|
|
|
|
// 日志接口
|
|
func (this *MatchPool) Debug(msg string, args ...log.Field) {
|
|
this.options.GetLog().Debug(msg, args...)
|
|
}
|
|
func (this *MatchPool) Info(msg string, args ...log.Field) {
|
|
this.options.GetLog().Info(msg, args...)
|
|
}
|
|
func (this *MatchPool) Print(msg string, args ...log.Field) {
|
|
this.options.GetLog().Print(msg, args...)
|
|
}
|
|
func (this *MatchPool) Warn(msg string, args ...log.Field) {
|
|
this.options.GetLog().Warn(msg, args...)
|
|
}
|
|
func (this *MatchPool) Error(msg string, args ...log.Field) {
|
|
this.options.GetLog().Error(msg, args...)
|
|
}
|
|
func (this *MatchPool) Panic(msg string, args ...log.Field) {
|
|
this.options.GetLog().Panic(msg, args...)
|
|
}
|
|
func (this *MatchPool) Fatal(msg string, args ...log.Field) {
|
|
this.options.GetLog().Fatal(msg, args...)
|
|
}
|
|
|
|
func (this *MatchPool) Debugf(format string, args ...interface{}) {
|
|
this.options.GetLog().Debugf(format, args...)
|
|
}
|
|
func (this *MatchPool) Infof(format string, args ...interface{}) {
|
|
this.options.GetLog().Infof(format, args...)
|
|
}
|
|
func (this *MatchPool) Printf(format string, args ...interface{}) {
|
|
this.options.GetLog().Printf(format, args...)
|
|
}
|
|
func (this *MatchPool) Warnf(format string, args ...interface{}) {
|
|
this.options.GetLog().Warnf(format, args...)
|
|
}
|
|
func (this *MatchPool) Errorf(format string, args ...interface{}) {
|
|
this.options.GetLog().Errorf(format, args...)
|
|
}
|
|
func (this *MatchPool) Fatalf(format string, args ...interface{}) {
|
|
this.options.GetLog().Fatalf(format, args...)
|
|
}
|
|
func (this *MatchPool) Panicf(format string, args ...interface{}) {
|
|
this.options.GetLog().Panicf(format, args...)
|
|
}
|
|
|
|
func (this *MatchPool) Debugln(args ...interface{}) {
|
|
this.options.GetLog().Debugln(args...)
|
|
}
|
|
func (this *MatchPool) Infoln(args ...interface{}) {
|
|
this.options.GetLog().Infoln(args...)
|
|
}
|
|
func (this *MatchPool) Println(args ...interface{}) {
|
|
this.options.GetLog().Println(args...)
|
|
}
|
|
func (this *MatchPool) Warnln(args ...interface{}) {
|
|
this.options.GetLog().Warnln(args...)
|
|
}
|
|
func (this *MatchPool) Errorln(args ...interface{}) {
|
|
this.options.GetLog().Errorln(args...)
|
|
}
|
|
func (this *MatchPool) Fatalln(args ...interface{}) {
|
|
this.options.GetLog().Fatalln(args...)
|
|
}
|
|
func (this *MatchPool) Panicln(args ...interface{}) {
|
|
this.options.GetLog().Panicln(args...)
|
|
}
|