package main

import (
	"encoding/json"
	"fmt"
	protobuf "github.com/golang/protobuf/proto"
	"vikingar/cmd"
	"vikingar/cmd/config"
	proto "vikingar/proto/gen-go/service"
)

func main() {
	for {
		var protoId string
		fmt.Println("----------------------------")
		fmt.Println("请输入protoId:")
		_, err := fmt.Scan(&protoId)
		if err != nil {
			panic(err)
		}

		//输入-1来关闭连接
		if protoId == "-1" {
			cmd.TproClient.Close()
		}
		cmd.TProCmd.SetArgs([]string{protoId})
		if err = cmd.TProCmd.Execute(); err != nil {
			panic(err)
		}
	}
}

func registerCallBack(protoId uint16, p protobuf.Message) {
	cmd.TproClient.RegisterCallBack(protoId, func(bytes []byte) {
		protobuf.Unmarshal(bytes, p)
		fmt.Println(protoId, ":")
		jsonBytes, _ := json.Marshal(p)
		fmt.Println(string(jsonBytes))
	})
}

func init() {
	cmd.InitClient("localhost:8071", "dfgagas123dfasfdasfsaf")
	//这里填你的请求参数路径
	config.InitConfig("request", "../tpro-client2")
	//在这里可以根据protoId自定义回调函数,可以用来查看推送消息
	registerCallBack(20199, &proto.UnionBattleMapPush{})
	registerCallBack(20198, &proto.UnionBattlePush{})
	registerCallBack(20196, &proto.UnionBattleRolePush{})
	registerCallBack(20195, &proto.UnionBattleTeamPush{})
	registerCallBack(20194, &proto.UnionBattleScorePush{})
	registerCallBack(20193, &proto.UnionBattleReviveStonePush{})
	registerCallBack(20192, &proto.UnionBattleReviveStoneDestroyedPush{})
	registerCallBack(20191, &proto.UnionBattleFightResultPush{})
	registerCallBack(20190, &proto.UnionBattleFightPush{})
	registerCallBack(20189, &proto.UnionBattleMarkPush{})
	registerCallBack(20188, &proto.UnionBattleMarkCanceledPush{})
	registerCallBack(20187, &proto.UnionBattleInvestigatePush{})
	registerCallBack(20186, &proto.UnionBattleInvestigateDisabledPush{})
	registerCallBack(20185, &proto.UnionBattleMoveEndPush{})
	registerCallBack(20184, &proto.UnionBattleTeamMovePush{})
	registerCallBack(20183, &proto.UnionBattleSpareWarriorMovePush{})
	registerCallBack(20182, &proto.UnionBattleHomePush{})
	registerCallBack(20181, &proto.UnionBattleKingCityAwardPush{})
	registerCallBack(20180, &proto.UnionBattleKingCityPush{})
	registerCallBack(20179, &proto.UnionBattleSpareWarriorPush{})
	registerCallBack(20178, &proto.UnionBattleBuildingPush{})
	registerCallBack(20177, &proto.UnionBattleRollingTitlePush{})
	registerCallBack(20176, &proto.UnionBattleSettlePush{})
	registerCallBack(20175, &proto.UnionBattleRankAwardRolePush{})
	registerCallBack(13099, &proto.ChatMessagePush{})
	registerCallBack(14878, &proto.RuinsTreasureActivityItemRolePush{})
	registerCallBack(20130, &proto.UnionBattleGetShareListResponse{})

	registerCallBack(19192, &proto.UnionSnowmanSpecialAwardPush{})
	registerCallBack(19193, &proto.UnionSnowmanRollingTitlePush{})
	registerCallBack(19194, &proto.UnionSnowmanReportPush{})
	registerCallBack(19195, &proto.UnionSnowmanSnowmanKilledPush{})
	registerCallBack(19196, &proto.UnionSnowmanSnowmanPush{})
	registerCallBack(19197, &proto.UnionSnowmanChosenTopicPush{})
	registerCallBack(19198, &proto.UnionSnowmanTopicPush{})
	registerCallBack(19199, &proto.UnionSnowmanTimePush{})

	//这里注册protoId，请求和响应结构体指针
	config.RegisterProto(10000, &proto.RoleLoginRequest{}, &proto.RoleLoginResponse{})
	config.RegisterProto(13900, &proto.SceneSwitchRequest{}, &proto.SceneSwitchResponse{})
	config.RegisterProto(13901, &proto.ScenePushRequest{}, &proto.ScenePushResponse{})

	config.RegisterProto(20100, &proto.UnionBattleAttackRequest{}, &proto.UnionBattleAttackResponse{})
	config.RegisterProto(20101, &proto.UnionBattleHoldRequest{}, &proto.UnionBattleHoldResponse{})
	config.RegisterProto(20102, &proto.UnionBattleQuitRequest{}, &proto.UnionBattleQuitResponse{})
	config.RegisterProto(20103, &proto.UnionBattleUseSpareWarriorRequest{}, &proto.UnionBattleUseSpareWarriorResponse{})
	config.RegisterProto(20104, &proto.UnionBattleAskHelpSpareWarriorRequest{}, &proto.UnionBattleAskHelpSpareWarriorResponse{})
	config.RegisterProto(20105, &proto.UnionBattleInvestigateRequest{}, &proto.UnionBattleInvestigateResponse{})
	config.RegisterProto(20106, &proto.UnionBattleMarkRequest{}, &proto.UnionBattleMarkResponse{})
	config.RegisterProto(20107, &proto.UnionBattleCancelMarkRequest{}, &proto.UnionBattleCancelMarkResponse{})
	config.RegisterProto(20108, &proto.UnionBattleShareBuildingRequest{}, &proto.UnionBattleShareBuildingResponse{})
	config.RegisterProto(20109, &proto.UnionBattleGetBuildingDetailsRequest{}, &proto.UnionBattleGetBuildingDetailsResponse{})
	config.RegisterProto(20110, &proto.UnionBattleGetBuildingInfoRequest{}, &proto.UnionBattleGetBuildingInfoResponse{})
	config.RegisterProto(20111, &proto.UnionBattleBuyTeamPowerRequest{}, &proto.UnionBattleBuyTeamPowerResponse{})
	config.RegisterProto(20112, &proto.UnionBattleReviveTeamRequest{}, &proto.UnionBattleReviveTeamResponse{})
	config.RegisterProto(20113, &proto.UnionBattleSpeedUpRequest{}, &proto.UnionBattleSpeedUpResponse{})
	config.RegisterProto(20114, &proto.UnionBattleUseReviveStoneRequest{}, &proto.UnionBattleUseReviveStoneResponse{})
	config.RegisterProto(20115, &proto.UnionBattleDestroyReviveStoneRequest{}, &proto.UnionBattleDestroyReviveStoneResponse{})
	config.RegisterProto(20116, &proto.UnionBattleGetPersonalReportRequest{}, &proto.UnionBattleGetPersonalReportResponse{})
	config.RegisterProto(20117, &proto.UnionBattleGetUnionReportRequest{}, &proto.UnionBattleGetUnionReportResponse{})
	config.RegisterProto(20118, &proto.UnionBattleGetUnionTeamRequest{}, &proto.UnionBattleGetUnionTeamResponse{})
	config.RegisterProto(20119, &proto.UnionBattleGetRoleRankListRequest{}, &proto.UnionBattleGetRoleRankListResponse{})
	config.RegisterProto(20120, &proto.UnionBattleGetUnionRankListRequest{}, &proto.UnionBattleGetUnionRankListResponse{})
	config.RegisterProto(20121, &proto.UnionBattleGetRankAwardRequest{}, &proto.UnionBattleGetRankAwardResponse{})
	config.RegisterProto(20122, &proto.UnionBattleGetFirstlyHoldAwardRequest{}, &proto.UnionBattleGetFirstlyHoldAwardResponse{})
	config.RegisterProto(20123, &proto.UnionBattleGetSkyAwardMovePointRequest{}, &proto.UnionBattleGetSkyAwardMovePointResponse{})
	config.RegisterProto(20124, &proto.UnionBattleHelpSpareWarriorRequest{}, &proto.UnionBattleHelpSpareWarriorResponse{})
	config.RegisterProto(20125, &proto.UnionBattleGetHomeAwardRequest{}, &proto.UnionBattleGetHomeAwardResponse{})
	config.RegisterProto(20126, &proto.UnionBattleGetKingCityAwardRequest{}, &proto.UnionBattleGetKingCityAwardResponse{})

	config.RegisterProto(13000, &proto.ChatGetMessageRequest{}, &proto.ChatGetMessageResponse{})
	config.RegisterProto(15408, &proto.CheatRuinsTreasureOpenActivityRequest{}, &proto.CheatRuinsTreasureOpenActivityResponse{})
	config.RegisterProto(14852, &proto.RuinsTreasureUseActivityItemRequest{}, &proto.RuinsTreasureUseActivityItemResponse{})

	config.RegisterProto(20130, &proto.UnionBattleGetShareListRequest{}, &proto.UnionBattleGetShareListResponse{})

	config.RegisterProto(19100, &proto.UnionSnowmanSetTopicRequest{}, &proto.UnionSnowmanSetTopicResponse{})
	config.RegisterProto(19101, &proto.UnionSnowmanAttackRequest{}, &proto.UnionSnowmanAttackResponse{})
	config.RegisterProto(19102, &proto.UnionSnowmanGetDamageRecordRequest{}, &proto.UnionSnowmanGetDamageRecordResponse{})
	config.RegisterProto(19103, &proto.UnionSnowmanGetDamageDetailRequest{}, &proto.UnionSnowmanGetDamageDetailResponse{})
	config.RegisterProto(19104, &proto.UnionSnowmanGetAwardRecordRequest{}, &proto.UnionSnowmanGetAwardRecordResponse{})
	config.RegisterProto(19105, &proto.UnionSnowmanGetReportRequest{}, &proto.UnionSnowmanGetReportResponse{})
	config.RegisterProto(19106, &proto.UnionSnowmanGetKillAwardRequest{}, &proto.UnionSnowmanGetKillAwardResponse{})
}
