package game

import (
	"bytes"
	"encoding/gob"
	"fmt"
	"os"
	"server/conf"
	avatarCfg "server/conf/avatar"
	cardCfg "server/conf/card"
	chargeCfg "server/conf/charge"
	emojiCfg "server/conf/emoji"
	faceCfg "server/conf/face"
	languageCfg "server/conf/language"
	mergeDataCfg "server/conf/merge_data"
	notification_cfg "server/conf/notification"
	playroomCfg "server/conf/playroom"
	"server/db"
	"server/game/mod/activity"
	"server/game/mod/avatar"
	"server/game/mod/card"
	"server/game/mod/chess"
	"server/game/mod/decorate"
	"server/game/mod/emoji"
	"server/game/mod/face"
	"server/game/mod/friend"
	"server/game/mod/handbook"
	"server/game/mod/item"
	MsgMod "server/game/mod/msg"
	"server/game/mod/order"
	"server/game/mod/playroom"
	GoUtil "server/game_util"
	"server/msg"
	"server/pkg/github.com/name5566/leaf/log"
	"strconv"
	"strings"
	"time"

	"google.golang.org/protobuf/proto"
)

func ReqGmCommand(player *Player, buf []byte) error {
	detail := &msg.ReqGmCommand{}
	proto.Unmarshal(buf, detail)
	return ReqGmCommand_(player, detail.Command)
}
func ReqGmCommand_(player *Player, Command string) error {
	// defer func() {
	// 	if err := recover(); err != nil {
	// 		log.Error("ReqGmCommand panic: %v", err)
	// 	}
	// }()
	if conf.Server.GameName != "pet_home" && conf.Server.GameName != "merge_pet_sdk" && conf.Server.GameName != "Merge_Pet_Local" && conf.Server.GameName != "pet_home_local" {
		return fmt.Errorf("Player %d ReqGmCommand not support in game %s, command %s", player.M_DwUin, conf.Server.GameName, Command)
	}
	player.TeLog("gm", map[string]interface{}{
		"command": Command,
	})
	arg := strings.Split(Command, " ")
	switch arg[0] {
	case "additem":
		id, _ := strconv.Atoi(arg[1])
		num, _ := strconv.Atoi(arg[2])
		player.HandleItem([]*item.Item{item.NewItem(id, num)}, msg.ITEM_POP_LABEL_GM.String())
	case "subitem":
		id, _ := strconv.Atoi(arg[1])
		num, _ := strconv.Atoi(arg[2])
		player.HandleItem([]*item.Item{item.NewItem(id, -num)}, msg.ITEM_POP_LABEL_GM.String())
	case "reset_order":
		player.PlayMod.mod_list.Order.Step = 0
		player.PlayMod.mod_list.Order.InitData()
		player.PushClientRes(player.PlayMod.mod_list.Order.BackData())
	case "add_card_star":
		num, _ := strconv.Atoi(arg[1])
		player.PlayMod.mod_list.Card.ExchangeStar += num
		player.PushClientRes(player.PlayMod.mod_list.Card.BackData())
	case "add_card":
		Id, _ := strconv.Atoi(arg[1])
		player.PlayMod.mod_list.Card.AddCard(Id)
		player.PushClientRes(player.PlayMod.mod_list.Card.NotifyCard())
	case "reset_card_reward":
		player.PlayMod.mod_list.Card.CollectReward = make(map[int]struct{})
		player.PlayMod.mod_list.Card.AllCollect = 0
		player.PushClientRes(player.PlayMod.mod_list.Card.BackData())
	case "addexp":
		num, _ := strconv.Atoi(arg[1])
		player.GetPlayerBaseMod().AddExp(player, num, 0)
		player.PushClientRes(&player.GetPlayerBaseMod().Data)
	case "addDailyActive":
		num, _ := strconv.Atoi(arg[1])
		DailyMod := player.PlayMod.getDailyTaskMod()
		DailyMod.Active = num
		player.PushClientRes(DailyMod.BackData())
	case "triggerOrder":
		OrderMod := player.PlayMod.getOrderMod()
		ChessMod := player.PlayMod.getChessMod()
		OrderMod.TriggerOrder(player.GetPlayerBaseMod().GetLevel(), order.TRIGGER_TYPE_ORDER, ChessMod.GetEmitList(), 1)
		player.PushClientRes(OrderMod.BackData())
	case "setlv":
		num, _ := strconv.Atoi(arg[1])
		player.PlayMod.getBaseMod().Level = num
		player.PlayMod.getBaseMod().Exp = 0
		player.PushClientRes(player.PlayerBaseMod.BackAsset())
		player.initAcitivity()
		player.PlayMod.getGuideTaskMod().Unlock(num)
		player.PlayMod.getOrderMod().TriggerOrder(num, order.TRIGGER_TYPE_LV, nil, 1)
		player.PushClientRes(player.PlayMod.getOrderMod().BackData())
		player.BackDataActivity()
	case "zeroUpdate":
		VarMod := player.PlayMod.getVarMod()
		VarMod.DailyResetTime = 0
		player.ZeroUpdate(nil)
		player.LoginBackData()
	case "addChampshipLog":
		num, _ := strconv.Atoi(arg[1])
		player.AddLog(num, friend.LOG_TYPE_PLAYROOM_CHAMPSHIP, fmt.Sprintf("%d_%d", 1, 1), GoUtil.Now())
	case "serverZeroUpdate":
		VarMod := player.PlayMod.getVarMod()
		VarMod.DailyResetTime = 0
		player.ZeroUpdate(nil)
		G_GameLogicPtr.ZeroFlush()
	case "resetActivity":
		ActivityMod := player.PlayMod.getActivityMod()
		ActivityMod.Var = nil
		ActivityMod.InitData()
		player.PlayMod.save()
		player.initAcitivity()
		player.BackDataActivity()
	case "weekUpdate":
		VarMod := player.PlayMod.getVarMod()
		VarMod.WeeklyResetTime = 0
		player.ZeroUpdate(nil)
		G_GameLogicPtr.ZeroFlush()
	case "setSevenLoginActive":
		num, _ := strconv.Atoi(arg[1])
		player.PlayMod.getSevenLoginMod().Active = num
	case "pay":
		ChargeId, _ := strconv.Atoi(arg[1])
		player.TeLog("pay", map[string]interface{}{
			"ProductId":         ChargeId,
			"AppId":             conf.Server.AppID,
			"Uid":               player.M_DwUin,
			"ServerId":          conf.Server.ServerID,
			"Price":             chargeCfg.GetMoneyCharge(ChargeId),
			"PayType":           3,
			"OrderId":           "gm",
			"PayChannelOrderId": "gm",
			"CreateTime":        GoUtil.Now(),
			"PayTime":           GoUtil.Now(),
		})
		player.Charge(ChargeId)
	case "AddPart":
		ChessMod := player.PlayMod.getChessMod()
		if ChessMod.PartBag.List == nil {
			ChessMod.PartBag.List = make(map[int]chess.PartBagGrid)
		}
		ChessMod.PartBag.List[1505] = chess.PartBagGrid{
			Num:    100,
			PartId: 1505,
		}
		ChessMod.PartBag.List[1515] = chess.PartBagGrid{
			Num:    100,
			PartId: 1515,
		}
		ChessMod.PartBag.List[1525] = chess.PartBagGrid{
			Num:    100,
			PartId: 1525,
		}
		ChessMod.PartBag.List[1535] = chess.PartBagGrid{
			Num:    100,
			PartId: 1535,
		}
	case "AllFace":
		Now := GoUtil.Now()
		FaceMod := player.PlayMod.getFaceMod()
		FaceList := faceCfg.GetAllId()
		FaceMod.List = make(map[int]*face.Face)
		for _, v := range FaceList {
			FaceMod.List[v] = &face.Face{
				AddTime: Now,
			}
		}

		AvatarMod := player.PlayMod.getAvatarMod()
		AvatarMod.List = make(map[int]*avatar.Avatar)
		AvatarList := avatarCfg.GetAllId()

		for _, v := range AvatarList {
			AvatarMod.List[v] = &avatar.Avatar{
				AddTime: Now,
			}
		}
		player.BackUserInfo()
	case "resetFace":
		FaceMod := player.PlayMod.getFaceMod()
		FaceMod.List = nil
		FaceMod.InitData()

		AvatarMod := player.PlayMod.getAvatarMod()
		AvatarMod.List = nil
		AvatarMod.InitData()
	case "initEmoji":
		EmojiMod := player.PlayMod.getEmojiMod()
		InitId := emojiCfg.GetInitList()
		now := GoUtil.Now()
		for _, v := range InitId {
			EmojiMod.List[v] = &emoji.Emoji{
				AddTime: now,
			}
		}
	case "addEmoji":
		EmojiMod := player.PlayMod.getEmojiMod()
		InitId := emojiCfg.GetAllList()
		now := GoUtil.Now()
		for _, v := range InitId {
			EmojiMod.List[v] = &emoji.Emoji{
				AddTime: now,
			}
		}
	case "createOrder":
		Lv := player.GetPlayerBaseMod().GetLevel()
		EmitList := player.PlayMod.getChessMod().GetEmitList()
		EnergyMul := player.PlayMod.getBaseMod().GetEnergyMul()
		OrderMod := player.PlayMod.getOrderMod()
		OrderMod.LastOrder.Type = 1
		OrderMod.CreateOrder(Lv, EmitList, EnergyMul, order.Common_type)
		player.PushClientRes(player.PlayMod.getOrderMod().BackData())
	case "resetCardReq":
		CardMod := player.PlayMod.getCardMod()
		CardMod.ReqFriend = make(map[int]*card.CardInfo)
		CardMod.ExCard = make(map[int]*card.CardInfo)
		CardMod.ExTimes = 10
		CardMod.ReqTimes = 10
		player.AddCard(1)
		player.AddCard(2)
		player.AddCard(3)
		FriendMod := player.PlayMod.getFriendMod()
		FriendMod.Card = make(map[string]*card.CardInfo)
		player.PushClientRes(CardMod.NotifyCard())
	case "subCard":
		ChargeId, _ := strconv.Atoi(arg[1])
		CardMod := player.PlayMod.getCardMod()
		player.SubCard(ChargeId)
		player.PushClientRes(CardMod.NotifyCard())
	case "setProgress":
		num, _ := strconv.Atoi(arg[1])
		player.PlayMod.getLimitedTimeEventMod().Progress = num
	case "setProgressReward":
		BaseMod := player.PlayMod.getBaseMod()
		LimitedTimeEventMod := player.PlayMod.getLimitedTimeEventMod()
		LimitedTimeEventMod.Progress = 5
		for i := 1; i < 5; i++ {
			LimitedTimeEventMod.AddProgress(BaseMod.GetLevel())
		}
		player.PushClientRes(LimitedTimeEventMod.ProgressBackData())
	case "champshipGroup":
		SendMsgToCenterAsync(&MsgMod.Msg{
			HandleType: MsgMod.HANDLE_MOD_CHAMPSHIP_GROUP,
		})
	case "inrank":
		ChampshipMod := player.PlayMod.getChampshipMod()
		num, _ := strconv.Atoi(arg[1])
		Score := float64(num)
		// 更新排行榜
		m := &MsgMod.Msg{
			Type:  MsgMod.HANDLE_TYPE_CHAMPSHIP_INRANK,
			SendT: GoUtil.Now(),
			Extra: CRank{
				Uid:   int(player.M_DwUin),
				Score: Score,
				H:     ChampshipMod.GetH(),
				N:     ChampshipMod.GetN(),
			},
			End:        GoUtil.ZeroTimestamp() + 86400, // 第二天零点删除
			HandleType: MsgMod.HANDLE_MDO_CHAMPSHIP_INRANK,
		}
		SendMsgToCenterAsync(m)
	case "resetUserInfo":
		Rank := G_GameLogicPtr.RankMgr.getRank(RANK_TYPE_USER)
		for _, v := range Rank {
			Idstr := strconv.Itoa(v.Uid)
			db.RedisDelKey(Idstr)
			G_GameLogicPtr.GetResSimplePlayerByUid(v.Uid)
		}

	case "champshipZero":
		G_GameLogicPtr.ChampshipMgrSend(&MsgMod.Msg{
			Type: MsgMod.SERVER_ZERO_UPDATE,
		})
	case "resetEmitOrder":
		OrderMod := player.PlayMod.getOrderMod()
		OrderMod.EimtOrder = make(map[string]struct{})
		HandbookMod := player.PlayMod.getHandbookMod()
		delete(HandbookMod.BookList, 125)
	case "handbook":
		HandbookMod := player.PlayMod.getHandbookMod()
		for _, v := range mergeDataCfg.GetAllId() {
			HandbookMod.SetHandbook(v)
			HandbookMod.BookList[v] = handbook.STATUS_REWARD
		}
	case "setLogin":
		Id, _ := strconv.Atoi(arg[1])
		BaseMod := player.PlayMod.getBaseMod()
		BaseMod.LoginTime = int64(Id)
	case "setLogout":
		Id, _ := strconv.Atoi(arg[1])
		BaseMod := player.PlayMod.getBaseMod()
		BaseMod.LogoutTime = int64(Id)
	case "setRegister":
		Id, _ := strconv.Atoi(arg[1])
		player.PlayerBaseMod.Data.Rolecreatetime = int32(Id)
	case "handbookReward":
		HandbookMod := player.PlayMod.getHandbookMod()
		for _, v := range mergeDataCfg.GetAllId() {
			HandbookMod.BookList[v] = handbook.STATUS_REWARD
		}
		player.PushClientRes(HandbookMod.BackData())
	case "deleteOrder":
		Id, _ := strconv.Atoi(arg[1])
		OrderMod := player.PlayMod.getOrderMod()
		delete(OrderMod.OrderList, Id)
		player.PushClientRes(OrderMod.BackData())
	case "miningReload":
		MiningMod := player.PlayMod.getMiningMod()
		MiningMod.ZeroUpdate(-1)
		ActivityInfo := player.GetActivityInfo(activity.ACT_TYPE_MINING)
		MiningMod.ZeroUpdate(ActivityInfo.Id)
		player.MiningBackData()
	case "catnipReload":
		CatnipMod := player.PlayMod.getCatnipMod()
		CatnipMod.ZeroUpdate(-1)
		ActivityInfo := player.GetActivityInfo(activity.ACT_TYPE_CATNIP)
		CatnipMod.ZeroUpdate(ActivityInfo.Id)
	case "guessColorReload":
		GuessColorMod := player.PlayMod.getGuessColorMod()
		GuessColorMod.ZeroUpdate(-1)
		ActivityInfo := player.GetActivityInfo(activity.ACT_TYPE_GUESS_COLOR)
		GuessColorMod.ZeroUpdate(ActivityInfo.Id)
		player.GuessColorBackData()
	case "raceReload":
		RaceMod := player.PlayMod.getRaceMod()
		RaceMod.ZeroUpdate(-1)
		ActivityInfo := player.GetActivityInfo(activity.ACT_TYPE_RACE)
		RaceMod.ZeroUpdate(ActivityInfo.Id)
		player.RaceBackData()
	case "raceAdd":
		RaceMod := player.PlayMod.getRaceMod()
		RaceMod.AddCoin(100)
		player.RaceBackData()
	case "playroomReset":
		PlayroomMod := playroom.PlayroomMod{}
		PlayroomMod.InitData()
		player.PlayMod.mod_list.Playroom = PlayroomMod
	case "resetCollect":
		CollectMod := player.PlayMod.getCollectMod()
		CollectMod.Reward = make([]int, 0)
		CollectMod.Jackpot = make([]int, 0)
		CollectMod.InitData()
	case "playroomCollect":
		CollectList := playroomCfg.GetDecorateList()
		PlayroomMod := player.PlayMod.getPlayroomMod()
		PlayroomMod.NewCollect = make(map[int]*playroom.CollectInfo, 0)
		for _, v := range CollectList {
			PlayroomMod.AddCollect(v, "Gm")
		}
	case "playroomDress":
		PlayroomMod := player.PlayMod.getPlayroomMod()
		PlayroomMod.NewDress = make(map[int]*playroom.DressInfo, 0)
		DressList := playroomCfg.GetDressList()
		for _, v := range DressList {
			Part := playroomCfg.GetDressPart(v)
			PlayroomMod.UnlockDress(Part, v)
		}
		player.PlayroomBackData()
	case "playroomAir":
		PlayroomMod := player.PlayMod.getPlayroomMod()
		PlayroomMod.NewPetAir = make(map[int]*playroom.PetAirInfo, 0)
		AirList := playroomCfg.GetAirList()
		for _, v := range AirList {
			PlayroomMod.UnlockPetAir(v)
		}
		player.PlayroomBackData()
	case "resetRetire":
		ChessMod := player.PlayMod.getChessMod()
		ChessMod.Retire = make(map[string]int)
		ChessMod.RetireChessMap = make(map[string][]int)
	case "cleanBuff":
		ChessMod := player.PlayMod.getChessMod()
		ChessMod.ChessBuff = []int{}
		player.PushClientRes(ChessMod.BackData())
	case "addPlayroomPoint":
		PlayroomMod := player.PlayMod.getPlayroomMod()
		Num, _ := strconv.Atoi(arg[1])
		PlayroomMod.RoomPoint += Num
		player.PlayroomBackData()
	case "resetPlayroomUnlock":
		PlayroomMod := player.PlayMod.getPlayroomMod()
		PlayroomMod.UnlockList = make(map[int]int64)
		player.PlayroomBackData()
	case "addChip":
		PlayroomMod := player.PlayMod.getPlayroomMod()
		PlayroomMod.AddChip(100100001, 1, 0)
		player.PushClientRes(PlayroomMod.NotifyLose())
	case "save":
		player.PlayMod.ClearData(player)
	case "logout":
		player.PushAndSendClienRes(&msg.ForceKickOut{})
		player.ClearData()
	case "resetFriend":
		FriendMod := player.PlayMod.getFriendMod()
		FriendMod.FriendList = make(map[int]struct{})
		FriendMod.ApplyList = make(map[int]int64)
		FriendMod.Card = make(map[string]*card.CardInfo)
		FriendMod.SendApply = make(map[int]int64)
		FriendMod.NewFriendList = make(map[int]*friend.FriendInfo)
		FriendMod.Npc = []int{}
		FriendMod.Id = 0
		FriendMod.Log = make([]*friend.LogInfo, 0)
		FriendMod.InitData()
		player.FriendListBackData()
		player.FriendLogBackData()
	case "addFriend":
		FriendMod := player.PlayMod.getFriendMod()
		Uid, _ := strconv.Atoi(arg[1])
		FriendMod.AddFriend(Uid)
	case "addAddCard":
		CardMod := player.PlayMod.getCardMod()
		CardList := cardCfg.GetAllCardId(CardMod.Round)
		for _, v := range CardList {
			player.AddCard(v)
			CardMod.Handbook[v] = card.HANDBOOK_STATUS_GET
		}
		player.PushClientRes(CardMod.NotifyCard())
	case "resetRankUser":
		db.RedisDelKey(RANK_USER)
		db.RedisDelKey(fmt.Sprintf("%s_%s", RANK_COUNTRY_USER, conf.Server.CountryCode))
	case "addFriendStar":
		FriendTreasureMod := player.PlayMod.getFriendTreasureMod()
		FriendTreasureMod.AddStar(200)
	case "comfortOrder":
		BaseMod := player.PlayMod.getBaseMod()
		BaseMod.LogoutTime = GoUtil.Now() - 7*86400
		player.TriggerComfortOrder()
		player.PushClientRes(player.PlayMod.getOrderMod().BackData())
	case "resetGuide":
		GuildMod := player.PlayMod.getGuideMod()
		GuildMod.Reward = make(map[int]int)
		player.PushClientRes(GuildMod.BackData())
	case "resetDecoratePart":
		DecorateMod := player.PlayMod.getDecorateMod()
		DecorateMod.PartCost = make(map[int]*decorate.PartCostInfo)
		DecorateMod.PartClassPool = []int{}
		DecorateMod.PartPool = make(map[int]int)
		DecorateMod.InitData()
		player.PushClientRes(DecorateMod.BackData())
	case "setDecorateArea":
		S, _ := strconv.Atoi(arg[1])
		DecorateMod := player.PlayMod.getDecorateMod()
		DecorateMod.AreaId = S
		DecorateMod.FinishList = make(map[int]struct{})
		DecorateMod.Progress = 0
		DecorateMod.PartCost = make(map[int]*decorate.PartCostInfo)
		DecorateMod.PartClassPool = []int{}
		DecorateMod.PartPool = make(map[int]int)
		DecorateMod.InitData()
		player.PushClientRes(DecorateMod.BackData())
	case "setDecorateProgress":
		S, _ := strconv.Atoi(arg[1])
		DecorateMod := player.PlayMod.getDecorateMod()
		DecorateMod.FinishList = make(map[int]struct{})
		for i := 1; i <= S; i++ {
			DecorateMod.FinishList[i] = struct{}{}
		}
		DecorateMod.Progress = S
		player.PushClientRes(DecorateMod.BackData())
	case "resetCardSeasonFirst":
		CardMod := player.PlayMod.getCardMod()
		CardMod.SeasonFirst = false
	case "addPhysiology":
		PlayroomMod := player.PlayMod.getPlayroomMod()
		Type, _ := strconv.Atoi(arg[1])
		Num, _ := strconv.Atoi(arg[2])
		PlayroomMod.AddPhysiology(Type, Num)
	case "resetTriggerTime":
		PlayroomMod := player.PlayMod.getPlayroomMod()
		PlayroomMod.TriggerTime = 0
	case "resetTimeline":
		FriendMod := player.PlayMod.getFriendMod()
		FriendMod.Log = make([]*friend.LogInfo, 0)
	case "resetFastCD":
		LimitedTimeEventMod := player.PlayMod.getLimitedTimeEventMod()
		LimitedTimeEventMod.ResetFastProduceCD()
		EndTime, Times := LimitedTimeEventMod.GetFastProduceInfo()
		player.PushClientRes(&msg.ResFastProduceInfo{
			EndTime: EndTime,
			Num:     int32(Times),
		})
	case "resetNpc":
		FriendMod := player.PlayMod.getFriendMod()
		FriendMod.Npc = []int{}
		player.FriendListBackData()
	case "recoverUser":
		file, err := os.OpenFile(conf.Server.GameConfPath+"user.info", os.O_RDWR|os.O_CREATE, 0666)
		if err != nil {
			log.Error("Failed to open user.info file: %v", err)
			return err
		}
		// file.Write(buf.Bytes())
		defer file.Close()
		Uid := player.M_DwUin
		file.Seek(0, 0)
		decoder := gob.NewDecoder(file)
		modList := PlayerModList{}
		err = decoder.Decode(&modList)
		player.PlayMod.mod_list = modList
		if err != nil {
			log.Error("Failed to decode user.info file: %v", err)
			return err
		}
		BaseMod := player.PlayMod.getBaseMod()
		BaseMod.Uid = Uid
	case "copyUser":
		p1 := new(Player)
		err := p1.InitPlayer(arg[1])
		if err != nil {
			return err
		}
		BaseMod := p1.PlayMod.getBaseMod()
		BaseMod.Uid = player.M_DwUin
		BaseMod.NickName = player.PlayMod.getBaseMod().NickName
		BaseMod.Account = player.PlayMod.getBaseMod().Account
		BaseMod.LoginTime = GoUtil.Now()
		BaseMod.AddCode = fmt.Sprintf("MMM-%s-%s", "156", GoUtil.UniqueStringFromInt(int(BaseMod.Uid)))
		// deep copy p1.PlayMod.mod_list to avoid sharing internal pointers
		var modCopy PlayerModList
		var buf bytes.Buffer
		enc := gob.NewEncoder(&buf)
		if err := enc.Encode(p1.PlayMod.mod_list); err != nil {
			log.Error("failed to encode mod_list: %v", err)
			return err
		}
		dec := gob.NewDecoder(&buf)
		if err := dec.Decode(&modCopy); err != nil {
			log.Error("failed to decode mod_list: %v", err)
			return err
		}
		player.PlayMod.mod_list = modCopy
		player.PlayMod.mod_list.Base = *BaseMod
	case "orderMerge": // 获取order订单的mergeId
		OrderMod := player.PlayMod.getOrderMod()
		items := make([]*item.Item, 0)
		for _, v := range OrderMod.OrderList {
			for _, j := range v.MergeId {
				items = append(items, &item.Item{
					Id:  j,
					Num: 1,
				})
			}
		}
		player.HandleItem(items, msg.ITEM_POP_LABEL_GM.String())
	case "resetCompensation":
		compensationMod := player.PlayMod.getCompensationMod()
		compensationMod.C20250910 = false
	case "resetWeekly":
		ChargeMod := player.PlayMod.getChargeMod()
		ChargeMod.WeeklyDiscount = make(map[int]int)
		player.ChargeBackData()
		PlayroomMod := player.PlayMod.getPlayroomMod()
		PlayroomMod.WeeklyDiscount = make(map[int]int)
		player.PlayroomBackData()
	case "resetPlayer":
		de := time.Now().Format("2006-01-02 15:04:05")
		BaseMod := player.PlayMod.getBaseMod()
		account := BaseMod.Account
		newAccount := fmt.Sprintf("%s_reset_%s", account, de)
		err := db.ResetAccountData(account, newAccount)
		if err != nil {
			log.Error("resetPlayer err:%s", err.Error())
			return err
		}
		log.Debug("player reset: old account: %s; new account %s", account, newAccount)
		BaseMod.Account = newAccount
		player.GetPlayerBaseMod().Data.UserName = newAccount
		player.PushAndSendClienRes(&msg.ForceKickOut{})
	case "resetCode":
		BaseMod := player.PlayMod.getBaseMod()
		BaseMod.AddCode = fmt.Sprintf("MMM-%s-%s", "156", GoUtil.UniqueStringFromInt(int(BaseMod.Uid)))
		player.BackUserInfo()
	case "debug":
		player.AddPlayroomUpvote(100100129)
		i := player.GetPlayroomUpvote(100100129)
		log.Debug("debug upvote:%d", i)
	case "addLimitEvent":
		Id, _ := strconv.Atoi(arg[1])
		Cd, _ := strconv.Atoi(arg[2])
		LimitedTimeEventMod := player.PlayMod.getLimitedTimeEventMod()
		LimitedTimeEventMod.AddEvent(Id, Cd)
		player.PushClientRes(LimitedTimeEventMod.BackData())
	case "resetTriggerMail":
		player.PlayMod.mod_list.Mail.TriggerMail = make([]int, 0, 8)
	case "notification":
		Id, _ := strconv.Atoi(arg[1])
		NotifyFriendApply(Id, int(player.M_DwUin))
		NotifyPetroomGame(Id)
	case "notificationTest":
		Id, _ := strconv.Atoi(arg[1])
		PlayerSimpleData := G_GameLogicPtr.GetSimplePlayerByUid(Id)
		if PlayerSimpleData == nil {
			return nil
		}
		titlekey, infokey := notification_cfg.GetFriendApplyNotificationMsg()
		title := languageCfg.GetLanguage(msg.LANG_TYPE(PlayerSimpleData.Lang), titlekey)
		info := languageCfg.GetLanguage(msg.LANG_TYPE(PlayerSimpleData.Lang), infokey)
		BaseMod := player.PlayMod.getBaseMod()
		GoUtil.NotifyPlayer(GoUtil.Int(PlayerSimpleData.Account), 1, title, fmt.Sprintf(info, BaseMod.NickName))

		titlekey, infokey = notification_cfg.GetPetroomGameNotificationMsg()
		title = languageCfg.GetLanguage(msg.LANG_TYPE(PlayerSimpleData.Lang), titlekey)
		info = languageCfg.GetLanguage(msg.LANG_TYPE(PlayerSimpleData.Lang), infokey)
		GoUtil.NotifyPlayer(GoUtil.Int(PlayerSimpleData.Account), NOTIFY_TYPE_PETROOM_GAME, fmt.Sprintf(title, PlayerSimpleData.PetName), fmt.Sprintf(info, PlayerSimpleData.PetName))

	default:
		return fmt.Errorf("Player %d ReqGmCommand:%v not found", player.M_DwUin, arg)
	}
	log.Debug("Player %d ReqGmCommand:%v", player.M_DwUin, arg)

	player.PlayMod.save()
	return nil
}
