114 lines
3.0 KiB
Go
114 lines
3.0 KiB
Go
package gameinvite
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/event"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
type GameInvite struct {
|
|
modules.ModuleBase
|
|
service comm.IService
|
|
api *apiComp
|
|
model *modelComp
|
|
pvp comm.IPvp
|
|
dcolor comm.IDColor
|
|
caninerabbit comm.ICanineRabbit
|
|
catchBugs comm.ICatchBugs
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &GameInvite{}
|
|
}
|
|
|
|
func (this *GameInvite) GetType() core.M_Modules {
|
|
return comm.ModuleGameInvite
|
|
}
|
|
|
|
func (this *GameInvite) 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)
|
|
return
|
|
}
|
|
|
|
func (this *GameInvite) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.model = this.RegisterComp(new(modelComp)).(*modelComp)
|
|
}
|
|
func (this *GameInvite) Start() (err error) {
|
|
if err = this.ModuleBase.Start(); err != nil {
|
|
return
|
|
}
|
|
var module core.IModule
|
|
if module, err = this.service.GetModule(comm.ModulePvp); err != nil {
|
|
return
|
|
}
|
|
this.pvp = module.(comm.IPvp)
|
|
if module, err = this.service.GetModule(comm.ModuleDcolor); err != nil {
|
|
return
|
|
}
|
|
this.dcolor = module.(comm.IDColor)
|
|
if module, err = this.service.GetModule(comm.ModuleCanineRabbit); err != nil {
|
|
return
|
|
}
|
|
this.caninerabbit = module.(comm.ICanineRabbit)
|
|
if module, err = this.service.GetModule(comm.ModuleCatchbugs); err != nil {
|
|
return
|
|
}
|
|
this.catchBugs = module.(comm.ICatchBugs)
|
|
this.service.RegisterFunctionName(string(comm.RPC_GameinviteOffline), this.trusteeship)
|
|
event.RegisterGO(comm.EventUserOffline, this.Useroffline)
|
|
return
|
|
}
|
|
func (this *GameInvite) GameInviteEnd(gtype int32, uid string) {
|
|
this.model.endQiecuo(gtype, uid)
|
|
}
|
|
|
|
// 用户离线处理
|
|
func (this *GameInvite) Useroffline(uid, sessionid string) {
|
|
var (
|
|
info *pb.GameInviteQiecuoRecord
|
|
spath string = fmt.Sprintf("%s/%s", this.service.GetType(), this.service.GetId())
|
|
err error
|
|
)
|
|
if info, err = this.model.queryQiecuo(uid); err != nil {
|
|
return
|
|
}
|
|
if info.Status == 1 {
|
|
if info.Spath == spath {
|
|
this.trusteeship(context.Background(), &pb.RPC_GameInviteOfflineReq{Gtype: info.Gtype, Roomid: info.Roomid, Offuid: uid}, &pb.RPC_GameInviteOfflineResp{})
|
|
} else {
|
|
err = this.service.RpcCall(
|
|
context.Background(),
|
|
spath,
|
|
string(comm.RPC_GameinviteOffline),
|
|
&pb.RPC_GameInviteOfflineReq{Gtype: info.Gtype, Roomid: info.Roomid, Offuid: uid},
|
|
&pb.RPC_GameInviteOfflineResp{})
|
|
if err != nil {
|
|
this.Errorln(err)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 用户离线处理
|
|
func (this *GameInvite) trusteeship(ctx context.Context, req *pb.RPC_GameInviteOfflineReq, resp *pb.RPC_GameInviteOfflineResp) (err error) {
|
|
switch req.Gtype {
|
|
case 1:
|
|
err = this.pvp.UserOffline(req.Roomid, req.Offuid)
|
|
case 2:
|
|
err = this.caninerabbit.UserOffline(req.Roomid, req.Offuid)
|
|
case 3:
|
|
err = this.dcolor.UserOffline(req.Roomid, req.Offuid)
|
|
}
|
|
return
|
|
}
|