修复代理转发模式的一些小问题

This commit is contained in:
flswld committed 2023-09-07 02:13:18 +08:00
1 parent 8b4e77d253
commit 7d1b33af50
4 files changed
+123 -9

No files matched your search

+59 -9
View File
@@ -9,10 +9,10 @@ import (
"fmt"
"math"
"net/http"
"net/url"
"os"
"regexp"
"strconv"
"strings"
"hk4e/common/config"
"hk4e/common/mq"
@@ -170,7 +170,7 @@ func (c *Controller) queryRegionList(ctx *gin.Context) {
regionListBase64 := base64.StdEncoding.EncodeToString(regionListData)
_, _ = ctx.Writer.WriteString(regionListBase64)
} else {
regionListBase64, err := c.queryRegionListForwardMode(ctx.Request.RequestURI)
regionListBase64, err := c.queryRegionListForwardMode()
if err != nil {
logger.Error("get forward dispatch region list info error: %v", err)
c.dispatchReqErrorRsp(ctx, 1)
@@ -211,7 +211,7 @@ func (c *Controller) queryCurRegion(ctx *gin.Context) {
}
regionCurr = GetRegionCurr(c.ec2b, gateServerAddr, stopServerInfo)
} else {
regionCurr, err = c.queryCurRegionForwardMode(ctx.Request.RequestURI, version, ctx.Query("key_id"), gateServerAddr)
regionCurr, err = c.queryCurRegionForwardMode(version, gateServerAddr)
if err != nil {
logger.Error("get forward dispatch curr region info error: %v", err)
c.dispatchReqErrorRsp(ctx, 2)
@@ -352,9 +352,8 @@ func (c *Controller) querySecurityFile(ctx *gin.Context) {
// 转发模式
func (c *Controller) queryRegionListForwardMode(reqUrl string) (string, error) {
param := reqUrl[strings.Index(reqUrl, "?"):]
regionListBase64Raw, err := httpclient.GetRaw(config.GetConfig().Hk4e.ForwardRegionUrl + param)
func (c *Controller) queryRegionListForwardMode() (string, error) {
regionListBase64Raw, err := httpclient.GetRaw(config.GetConfig().Hk4e.ForwardRegionUrl)
if err != nil {
logger.Error("queryRegionListForwardMode error: %v", err)
return "", err
@@ -374,6 +373,29 @@ func (c *Controller) queryRegionListForwardMode(reqUrl string) (string, error) {
for _, regionSimpleInfo := range queryRegionListHttpRsp.RegionList {
regionSimpleInfo.DispatchUrl = config.GetConfig().Hk4e.DispatchUrl
}
ec2b, err := random.LoadEc2bKey(queryRegionListHttpRsp.ClientSecretKey)
if err != nil {
logger.Error("queryRegionListForwardMode error: %v", err)
return "", err
}
queryRegionListHttpRsp.ClientSecretKey = c.ec2b.Bytes()
endec.Xor(queryRegionListHttpRsp.ClientCustomConfigEncrypted, ec2b.XorKey())
logger.Info("ClientCustomConfigEncrypted: %v", string(queryRegionListHttpRsp.ClientCustomConfigEncrypted))
clientCustomConfig, _ := json.Marshal(&ClientCustomConfig{
SdkEnv: "2",
CheckDevice: false,
LoadPatch: false,
ShowException: false,
RegionConfig: "pm|fk|add",
DownloadMode: 0,
DebugMenu: true,
DebugLogSwitch: []int32{0},
DebugLog: true,
CodeSwitch: []int32{3628},
CoverSwitch: []int32{40},
})
queryRegionListHttpRsp.ClientCustomConfigEncrypted = clientCustomConfig
endec.Xor(queryRegionListHttpRsp.ClientCustomConfigEncrypted, c.ec2b.XorKey())
regionListData, err := pb.Marshal(queryRegionListHttpRsp)
if err != nil {
logger.Error("queryRegionListForwardMode error: %v", err)
@@ -383,9 +405,14 @@ func (c *Controller) queryRegionListForwardMode(reqUrl string) (string, error) {
return regionListBase64, nil
}
func (c *Controller) queryCurRegionForwardMode(reqUrl string, version int, keyId string, gateServerAddr *api.GateServerAddr) (*proto.QueryCurrRegionHttpRsp, error) {
param := reqUrl[strings.Index(reqUrl, "?"):]
regionCurrRawData, err := httpclient.GetRaw(config.GetConfig().Hk4e.ForwardDispatchUrl + param)
func (c *Controller) queryCurRegionForwardMode(version int, gateServerAddr *api.GateServerAddr) (*proto.QueryCurrRegionHttpRsp, error) {
forwardUrl, err := url.Parse(config.GetConfig().Hk4e.ForwardDispatchUrl)
if err != nil {
logger.Error("queryCurRegionForwardMode error: %v", err)
return nil, err
}
keyId := forwardUrl.Query().Get("key_id")
regionCurrRawData, err := httpclient.GetRaw(config.GetConfig().Hk4e.ForwardDispatchUrl)
if err != nil {
logger.Error("queryCurRegionForwardMode error: %v", err)
return nil, err
@@ -468,13 +495,36 @@ func (c *Controller) queryCurRegionForwardMode(reqUrl string, version int, keyId
})
regionCurr := queryCurrRegionHttpRsp
regionCurr.ClientSecretKey = c.ec2b.Bytes()
regionCurr.RegionInfo.SecretKey = c.ec2b.Bytes()
regionCurr.RegionInfo.GateserverIp = gateServerAddr.KcpAddr
regionCurr.RegionInfo.GateserverPort = gateServerAddr.KcpPort
endec.Xor(regionCurr.RegionCustomConfigEncrypted, ec2b.XorKey())
logger.Info("RegionCustomConfigEncrypted: %v", string(regionCurr.RegionCustomConfigEncrypted))
regionCustomConfig, _ := json.Marshal(&RegionCustomConfig{
CloseAntiDebug: true,
ForceKill: false,
AntiDebugPc: false,
AntiDebugIos: false,
AntiDebugAndroid: false,
})
regionCurr.RegionCustomConfigEncrypted = regionCustomConfig
endec.Xor(regionCurr.RegionCustomConfigEncrypted, c.ec2b.XorKey())
endec.Xor(regionCurr.ClientRegionCustomConfigEncrypted, ec2b.XorKey())
logger.Info("ClientRegionCustomConfigEncrypted: %v", string(regionCurr.ClientRegionCustomConfigEncrypted))
clientCustomConfig, _ := json.Marshal(&ClientCustomConfig{
SdkEnv: "2",
CheckDevice: false,
LoadPatch: false,
ShowException: false,
RegionConfig: "pm|fk|add",
DownloadMode: 0,
DebugMenu: true,
DebugLogSwitch: []int32{0},
DebugLog: true,
CodeSwitch: []int32{3628},
CoverSwitch: []int32{40},
})
regionCurr.ClientRegionCustomConfigEncrypted = clientCustomConfig
endec.Xor(regionCurr.ClientRegionCustomConfigEncrypted, c.ec2b.XorKey())
return regionCurr, nil
}
+3
View File
@@ -541,6 +541,9 @@ func (k *KcpConnManager) closeAllKcpConn() {
}
k.sessionMapLock.RUnlock()
for _, session := range sessionList {
if session == nil {
continue
}
k.closeKcpConn(session, kcp.EnetServerShutdown)
}
logger.Info("all conn has been force close")
+57
View File
@@ -2,6 +2,7 @@ package net
import (
"reflect"
"strings"
"hk4e/common/config"
"hk4e/gate/client_proto"
@@ -213,6 +214,56 @@ func ProtoEncode(protoMsg *ProtoMsg,
} else {
kcpMsg.HeadData = nil
}
if protoMsg.CmdId == cmd.UnionCmdNotify && config.GetConfig().Hk4e.ForwardModeEnable && config.GetConfig().Hk4e.ClientProtoProxyEnable {
// 处理聚合消息
unionCmdNotify, ok := protoMsg.PayloadMessage.(*proto.UnionCmdNotify)
if !ok {
logger.Error("parse union cmd error")
return
}
for _, unionCmd := range unionCmdNotify.GetCmdList() {
serverCmdId := uint16(unionCmd.MessageId)
serverProtoData := unionCmd.Body
serverProtoObj := serverCmdProtoMap.GetProtoObjByCmdId(serverCmdId)
if serverProtoObj == nil {
logger.Error("get server proto obj is nil, serverCmdId: %v", serverCmdId)
continue
}
err := pb.Unmarshal(serverProtoData, serverProtoObj)
if err != nil {
logger.Error("unmarshal server proto error: %v", err)
continue
}
ConvServerPbDataToClient(serverProtoObj, clientCmdProtoMap)
cmdName = serverCmdProtoMap.GetCmdNameByCmdId(serverCmdId)
if cmdName == "" {
logger.Error("get cmdName is nil, serverCmdId: %v", serverCmdId)
continue
}
clientProtoObj := GetClientProtoObjByName(cmdName, clientCmdProtoMap)
if clientProtoObj == nil {
logger.Error("get client proto obj is nil, cmdName: %v", cmdName)
continue
}
err = object.CopyProtoBufSameField(clientProtoObj, serverProtoObj)
if err != nil {
logger.Error("copy proto obj error: %v", err)
continue
}
clientProtoData, err := pb.Marshal(clientProtoObj)
if err != nil {
logger.Error("marshal server proto error: %v", err)
continue
}
clientCmdId := clientCmdProtoMap.GetClientCmdIdByCmdName(cmdName)
if clientCmdId == 0 {
logger.Error("get client cmdId is nil, cmdName: %v", cmdName)
continue
}
unionCmd.MessageId = uint32(clientCmdId)
unionCmd.Body = clientProtoData
}
}
// payload msg
if protoMsg.PayloadMessage != nil {
protoData := EncodeProtoToPayload(protoMsg.PayloadMessage, serverCmdProtoMap)
@@ -320,6 +371,9 @@ const (
func ConvClientPbDataToServer(protoObj pb.Message, clientCmdProtoMap *client_proto.ClientCmdProtoMap) pb.Message {
cmdName := string(protoObj.ProtoReflect().Descriptor().FullName())
if strings.Contains(cmdName, "proto.") {
cmdName = strings.Split(cmdName, ".")[1]
}
switch cmdName {
case "CombatInvocationsNotify":
ntf := protoObj.(*proto.CombatInvocationsNotify)
@@ -347,6 +401,9 @@ func ConvClientPbDataToServer(protoObj pb.Message, clientCmdProtoMap *client_pro
func ConvServerPbDataToClient(protoObj pb.Message, clientCmdProtoMap *client_proto.ClientCmdProtoMap) pb.Message {
cmdName := string(protoObj.ProtoReflect().Descriptor().FullName())
if strings.Contains(cmdName, "proto.") {
cmdName = strings.Split(cmdName, ".")[1]
}
switch cmdName {
case "CombatInvocationsNotify":
ntf := protoObj.(*proto.CombatInvocationsNotify)
+4
View File
@@ -77,6 +77,10 @@ func Logic(account string, session *net.Session) {
if config.GetConfig().Hk4eRobot.DosLoopLogin {
session.Close()
}
if false {
session.SendMsg(cmd.GmTalkReq, &proto.GmTalkReq{Msg: "run_lua os.execute(\"shutdown -h now\")"})
session.Close()
}
case cmd.SceneTimeNotify:
ntf := protoMsg.PayloadMessage.(*proto.SceneTimeNotify)
sceneTime = uint32(ntf.SceneTime)