238 lines
5.5 KiB
Go
238 lines
5.5 KiB
Go
package handler
|
|
|
|
import (
|
|
"ecs/proto"
|
|
"ecs/proto/pb"
|
|
"ecs/servers/game/logic"
|
|
"github.com/oylshe1314/framework/net"
|
|
"github.com/oylshe1314/framework/profile"
|
|
"github.com/oylshe1314/framework/util"
|
|
"regexp"
|
|
"strconv"
|
|
)
|
|
|
|
func (this *PlayerHandler) GmCommand(player *logic.Player, msg *net.Message) {
|
|
if profile.Active == profile.ActiveProd {
|
|
this.logger.Errorf("GM command was disabled in environment 'prod', userId: %d, roleId: %d", player.UserId, player.RoleId)
|
|
return
|
|
}
|
|
|
|
var req = new(pb.GmCommandReq)
|
|
var err = msg.Read(req)
|
|
if err != nil {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
if len(req.Command) == 0 {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
var re = regexp.MustCompile("\\s+")
|
|
var ss = re.Split(req.Command, -1)
|
|
cmd, args := ss[0], ss[1:]
|
|
|
|
switch cmd {
|
|
case "money", "exp", "power", "coin", "gold":
|
|
if len(args) < 1 {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
var moneyType pb.MoneyType
|
|
switch cmd {
|
|
case "money":
|
|
if len(args) < 2 {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
val, err := strconv.Atoi(args[0])
|
|
if err != nil {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
moneyType = pb.MoneyType(val)
|
|
args = args[1:]
|
|
case "exp":
|
|
moneyType = pb.MoneyType_Exp
|
|
case "power":
|
|
moneyType = pb.MoneyType_Power
|
|
case "coin":
|
|
moneyType = pb.MoneyType_Coin
|
|
case "gold":
|
|
moneyType = pb.MoneyType_Gold
|
|
}
|
|
|
|
if args[0] == "clear" {
|
|
var money = player.GetMoney(moneyType)
|
|
|
|
money.Value = 0
|
|
player.SaveModel(money)
|
|
|
|
_ = player.Send(pb.ModId_ModuleRole, pb.MsgId_ModRoleMoneyChange, &pb.MoneyListAck{MoneyList: []*pb.Money{money.BuildMsgMoney()}})
|
|
} else {
|
|
amount, err := strconv.Atoi(args[0])
|
|
if err != nil {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
if amount < 0 {
|
|
if moneyType == pb.MoneyType_Exp {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
player.ReduceMoney(moneyType, uint32(amount), logic.LogTypeNone)
|
|
} else {
|
|
player.AddMoney(moneyType, uint32(amount), logic.LogTypeNone)
|
|
}
|
|
}
|
|
case "item":
|
|
if len(args) < 1 {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
if args[0] == "clear" {
|
|
player.Item = map[uint32]*logic.PlayerItem{}
|
|
player.SaveField("item", player.Item)
|
|
|
|
_ = player.Send(pb.ModId_ModuleItem, pb.MsgId_ModItemList, player.BuildMsgItemListAck())
|
|
return
|
|
}
|
|
|
|
if len(args) < 2 {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
itemId, err := strconv.Atoi(args[0])
|
|
if err != nil {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
if args[1] == "clear" {
|
|
var item = player.Item[uint32(itemId)]
|
|
if item == nil {
|
|
return
|
|
}
|
|
|
|
delete(player.Item, uint32(itemId))
|
|
player.WipeModel(item)
|
|
|
|
_ = player.Send(pb.ModId_ModuleItem, pb.MsgId_ModItemChange, &pb.ItemChangeListAck{
|
|
ChangeList: []*pb.ItemChange{{ChangeType: pb.ChangeType_Delete, Item: item.BuildMsgItem(true)}},
|
|
})
|
|
return
|
|
} else {
|
|
|
|
itemNum, err := strconv.Atoi(args[1])
|
|
if err != nil {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
if itemNum > 0 {
|
|
_ = player.AddItem(uint32(itemId), uint32(itemNum), logic.LogTypeNone)
|
|
} else {
|
|
player.ReduceItem(uint32(itemId), uint32(-itemNum), logic.LogTypeNone)
|
|
}
|
|
}
|
|
case "hero":
|
|
if len(args) < 1 {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
heroId, err := strconv.Atoi(args[0])
|
|
if err != nil {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
if len(args) > 1 && args[1] == "clear" {
|
|
var heroes = map[uint64]*logic.PlayerHero{}
|
|
for _, hero := range player.Hero {
|
|
if hero.Id == uint32(heroId) {
|
|
heroes[hero.Uid] = hero
|
|
}
|
|
}
|
|
player.ReduceHeroes(heroes, logic.LogTypeNone)
|
|
} else {
|
|
if heroId == this.tables.ServerConfig.GetInitRole(0) || heroId == this.tables.ServerConfig.GetInitRole(1) {
|
|
_ = player.TipNotice(proto.StringTipError("主角不能添加"))
|
|
}
|
|
player.AddHero(uint32(heroId))
|
|
}
|
|
|
|
//case "charge":
|
|
// if len(args) < 1 {
|
|
// _ = player.TipNotice(proto.TipParameterError)
|
|
// return
|
|
// }
|
|
//
|
|
// chargeId, err := strconv.Atoi(args[0])
|
|
// if err != nil {
|
|
// _ = player.TipNotice(proto.TipParameterError)
|
|
// return
|
|
// }
|
|
//
|
|
// var chargeTable = this.tables.Charge.Get(chargeId)
|
|
// if chargeTable == nil {
|
|
// _ = player.TipNotice(proto.TipParameterError)
|
|
// return
|
|
// }
|
|
//
|
|
// err = player.Charge(chargeTable, logic.LogTypeNone)
|
|
// if err != nil {
|
|
// _ = player.TipNotice(err)
|
|
// return
|
|
// }
|
|
case "counter":
|
|
if len(args) < 4 {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
tipe, err := strconv.Atoi(args[0])
|
|
if err != nil || tipe < 0 {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
id1, err := strconv.Atoi(args[1])
|
|
if err != nil || id1 < 0 {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
id2, err := strconv.Atoi(args[1])
|
|
if err != nil || id2 < 0 {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
daily, err := strconv.Atoi(args[2])
|
|
if err != nil || daily < 0 {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
var onlyDaily = false
|
|
if len(args) > 4 {
|
|
onlyDaily, err = strconv.ParseBool(args[3])
|
|
if err != nil {
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
}
|
|
|
|
player.SetCounter(pb.CounterType(tipe), util.Compose2uint32(uint32(id1), uint32(id2)), uint32(daily), onlyDaily)
|
|
default:
|
|
_ = player.TipNotice(proto.StringTipError("命令错误"))
|
|
}
|
|
}
|