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) (code pb.ErrorCode) { code = pb.ErrorCode_ReqParameterError 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) { num, err := strconv.Atoi(datas[2]) if err != nil { code = pb.ErrorCode_ReqParameterError return } code = this.DispenseRes(session, []*cfg.Gameatn{ // 添加资源 { A: datas[0], T: datas[1], N: int32(num), }, }, true) if code == pb.ErrorCode_Success { // 成功直接返回 session.SendMsg(string(this.GetType()), "cmd", &pb.GMCmdResp{IsSucc: true}) } this.Debug("使用bingo命令", log.Field{"uid", session.GetUserId()}, log.Field{"A", datas[0]}, log.Field{"T", datas[1]}, log.Field{"N", int32(num)}) } else if len(datas) == 2 && (datas[0] == "mapid") { module1, err := this.service.GetModule(comm.ModuleMainline) if err != nil { return } num, err := strconv.Atoi(datas[1]) if err != nil { code = pb.ErrorCode_ReqParameterError return } code = module1.(comm.IMainline).ModifyMainlineData(session.GetUserId(), int32(num)) this.Debug("使用bingo命令", log.Field{"uid", session.GetUserId()}, log.Field{"0", datas[0]}, log.Field{"N", int32(num)}) } else if len(datas) == 2 && (datas[0] == "pataid") { module1, err := this.service.GetModule(comm.ModulePagoda) if err != nil { return } num, err := strconv.Atoi(datas[1]) if err != nil { code = pb.ErrorCode_ReqParameterError return } code = module1.(comm.IPagoda).ModifyPagodaFloor(session, int32(num)) this.Debug("使用bingo命令:uid = %s ", log.Field{"uid", session.GetUserId()}, log.Field{"0", datas[0]}, log.Field{"N", int32(num)}) } else if len(datas) == 1 && (datas[0] == "Iamyoudad" || datas[0] == "iamyoudad") { var ( res []*cfg.Gameatn ) if val, err := this.configure.GetYouDaddyConf(); err == nil { for _, v := range val.GetDataList() { res = append(res, v.Var...) } code = this.DispenseRes(session, res, true) if code != pb.ErrorCode_Success { this.Errorf("资源发放失败,%v", code) } } this.Debugf("使用bingo命令", log.Field{"uid", session.GetUserId()}, datas[0], 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.Errorf("bingo worldTask Failed ,Parameter :%s,%s %v", datas[1], datas[2], err) } } } } } 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("请求参数错误") } if session, ok := this.GetUserSession(args.Param1); !ok { err = fmt.Errorf("目标用户:%s 不在线", args.Param1) return } else { this.CreateCmd(session, args.Param2) session.Push() } return }