561 lines
17 KiB
Go
561 lines
17 KiB
Go
package gm
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/base"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
/*
|
|
模块名:GM工具模块
|
|
描述:处理客户端发过来的gm命令
|
|
开发:梅雄风
|
|
*/
|
|
func NewModule() core.IModule {
|
|
m := new(GM)
|
|
return m
|
|
}
|
|
|
|
type GM struct {
|
|
modules.ModuleBase
|
|
api_comp *apiComp
|
|
service base.IRPCXService
|
|
configure *configureComp
|
|
}
|
|
|
|
// 模块名
|
|
func (this *GM) GetType() core.M_Modules {
|
|
return comm.ModuleGM
|
|
}
|
|
|
|
// 模块初始化接口 注册用户创建角色事件
|
|
func (this *GM) 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 *GM) Start() (err error) {
|
|
err = this.ModuleBase.Start()
|
|
this.service.RegisterFunctionName(string(comm.Rpc_ModuleGMCreateCmd), this.Rpc_ModuleGMCreateCmd)
|
|
return
|
|
}
|
|
|
|
// 装备组件
|
|
func (this *GM) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
// bingo:Iamyoudad
|
|
func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (errdata *pb.ErrorData) {
|
|
|
|
cmd = strings.Replace(cmd, " ", "", -1) // 去空格
|
|
keys := strings.Split(cmd, ":")
|
|
if len(keys) == 2 {
|
|
if keys[0] == "bingo" {
|
|
this.Debugf("create CMD :%s", cmd) // 打印个日志方便查询
|
|
datas := strings.Split(keys[1], ",")
|
|
if len(datas) == 3 && (datas[0] == comm.AttrType || datas[0] == comm.ItemType ||
|
|
datas[0] == comm.HeroType || datas[0] == comm.EquipmentType || datas[0] == comm.VipType || datas[0] == comm.AtlasType || datas[0] == comm.PandaType || datas[0] == comm.MountsType) {
|
|
num, err := strconv.Atoi(datas[2])
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
errdata = this.DispenseRes(session, []*cfg.Gameatn{ // 添加资源
|
|
{
|
|
A: datas[0],
|
|
T: datas[1],
|
|
N: int32(num),
|
|
},
|
|
}, true)
|
|
if errdata == nil { // 成功直接返回
|
|
session.SendMsg(string(this.GetType()), "cmd", &pb.GMCmdResp{IsSucc: true})
|
|
}
|
|
this.Debug("使用bingo命令",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "A", Value: datas[0]},
|
|
log.Field{Key: "T", Value: datas[1]},
|
|
log.Field{Key: "N", Value: int32(num)},
|
|
)
|
|
} else if len(datas) == 3 && (datas[0] == "pataid") {
|
|
module1, err := this.service.GetModule(comm.ModulePagoda)
|
|
if err != nil {
|
|
return
|
|
}
|
|
d1, err := strconv.Atoi(datas[1])
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
d2, err := strconv.Atoi(datas[2])
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
errdata = module1.(comm.IPagoda).ModifyPagodaFloor(session, int32(d1), int32(d2))
|
|
this.Debug("使用bingo命令:uid = %s ",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "p0", Value: datas[0]},
|
|
log.Field{Key: "p1", Value: datas[1]},
|
|
log.Field{Key: "p3", Value: datas[2]},
|
|
)
|
|
} else if len(datas) == 1 && (datas[0] == "Iamyoudad" || datas[0] == "iamyoudad") {
|
|
var (
|
|
res []*cfg.Gameatn
|
|
)
|
|
|
|
equip := this.configure.GetAllEquipmentConfigure()
|
|
for _, v1 := range equip {
|
|
|
|
res = append(res, &cfg.Gameatn{
|
|
A: "equi",
|
|
T: v1.Id,
|
|
N: 5,
|
|
})
|
|
}
|
|
data := this.configure.GetHeroConfigData()
|
|
for _, v := range data {
|
|
if v.Handbook != -1 {
|
|
res = append(res, &cfg.Gameatn{
|
|
A: "hero",
|
|
T: v.Hid,
|
|
N: 1,
|
|
})
|
|
}
|
|
}
|
|
// 发所有道具
|
|
item := this.configure.GetAllItemConfigure()
|
|
for _, v := range item {
|
|
if v.Bagtype != 0 {
|
|
res = append(res, &cfg.Gameatn{
|
|
A: "item",
|
|
T: v.Id,
|
|
N: 100,
|
|
})
|
|
}
|
|
}
|
|
errdata = this.DispenseRes(session, res, true)
|
|
if errdata != nil {
|
|
this.Errorf("资源发放失败,%v", errdata)
|
|
}
|
|
this.Debug("使用bingo命令",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "param", Value: datas[0]},
|
|
log.Field{Key: "res", Value: res},
|
|
)
|
|
} else if len(datas) == 3 && (datas[0] == "worldtask") {
|
|
module, err := this.service.GetModule(comm.ModuleWorldtask)
|
|
if err != nil {
|
|
return
|
|
}
|
|
if wt, ok := module.(comm.IWorldtask); ok {
|
|
if err = wt.BingoJumpTask(session, utils.ToInt32(datas[1]), utils.ToInt32(datas[2])); err != nil {
|
|
this.Error("bingo 世界任务",
|
|
log.Field{Key: "params", Value: datas},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
}
|
|
}
|
|
} else if len(datas) == 2 && (datas[0] == "worldtask") {
|
|
module, err := this.service.GetModule(comm.ModuleWorldtask)
|
|
if err != nil {
|
|
return
|
|
}
|
|
if wt, ok := module.(comm.IWorldtask); ok {
|
|
if err = wt.JumpTaskByTaskId(session, utils.ToInt32(datas[1])); err != nil {
|
|
this.Error("bingo 世界任务",
|
|
log.Field{Key: "params", Value: datas},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
}
|
|
}
|
|
} else if len(datas) == 1 && (datas[0] == "manhero") { // 获取满星、等级、觉醒、共鸣技能
|
|
module1, err := this.service.GetModule(comm.ModuleHero)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
errdata = module1.(comm.IHero).GetAllMaxHero(session)
|
|
this.Debug("使用bingo命令:uid = %s ",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[0]},
|
|
)
|
|
} else if len(datas) == 2 && (datas[0] == "season") { // 赛季塔跳转
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
}
|
|
return
|
|
} else if len(datas) == 1 && (datas[0] == "viking") { // 解锁远征所有难度
|
|
module1, err := this.service.GetModule(comm.ModuleViking)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
errdata = module1.(comm.IViking).CompleteAllLevel(session)
|
|
this.Debug("使用bingo命令:uid = %s ", log.Field{Key: "uid", Value: session.GetUserId()})
|
|
} else if len(datas) == 1 && (datas[0] == "hunting") { // 解锁狩猎所有难度
|
|
module1, err := this.service.GetModule(comm.ModuleHunting)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
errdata = module1.(comm.IHunting).CompleteAllLevel(session)
|
|
this.Debug("使用bingo命令:uid = %s ",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[0]})
|
|
} else if len(datas) == 2 && (datas[0] == "mainline") {
|
|
module1, err := this.service.GetModule(comm.ModuleMline)
|
|
if err != nil {
|
|
return
|
|
}
|
|
num1, err := strconv.Atoi(datas[1])
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
errdata = module1.(comm.IMline).ModifyMlineDataByNanduID(session, int32(num1))
|
|
|
|
this.Debug("使用bingo命令",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[1]},
|
|
)
|
|
} else if len(datas) == 2 && (datas[0] == "moon") { // 触发月之秘境
|
|
module1, err := this.service.GetModule(comm.ModuleMoonfantasy)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
module1.(comm.IMoonFantasy).TriggerMF(session, datas[1])
|
|
|
|
this.Debug("使用bingo命令",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[1]},
|
|
)
|
|
} else if len(datas) == 2 && (datas[0] == "arena") { // 设置竞技场用户积分
|
|
module1, err := this.service.GetModule(comm.ModuleArena)
|
|
if err != nil {
|
|
return
|
|
}
|
|
num, err := strconv.Atoi(datas[1])
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
module1.(comm.IArena).SetUserIntegral(session, int32(num))
|
|
this.Debug("使用bingo命令",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[1]},
|
|
)
|
|
} else if len(datas) == 2 && (datas[0] == "sociatyexp") { // 设置工会经验
|
|
module1, err := this.service.GetModule(comm.ModuleSociaty)
|
|
if err != nil {
|
|
return
|
|
}
|
|
num, err := strconv.Atoi(datas[1])
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
module1.(comm.ISociaty).BingoSetExp(session, int32(num))
|
|
this.Debug("使用bingo命令",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[1]},
|
|
)
|
|
} else if len(datas) == 2 && (datas[0] == "sociatyactivity") { // 设置工会活跃度
|
|
module1, err := this.service.GetModule(comm.ModuleSociaty)
|
|
if err != nil {
|
|
return
|
|
}
|
|
num, err := strconv.Atoi(datas[1])
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
module1.(comm.ISociaty).BingoSetActivity(session, int32(num))
|
|
this.Debug("使用bingo命令",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[1]},
|
|
)
|
|
} else if len(datas) == 1 && (datas[0] == "allgrowtask") { // 完成所有成长任务
|
|
module, err := this.service.GetModule(comm.ModuleGrowtask)
|
|
if err != nil {
|
|
return
|
|
}
|
|
if wt, ok := module.(comm.IGrowtask); ok {
|
|
if err = wt.BingoAllGrowTask(session); err != nil {
|
|
this.Error("bingo 成长任务",
|
|
log.Field{Key: "param", Value: datas},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
}
|
|
}
|
|
|
|
} else if len(datas) == 1 && (datas[0] == "allhero") { // 完成所有世界任务
|
|
var (
|
|
res []*cfg.Gameatn
|
|
)
|
|
data := this.configure.GetHeroConfigData()
|
|
for _, v := range data {
|
|
if v.Handbook != -1 {
|
|
res = append(res, &cfg.Gameatn{
|
|
A: "hero",
|
|
T: v.Hid,
|
|
N: 1,
|
|
})
|
|
}
|
|
}
|
|
errdata = this.DispenseRes(session, res, true)
|
|
if errdata != nil {
|
|
this.Errorf("资源发放失败,%v", errdata)
|
|
}
|
|
this.Debug("使用bingo命令",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "param", Value: datas[0]},
|
|
log.Field{Key: "res", Value: res},
|
|
)
|
|
} else if len(datas) == 2 && (datas[0] == "lv") { // 玩家等级
|
|
module1, err := this.service.GetModule(comm.ModuleUser)
|
|
if err != nil {
|
|
return
|
|
}
|
|
num, err := strconv.Atoi(datas[1])
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if err = module1.(comm.IUser).BingoSetUserLv(session, int32(num)); err == nil {
|
|
}
|
|
this.Debug("使用bingo命令:uid = %s ",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[0]},
|
|
log.Field{Key: "N", Value: int32(num)},
|
|
)
|
|
} else if len(datas) == 2 && (datas[0] == "recharge") { // 充值次数
|
|
module1, err := this.service.GetModule(comm.ModulePay)
|
|
if err != nil {
|
|
return
|
|
}
|
|
num, err := strconv.Atoi(datas[1])
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
for i := 0; i < num; i++ {
|
|
if errdata = module1.(comm.IPay).ModulePayDelivery(session, "8", 64800); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
this.Debug("使用bingo命令:uid = %s ",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[0]},
|
|
log.Field{Key: "N", Value: int32(num)},
|
|
)
|
|
} else if len(datas) == 1 && (datas[0] == "cleanitem") { // 充值次数
|
|
module1, err := this.service.GetModule(comm.ModuleItems)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if errdata = module1.(comm.IItems).CleanItems(session); errdata != nil {
|
|
return
|
|
}
|
|
|
|
this.Debug("使用bingo命令:uid = %s ",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[0]},
|
|
)
|
|
} else if len(datas) == 1 && (datas[0] == "allequip") { // 充值次数
|
|
module1, err := this.service.GetModule(comm.ModuleEquipment)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if errdata = module1.(comm.IEquipment).AddAllEquipments(session); errdata != nil {
|
|
return
|
|
}
|
|
|
|
this.Debug("使用bingo命令:uid = %s ",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[0]},
|
|
)
|
|
} else if len(datas) == 2 && (datas[0] == "chat") {
|
|
|
|
if module, err := this.service.GetModule(comm.ModuleChat); err == nil {
|
|
if errdata = module.(comm.IChat).SendSysChatToWorld(comm.ChatSystem10, nil, 5, 0, "xxx", "25001"); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
this.Debug("使用bingo命令:uid = %s ",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[0]},
|
|
)
|
|
} else if len(datas) == 3 && (datas[0] == "itemtype") {
|
|
num1, err := strconv.Atoi(datas[1])
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
num2, err := strconv.Atoi(datas[2])
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
_data := this.configure.GetItemConfigureByType(int32(num1))
|
|
for _, v := range _data {
|
|
res := &cfg.Gameatn{
|
|
A: "item",
|
|
T: v.Id,
|
|
N: int32(num2),
|
|
}
|
|
if errdata = this.DispenseRes(session, []*cfg.Gameatn{res}, true); errdata != nil {
|
|
this.Debugf("DispenseRes err :uid = %s,code = %d", datas[0], errdata)
|
|
}
|
|
}
|
|
this.Debug("使用bingo命令:uid = %s ",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[0]},
|
|
log.Field{Key: "1", Value: datas[1]},
|
|
log.Field{Key: "2", Value: datas[2]},
|
|
)
|
|
} else if len(datas) == 2 && (datas[0] == "viplv") { // 玩家等级
|
|
module1, err := this.service.GetModule(comm.ModuleUser)
|
|
if err != nil {
|
|
return
|
|
}
|
|
num, err := strconv.Atoi(datas[1])
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if errdata = module1.(comm.IUser).BingoSetUserVipLv(session, int32(num)); errdata != nil {
|
|
return
|
|
}
|
|
this.Debug("使用bingo命令:uid = %s ",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[0]},
|
|
log.Field{Key: "N", Value: int32(num)},
|
|
)
|
|
} else if len(datas) == 1 && (datas[0] == "cleannpc") { // 充值次数
|
|
module1, err := this.service.GetModule(comm.ModulePractice)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
module1.(comm.IPractice).CleanUpNpc(session.GetUserId())
|
|
|
|
this.Debug("使用bingo命令:uid = %s ",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "0", Value: datas[0]},
|
|
)
|
|
} else if len(datas) == 1 && (datas[0] == "jx") {
|
|
module, err := this.service.GetModule(comm.ModulePractice)
|
|
if err != nil {
|
|
return
|
|
}
|
|
var res []*cfg.Gameatn
|
|
if wt, ok := module.(comm.IPractice); ok {
|
|
if r, err := wt.GetAllJxRes(); err == nil {
|
|
for _, v1 := range r {
|
|
res = append(res, &cfg.Gameatn{
|
|
A: "panda",
|
|
T: v1,
|
|
N: 1,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
errdata = this.DispenseRes(session, res, true)
|
|
if errdata != nil {
|
|
this.Errorf("资源发放失败,%v", errdata)
|
|
}
|
|
this.Debug("使用bingo命令",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "param", Value: datas[0]},
|
|
log.Field{Key: "res", Value: res},
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (this *GM) Rpc_ModuleGMCreateCmd(ctx context.Context, args *pb.RPCGeneralReqA2, reply *pb.EmptyResp) (err error) {
|
|
this.Debug("Rpc_ModuleGMCreateCmd", log.Field{Key: "args", Value: args.String()})
|
|
|
|
if args.Param1 == "" || args.Param2 == "" {
|
|
err = errors.New("请求参数错误")
|
|
return
|
|
}
|
|
var (
|
|
session comm.IUserSession
|
|
ok bool
|
|
)
|
|
defer func() {
|
|
this.PutUserSession(session)
|
|
}()
|
|
if session, ok = this.GetUserSession(args.Param1); !ok {
|
|
err = fmt.Errorf("目标用户:%s 不在线", args.Param1)
|
|
return
|
|
} else {
|
|
this.CreateCmd(session, args.Param2)
|
|
session.Push()
|
|
}
|
|
return
|
|
}
|