客户端GM控制台发送指令解析并发放资源

This commit is contained in:
meixiongfeng 2022-08-01 10:25:42 +08:00
parent 7af40d1031
commit 1e7dc159e4

View File

@ -3,10 +3,17 @@ package gm
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"strconv"
"strings"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
/* GM 在控制台输入的字符串类型
//bingo:item,10001,1
//bingo:attr,gold,1000000
*/
//参数校验 //参数校验
func (this *apiComp) CmdCheck(session comm.IUserSession, req *pb.GMCmdReq) (code pb.ErrorCode) { func (this *apiComp) CmdCheck(session comm.IUserSession, req *pb.GMCmdReq) (code pb.ErrorCode) {
if len(req.Cmod) == 0 { if len(req.Cmod) == 0 {
@ -17,17 +24,35 @@ func (this *apiComp) CmdCheck(session comm.IUserSession, req *pb.GMCmdReq) (code
///解析GM 指令 ///解析GM 指令
func (this *apiComp) Cmd(session comm.IUserSession, req *pb.GMCmdReq) (code pb.ErrorCode, data proto.Message) { func (this *apiComp) Cmd(session comm.IUserSession, req *pb.GMCmdReq) (code pb.ErrorCode, data proto.Message) {
var (
heroid string
star int32
lv int32
)
if code = this.CmdCheck(session, req); code == pb.ErrorCode_Success { if code = this.CmdCheck(session, req); code == pb.ErrorCode_Success {
return return
} }
// strings.Split(req.Cmod, "sign") keys := strings.Split(req.Cmod, ":")
this.module.ModuleHero.GetSpecifiedHero(session.GetUserId(), heroid, star, lv) if len(keys) == 2 {
if keys[0] == "bingo" {
datas := strings.Split(keys[1], ",")
if len(datas) != 3 {
num, err := strconv.Atoi(datas[2])
if err != nil {
code = pb.ErrorCode_ReqParameterError
return
}
code = this.module.DispenseRes(session, []*cfg.Game_atn{ // 添加资源
{
A: datas[0],
T: datas[1],
N: int32(num),
},
}, true)
if code == pb.ErrorCode_Success { // 成功直接返回
session.SendMsg(string(this.module.GetType()), "cmd", &pb.GMCmdResp{IsSucc: true}) session.SendMsg(string(this.module.GetType()), "cmd", &pb.GMCmdResp{IsSucc: true})
return return
}
}
}
}
//this.module.ModuleHero.GetSpecifiedHero(session.GetUserId(), heroid, star, lv)
session.SendMsg(string(this.module.GetType()), "cmd", &pb.GMCmdResp{IsSucc: false})
return
} }