mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 15:52:27 +08:00
客户端协议代理功能
This commit is contained in:
16
gate/client_proto/README.md
Normal file
16
gate/client_proto/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# 客户端协议代理功能
|
||||
|
||||
## 功能介绍
|
||||
|
||||
### 开启本功能后,网关服务器以及游戏服务器等其他服务器,将预先对客户端上行和服务器下行的协议数据做前置转换,采用任意版本的协议文件(必要字段名必须与现有的协议保持一致)均可,避免了因协议序号混淆等频繁变动,而造成游戏服务器代码不必要的频繁改动
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 在此目录下建立bin目录和proto目录
|
||||
2. 将client_cmd.csv文件放到bin目录下
|
||||
3. 将对应版本的proto协议文件复制到proto目录下并编译成pb.go
|
||||
4. 将client_proto_gen_test.go的TestClientProtoGen方法添加运行配置
|
||||
5. 将运行配置输出目录和工作目录都设置为bin目录
|
||||
6. 运行并生成client_proto_gen.go
|
||||
7. 将client_cmd.csv放入gate和gs和fight服务器的运行目录下
|
||||
8. 将gate和gs和fight服务器的配置文件中开启client_proto_proxy_enable客户端协议代理功能
|
||||
@@ -2,11 +2,23 @@ package client_proto
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestClientProtoGen(t *testing.T) {
|
||||
clientCmdProtoMap := NewClientCmdProtoMap()
|
||||
dir, err := os.ReadDir("../proto")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
nameList := make([]string, 0)
|
||||
for _, entry := range dir {
|
||||
split := strings.Split(entry.Name(), ".")
|
||||
if len(split) != 2 {
|
||||
panic("file name error")
|
||||
}
|
||||
nameList = append(nameList, split[0])
|
||||
}
|
||||
|
||||
fileData := "package client_proto\n"
|
||||
fileData += "\n"
|
||||
@@ -15,10 +27,10 @@ func TestClientProtoGen(t *testing.T) {
|
||||
fileData += "pb \"google.golang.org/protobuf/proto\"\n"
|
||||
fileData += ")\n"
|
||||
fileData += "\n"
|
||||
fileData += "func (c *ClientCmdProtoMap) GetClientProtoObjByCmdName(cmdName string) pb.Message {\n"
|
||||
fileData += "switch cmdName {\n"
|
||||
for cmdName := range clientCmdProtoMap.clientCmdNameCmdIdMap {
|
||||
fileData += "case \"" + cmdName + "\":\nreturn new(proto." + cmdName + ")\n"
|
||||
fileData += "func (c *ClientCmdProtoMap) GetClientProtoObjByName(protoObjName string) pb.Message {\n"
|
||||
fileData += "switch protoObjName {\n"
|
||||
for _, protoObjName := range nameList {
|
||||
fileData += "case \"" + protoObjName + "\":\nreturn new(proto." + protoObjName + ")\n"
|
||||
}
|
||||
fileData += "default:\n"
|
||||
fileData += "return nil\n"
|
||||
@@ -26,7 +38,7 @@ func TestClientProtoGen(t *testing.T) {
|
||||
fileData += "}\n"
|
||||
fileData += "\n"
|
||||
|
||||
err := os.WriteFile("../client_proto_gen.go", []byte(fileData), 0644)
|
||||
err = os.WriteFile("../client_proto_gen.go", []byte(fileData), 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user