159 lines
4.0 KiB
Go
159 lines
4.0 KiB
Go
package sys
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/base"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"time"
|
|
)
|
|
|
|
var _ comm.ISys = (*ModuleSys)(nil)
|
|
|
|
type ModuleSys struct {
|
|
modules.ModuleBase
|
|
api *apiComp
|
|
configure *configureComp
|
|
service base.IRPCXService
|
|
modelSys *ModelSys
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &ModuleSys{}
|
|
}
|
|
|
|
func (this *ModuleSys) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelSys = this.RegisterComp(new(ModelSys)).(*ModelSys)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
//模块初始化
|
|
func (this *ModuleSys) 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
|
|
}
|
|
|
|
func (this *ModuleSys) Start() (err error) {
|
|
err = this.ModuleBase.Start()
|
|
this.service.RegisterFunctionName(string(comm.Rpc_OpendCond), this.OpenCond)
|
|
return
|
|
}
|
|
|
|
func (this *ModuleSys) GetType() core.M_Modules {
|
|
return comm.ModuleSys
|
|
}
|
|
|
|
func (this *ModuleSys) IsAccess(funcName string, userId string) (errdata *pb.ErrorData) {
|
|
return this.modelSys.IsAccess(funcName, userId)
|
|
}
|
|
|
|
func (this *ModuleSys) ValidCond(uid string, conf *cfg.GameOpencondData) string {
|
|
return this.modelSys.validCond(uid, conf)
|
|
}
|
|
|
|
func (this *ModuleSys) CheckLvUpCond(session comm.IUserSession, lv int32) {
|
|
if cond := this.configure.GetOpencondLv(lv); len(cond) > 0 {
|
|
this.AutoActivate(session, cond)
|
|
}
|
|
}
|
|
|
|
func (this *ModuleSys) CheckMlineCond(session comm.IUserSession, id int32) {
|
|
if cond := this.configure.getOpencondMline(id); len(cond) > 0 {
|
|
this.AutoActivate(session, cond)
|
|
}
|
|
}
|
|
|
|
func (this *ModuleSys) CheckFriendCond(session comm.IUserSession, id int32) {
|
|
if cond := this.configure.getFriendTask(id); len(cond) > 0 {
|
|
this.AutoActivate(session, cond)
|
|
}
|
|
}
|
|
func (this *ModuleSys) CheckTaskCond(session comm.IUserSession, num int32) {
|
|
if cond := this.configure.getOpencondTask(num); len(cond) > 0 {
|
|
// 通知本服
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
|
|
_, err := this.service.RpcGo(
|
|
ctx,
|
|
comm.Service_Worker,
|
|
string(comm.Rpc_OpendCond),
|
|
&pb.RPCFriendNumReq{Uid: session.GetUserId(), Cond: cond},
|
|
nil)
|
|
if err != nil {
|
|
this.Errorln(err)
|
|
return
|
|
}
|
|
this.AutoActivate(session, cond)
|
|
}
|
|
}
|
|
|
|
// 自动激活
|
|
func (this *ModuleSys) AutoActivate(session comm.IUserSession, cids []string) bool {
|
|
var (
|
|
szOpen []string
|
|
)
|
|
list, _ := this.modelSys.GetOpenCondList(session.GetUserId())
|
|
for _, cid := range cids {
|
|
opencfg := this.configure.getOpencondCfgByCid(cid)
|
|
if opencfg == nil {
|
|
continue
|
|
}
|
|
if id := this.modelSys.validCond(session.GetUserId(), opencfg); id == "" { // 条件不满足
|
|
continue
|
|
} else {
|
|
if _, ok := list.Cond[cid]; !ok {
|
|
list.Cond[cid] = 1
|
|
szOpen = append(szOpen, cid)
|
|
}
|
|
}
|
|
|
|
}
|
|
if len(szOpen) > 0 {
|
|
this.modelSys.ChangeOpenCondData(session.GetUserId(), map[string]interface{}{
|
|
"cond": list.Cond,
|
|
})
|
|
}
|
|
// 推送变化
|
|
session.SendMsg(string(this.GetType()), "open", &pb.SysFuncOpnePush{
|
|
Cid: szOpen,
|
|
})
|
|
return true
|
|
}
|
|
|
|
// 功能开启条件校验
|
|
func (this *ModuleSys) CheckOpenCondCfgById(uid string, id string) (bOpen bool, errdata *pb.ErrorData) {
|
|
|
|
conf, err := this.configure.GetOpenCondCfgById(id)
|
|
if err != nil {
|
|
bOpen = false
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if this.ValidCond(uid, conf) != "" {
|
|
bOpen = true
|
|
}
|
|
return
|
|
}
|
|
func (this *ModuleSys) OpenCond(ctx context.Context, req *pb.RPCFriendNumReq, resp interface{}) (err error) {
|
|
if session, ok := this.GetUserSession(req.Uid); ok {
|
|
this.AutoActivate(session, req.Cond)
|
|
if err = session.Push(); err != nil {
|
|
this.Errorln(err)
|
|
}
|
|
this.PutUserSession(session)
|
|
} else {
|
|
this.PutUserSession(session)
|
|
}
|
|
|
|
return
|
|
}
|