diff --git a/common/region/region.go b/common/region/region.go index 89d87b05..f18e6eef 100644 --- a/common/region/region.go +++ b/common/region/region.go @@ -1,6 +1,7 @@ package region import ( + "encoding/json" "os" "hk4e/common/config" @@ -38,22 +39,35 @@ func NewRegionEc2b() *random.Ec2b { return random.NewEc2b() } +// RegionCustomConfig 区服相关的配置,避免在http中使用Json格式 +type RegionCustomConfig struct { + CloseAntiDebug bool `json:"close_antidebug"` // 默认false: 默认打开反调开关 + ForceKill bool `json:"force_kill"` // 默认false: + AntiDebugPc bool `json:"antidebug_pc"` // 默认false: pc默认不开启反调 + AntiDebugIos bool `json:"antidubug_ios"` // 默认false: ios默认不开启反调 + AntiDebugAndroid bool `json:"antidubug_androd"` // 默认false: android默认不开启反调 +} + +// ClientCustomConfig 客户端版本定义的配置 客户端版本号对应的配置, 需要兼容老的json格式 +type ClientCustomConfig struct { + Visitor bool `json:"visitor"` // 游客功能 + SdkEnv string `json:"sdkenv"` // sdk环境类型 + DebugMenu bool `json:"debugmenu"` // debug菜单 + DebugLogSwitch []int32 `json:"debuglogswitch"` // 打开的log类型 + DebugLog bool `json:"debuglog"` // log总开关 + DeviceList map[string]string `json:"devicelist"` + LoadJsonData bool `json:"loadjsondata"` // 用json读取InLevel数据 + ShowException bool `json:"showexception"` // 是否显示异常提示框 默认为:true + CheckDevice bool `json:"checkdevice"` + LoadPatch bool `json:"loadPatch"` + RegionConfig string `json:"regionConfig"` + DownloadMode int32 `json:"downloadMode"` +} + func GetRegionList(ec2b *random.Ec2b) *proto.QueryRegionListHttpRsp { - dispatchEc2bData := ec2b.Bytes() - dispatchXorKey := ec2b.XorKey() // RegionList - customConfigStr := ` - { - "sdkenv": "2", - "checkdevice": "false", - "loadPatch": "false", - "showexception": "false", - "regionConfig": "pm|fk|add", - "downloadMode": "0", - } - ` - customConfig := []byte(customConfigStr) - endec.Xor(customConfig, dispatchXorKey) + regionList := new(proto.QueryRegionListHttpRsp) + regionList.Retcode = 0 serverList := make([]*proto.RegionSimpleInfo, 0) server := &proto.RegionSimpleInfo{ Name: "os_usa", @@ -62,23 +76,64 @@ func GetRegionList(ec2b *random.Ec2b) *proto.QueryRegionListHttpRsp { DispatchUrl: config.GetConfig().Hk4e.DispatchUrl, } serverList = append(serverList, server) - regionList := new(proto.QueryRegionListHttpRsp) regionList.RegionList = serverList - regionList.ClientSecretKey = dispatchEc2bData - regionList.ClientCustomConfigEncrypted = customConfig + dispatchEc2bData := ec2b.Bytes() + regionList.ClientSecretKey = dispatchEc2bData // 客户端使用密钥 + dispatchXorKey := ec2b.XorKey() + clientCustomConfig, _ := json.Marshal(&ClientCustomConfig{ + SdkEnv: "2", + CheckDevice: false, + LoadPatch: false, + ShowException: true, + RegionConfig: "pm|fk|add", + DownloadMode: 0, + DebugMenu: true, + DebugLogSwitch: []int32{0, 1, 2}, + DebugLog: true, + }) + endec.Xor(clientCustomConfig, dispatchXorKey) + regionList.ClientCustomConfigEncrypted = clientCustomConfig // 加密后的客户端版本定义的配置 regionList.EnableLoginPc = true return regionList } func GetRegionCurr(kcpAddr string, kcpPort int32, ec2b *random.Ec2b) *proto.QueryCurrRegionHttpRsp { - dispatchEc2bData := ec2b.Bytes() // RegionCurr + // region_info: retcode == 0 || RET_STOP_SERVER + // force_udpate: retcode == RET_CLIENT_FORCE_UPDATE + // stop_server: retcode == RET_STOP_SERVER regionCurr := new(proto.QueryCurrRegionHttpRsp) + regionCurr.Retcode = 0 // 错误码 + regionCurr.Msg = "" // 错误信息 + dispatchEc2bData := ec2b.Bytes() regionCurr.RegionInfo = &proto.RegionInfo{ GateserverIp: kcpAddr, GateserverPort: uint32(kcpPort), - SecretKey: dispatchEc2bData, + SecretKey: dispatchEc2bData, // 第一条协议加密密钥 } - regionCurr.ClientSecretKey = dispatchEc2bData + regionCurr.ClientSecretKey = dispatchEc2bData // 客户端使用密钥 + dispatchXorKey := ec2b.XorKey() + regionCustomConfig, _ := json.Marshal(&RegionCustomConfig{ + CloseAntiDebug: true, + ForceKill: false, + AntiDebugPc: false, + AntiDebugIos: false, + AntiDebugAndroid: false, + }) + endec.Xor(regionCustomConfig, dispatchXorKey) + regionCurr.RegionCustomConfigEncrypted = regionCustomConfig // 加密后的区服定义的配置 + clientCustomConfig, _ := json.Marshal(&ClientCustomConfig{ + SdkEnv: "2", + CheckDevice: false, + LoadPatch: false, + ShowException: true, + RegionConfig: "pm|fk|add", + DownloadMode: 0, + DebugMenu: true, + DebugLogSwitch: []int32{0, 1, 2}, + DebugLog: true, + }) + endec.Xor(clientCustomConfig, dispatchXorKey) + regionCurr.ClientRegionCustomConfigEncrypted = clientCustomConfig // 加密后的客户端区服定义的配置 return regionCurr } diff --git a/dispatch/controller/dispatch_controller.go b/dispatch/controller/dispatch_controller.go index 7ec848c5..50be8270 100644 --- a/dispatch/controller/dispatch_controller.go +++ b/dispatch/controller/dispatch_controller.go @@ -71,7 +71,9 @@ func (c *Controller) queryRegionList(context *gin.Context) { return } logger.Debug("QueryRegionListHttpRsp: %+v", queryRegionListHttpRsp) - queryRegionListHttpRsp.RegionList[0].DispatchUrl = config.GetConfig().Hk4e.DispatchUrl + for _, regionSimpleInfo := range queryRegionListHttpRsp.RegionList { + regionSimpleInfo.DispatchUrl = config.GetConfig().Hk4e.DispatchUrl + } regionListData, err := pb.Marshal(queryRegionListHttpRsp) if err != nil { _, _ = context.Writer.WriteString("500") diff --git a/gs/game/game.go b/gs/game/game.go index b98a1b1b..5c974612 100644 --- a/gs/game/game.go +++ b/gs/game/game.go @@ -376,7 +376,7 @@ func (g *Game) SendSucc(cmdId uint16, player *model.Player, rsp pb.Message) { // SendToWorldA 给世界内所有玩家发消息 func (g *Game) SendToWorldA(world *World, cmdId uint16, seq uint32, msg pb.Message) { for _, v := range world.GetAllPlayer() { - GAME.SendMsg(cmdId, v.PlayerID, seq, msg) + g.SendMsg(cmdId, v.PlayerID, seq, msg) } } @@ -386,13 +386,13 @@ func (g *Game) SendToWorldAEC(world *World, cmdId uint16, seq uint32, msg pb.Mes if aecUid == v.PlayerID { continue } - GAME.SendMsg(cmdId, v.PlayerID, seq, msg) + g.SendMsg(cmdId, v.PlayerID, seq, msg) } } // SendToWorldH 给世界房主发消息 func (g *Game) SendToWorldH(world *World, cmdId uint16, seq uint32, msg pb.Message) { - GAME.SendMsg(cmdId, world.GetOwner().PlayerID, seq, msg) + g.SendMsg(cmdId, world.GetOwner().PlayerID, seq, msg) } // SendToSceneA 给场景内所有玩家发消息 @@ -402,11 +402,11 @@ func (g *Game) SendToSceneA(scene *Scene, cmdId uint16, seq uint32, msg pb.Messa bigWorldAoi := world.GetBigWorldAoi() otherWorldAvatarMap := bigWorldAoi.GetObjectListByPos(float32(SELF.Pos.X), float32(SELF.Pos.Y), float32(SELF.Pos.Z)) for uid := range otherWorldAvatarMap { - GAME.SendMsg(cmdId, uint32(uid), seq, msg) + g.SendMsg(cmdId, uint32(uid), seq, msg) } } else { for _, v := range scene.GetAllPlayer() { - GAME.SendMsg(cmdId, v.PlayerID, seq, msg) + g.SendMsg(cmdId, v.PlayerID, seq, msg) } } } @@ -421,14 +421,14 @@ func (g *Game) SendToSceneAEC(scene *Scene, cmdId uint16, seq uint32, msg pb.Mes if aecUid == uint32(uid) { continue } - GAME.SendMsg(cmdId, uint32(uid), seq, msg) + g.SendMsg(cmdId, uint32(uid), seq, msg) } } else { for _, v := range scene.GetAllPlayer() { if aecUid == v.PlayerID { continue } - GAME.SendMsg(cmdId, v.PlayerID, seq, msg) + g.SendMsg(cmdId, v.PlayerID, seq, msg) } } } diff --git a/gs/game/game_route_manager.go b/gs/game/game_route_manager.go index 989ec32e..97715d9d 100644 --- a/gs/game/game_route_manager.go +++ b/gs/game/game_route_manager.go @@ -110,6 +110,7 @@ func (r *RouteManager) initRoute() { r.registerRouter(cmd.PlayerEnterDungeonReq, GAME.PlayerEnterDungeonReq) r.registerRouter(cmd.PlayerQuitDungeonReq, GAME.PlayerQuitDungeonReq) r.registerRouter(cmd.GadgetInteractReq, GAME.GadgetInteractReq) + r.registerRouter(cmd.GmTalkReq, GAME.GmTalkReq) } type HandlerFunc func(player *model.Player, payloadMsg pb.Message) diff --git a/gs/game/player_common.go b/gs/game/player_common.go index 0667d712..f849c994 100644 --- a/gs/game/player_common.go +++ b/gs/game/player_common.go @@ -2,6 +2,7 @@ package game import ( "math" + "strings" "time" "hk4e/common/constant" @@ -136,7 +137,7 @@ func (g *Game) WorldPlayerRTTNotify(world *World) { playerRTTInfo := &proto.PlayerRTTInfo{Uid: worldPlayer.PlayerID, Rtt: worldPlayer.ClientRTT} worldPlayerRTTNotify.PlayerRttList = append(worldPlayerRTTNotify.PlayerRttList, playerRTTInfo) } - GAME.SendToWorldA(world, cmd.WorldPlayerRTTNotify, 0, worldPlayerRTTNotify) + g.SendToWorldA(world, cmd.WorldPlayerRTTNotify, 0, worldPlayerRTTNotify) } // WorldPlayerLocationNotify 多人世界其他玩家的坐标位置广播 @@ -163,7 +164,7 @@ func (g *Game) WorldPlayerLocationNotify(world *World) { } worldPlayerLocationNotify.PlayerWorldLocList = append(worldPlayerLocationNotify.PlayerWorldLocList, playerWorldLocationInfo) } - GAME.SendToWorldA(world, cmd.WorldPlayerLocationNotify, 0, worldPlayerLocationNotify) + g.SendToWorldA(world, cmd.WorldPlayerLocationNotify, 0, worldPlayerLocationNotify) } func (g *Game) ScenePlayerLocationNotify(world *World) { @@ -219,7 +220,7 @@ func (g *Game) ScenePlayerLocationNotify(world *World) { } } } - GAME.SendToSceneA(scene, cmd.ScenePlayerLocationNotify, 0, scenePlayerLocationNotify) + g.SendToSceneA(scene, cmd.ScenePlayerLocationNotify, 0, scenePlayerLocationNotify) } } @@ -230,7 +231,7 @@ func (g *Game) SceneTimeNotify(world *World) { SceneId: player.SceneId, SceneTime: uint64(scene.GetSceneTime()), } - GAME.SendMsg(cmd.SceneTimeNotify, player.PlayerID, 0, sceneTimeNotify) + g.SendMsg(cmd.SceneTimeNotify, player.PlayerID, 0, sceneTimeNotify) } } } @@ -242,6 +243,22 @@ func (g *Game) PlayerTimeNotify(world *World) { PlayerTime: uint64(player.TotalOnlineTime), ServerTime: uint64(time.Now().UnixMilli()), } - GAME.SendMsg(cmd.PlayerTimeNotify, player.PlayerID, 0, playerTimeNotify) + g.SendMsg(cmd.PlayerTimeNotify, player.PlayerID, 0, playerTimeNotify) } } + +func (g *Game) GmTalkReq(player *model.Player, payloadMsg pb.Message) { + req := payloadMsg.(*proto.GmTalkReq) + logger.Info("GmTalkReq: %v", req.Msg) + commandText := strings.TrimSpace(req.Msg) + beginIndex := strings.Index(commandText, "(") + endIndex := strings.Index(commandText, ")") + if beginIndex == 0 || beginIndex == -1 || endIndex == -1 || beginIndex >= endIndex { + g.SendMsg(cmd.GmTalkRsp, player.PlayerID, player.ClientSeq, &proto.GmTalkRsp{Retmsg: "命令解析失败", Msg: req.Msg}) + return + } + funcName := commandText[:beginIndex] + paramList := strings.Split(commandText[beginIndex:endIndex+1], ",") + COMMAND_MANAGER.HandleCommand(&CommandMessage{FuncName: funcName, ParamList: paramList}) + g.SendMsg(cmd.GmTalkRsp, player.PlayerID, player.ClientSeq, &proto.GmTalkRsp{Retmsg: "执行成功", Msg: req.Msg}) +} diff --git a/gs/game/player_gcg.go b/gs/game/player_gcg.go index df6ab5ae..fc655f8a 100644 --- a/gs/game/player_gcg.go +++ b/gs/game/player_gcg.go @@ -59,7 +59,7 @@ func (g *Game) GCGStartChallenge(player *model.Player) { game := GCG_MANAGER.CreateGame(30101, []*model.Player{player}) // GCG游戏简要信息通知 - GAME.SendMsg(cmd.GCGGameBriefDataNotify, player.PlayerID, player.ClientSeq, + g.SendMsg(cmd.GCGGameBriefDataNotify, player.PlayerID, player.ClientSeq, g.PacketGCGGameBriefDataNotify(player, proto.GCGGameBusinessType_GCG_GAME_GUIDE_GROUP, game)) // 玩家进入GCG界面 @@ -266,7 +266,7 @@ func (g *Game) GCGAskDuelReq(player *model.Player, payloadMsg pb.Message) { // }) // } - GAME.SendMsg(cmd.GCGAskDuelRsp, player.PlayerID, player.ClientSeq, gcgAskDuelRsp) + g.SendMsg(cmd.GCGAskDuelRsp, player.PlayerID, player.ClientSeq, gcgAskDuelRsp) } // GCGInitFinishReq GCG初始化完成请求 @@ -287,7 +287,7 @@ func (g *Game) GCGInitFinishReq(player *model.Player, payloadMsg pb.Message) { // 更改操控者加载状态 gameController.loadState = ControllerLoadState_InitFinish - GAME.SendMsg(cmd.GCGInitFinishRsp, player.PlayerID, player.ClientSeq, &proto.GCGInitFinishRsp{}) + g.SendMsg(cmd.GCGInitFinishRsp, player.PlayerID, player.ClientSeq, &proto.GCGInitFinishRsp{}) // 检查所有玩家是否已加载完毕 game.CheckAllInitFinish() @@ -317,7 +317,7 @@ func (g *Game) GCGOperationReq(player *model.Player, payloadMsg pb.Message) { // 操作者是否拥有该卡牌 cardInfo := gameController.GetCharCardByGuid(op.CardGuid) if cardInfo == nil { - GAME.SendError(cmd.GCGOperationRsp, player, &proto.GCGOperationRsp{}, proto.Retcode_RET_GCG_SELECT_HAND_CARD_GUID_ERROR) + g.SendError(cmd.GCGOperationRsp, player, &proto.GCGOperationRsp{}, proto.Retcode_RET_GCG_SELECT_HAND_CARD_GUID_ERROR) return } // 操控者选择角色牌 @@ -364,7 +364,7 @@ func (g *Game) GCGOperationReq(player *model.Player, payloadMsg pb.Message) { gcgOperationRsp := &proto.GCGOperationRsp{ OpSeq: req.OpSeq, } - GAME.SendMsg(cmd.GCGOperationRsp, player.PlayerID, player.ClientSeq, gcgOperationRsp) + g.SendMsg(cmd.GCGOperationRsp, player.PlayerID, player.ClientSeq, gcgOperationRsp) } // PacketGCGSkillPreviewNotify GCG游戏技能预览通知 @@ -470,7 +470,7 @@ func (g *Game) SendGCGMessagePackNotify(controller *GCGController, serverSeq uin // 根据操控者的类型发送消息包 switch controller.controllerType { case ControllerType_Player: - GAME.SendMsg(cmd.GCGMessagePackNotify, controller.player.PlayerID, controller.player.ClientSeq, gcgMessagePackNotify) + g.SendMsg(cmd.GCGMessagePackNotify, controller.player.PlayerID, controller.player.ClientSeq, gcgMessagePackNotify) case ControllerType_AI: controller.ai.ReceiveGCGMessagePackNotify(gcgMessagePackNotify) default: diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index 3641f318..e1e986b6 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -1,6 +1,7 @@ package game import ( + "encoding/base64" "math" "strconv" "time" @@ -389,6 +390,24 @@ func (g *Game) PostEnterSceneReq(player *model.Player, payloadMsg pb.Message) { EnterSceneToken: req.EnterSceneToken, } g.SendMsg(cmd.PostEnterSceneRsp, player.PlayerID, player.ClientSeq, postEnterSceneRsp) + + // 开启live版本客户端的GM按钮 虽然没什么卵用 + // local btnGm = CS.UnityEngine.GameObject.Find("/Canvas/Pages/InLevelMainPage/GrpMainPage/GrpMainBtn/GrpMainToggle/GrpTopPanel/BtnGm") + // btnGm:SetActive(true) + luac, err := base64.StdEncoding.DecodeString("G0x1YVMBGZMNChoKBAQICHhWAAAAAAAAAAAAAAAod0ABCEBnbS5sdWEAAAAAAAAAAAABBAoAAAAkAEAAKUBAACmAQAApwEAAVgABACyAAAFdQEEA2ACAAGxAgAEZAIAABgAAAAQDQ1MEDFVuaXR5RW5naW5lBAtHYW1lT2JqZWN0BAVGaW5kFFUvQ2FudmFzL1BhZ2VzL0luTGV2ZWxNYWluUGFnZS9HcnBNYWluUGFnZS9HcnBNYWluQnRuL0dycE1haW5Ub2dnbGUvR3JwVG9wUGFuZWwvQnRuR20EClNldEFjdGl2ZQEAAAABAAAAAAAKAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAgAAAAIAAAACAAAAAgAAAAEAAAAGYnRuR20GAAAACgAAAAEAAAAFX0VOVg==") + if err != nil { + logger.Error("decode luac error: %v", err) + return + } + GAME.SendMsg(cmd.WindSeedClientNotify, player.PlayerID, 0, &proto.WindSeedClientNotify{ + Notify: &proto.WindSeedClientNotify_AreaNotify_{ + AreaNotify: &proto.WindSeedClientNotify_AreaNotify{ + AreaCode: luac, + AreaId: 1, + AreaType: 1, + }, + }, + }) } func (g *Game) SceneEntityDrownReq(player *model.Player, payloadMsg pb.Message) { diff --git a/robot/cmd/main.go b/robot/cmd/main.go index ff2939d3..299c2d5c 100644 --- a/robot/cmd/main.go +++ b/robot/cmd/main.go @@ -89,6 +89,7 @@ func main() { defer messageQueue.Close() go runForward(messageQueue) + go runPacketCaptureApi() } else { go runRobot() } @@ -109,6 +110,18 @@ func main() { } } +func runPacketCaptureApi() { + gin.SetMode(gin.DebugMode) + engine := gin.Default() + engine.GET("/packet/capture/websocket", packetCaptureWebsocket) + engine.GET("/packet/capture/all", packetCaptureAll) + err := engine.Run(":9999") + if err != nil { + logger.Error("gin run error: %v", err) + return + } +} + var ForwardSession *net.Session = nil func packetCaptureWebsocket(ctx *gin.Context) { @@ -146,15 +159,6 @@ func packetCaptureAll(ctx *gin.Context) { } func runForward(messageQueue *mq.MessageQueue) { - gin.SetMode(gin.DebugMode) - engine := gin.Default() - engine.GET("/packet/capture/websocket", packetCaptureWebsocket) - engine.GET("/packet/capture/all", packetCaptureAll) - err := engine.Run(":9999") - if err != nil { - logger.Error("gin run error: %v", err) - return - } for { netMsg := <-messageQueue.GetNetMsg() if netMsg.OriginServerType != api.DISPATCH {