d500811b
zhangqijia
feat: 使用python3 自...
|
1
2
3
|
import os
ProtoCodeGO = './cmd/gameserver/action/protocode.go'
|
2ea16684
zhangqijia
fix: update
|
4
|
ProtoCodeGOTest = './cmd/test/action/protocode.go'
|
d500811b
zhangqijia
feat: 使用python3 自...
|
5
6
7
8
9
|
ProtoCodeFile = './protos/protocode.proto'
ProtoFileDir = "./protos"
ProtoCodeStr = "syntax = \"proto3\";\noption go_package = \"../pb;pb\";\n\npackage protocode;\n\nenum ProtoCode\n{{\n " \
"UNKNOWN = 0;\n {}\n}} "
|
2e0d2609
zhangqijia
fix: 英雄升级返回值+prot...
|
10
|
ProtoCodeLineReq = "\t{}Rpc = {};\n"
|
d500811b
zhangqijia
feat: 使用python3 自...
|
11
|
ProtoCodeLineRsp = "\t{}Rsp = {};\n"
|
23822e2f
zhangqijia
fix: update proto...
|
12
|
ProtoCodeLineNty = "\t{}Nty = {};\n"
|
d500811b
zhangqijia
feat: 使用python3 自...
|
13
14
15
16
|
GoProtoCodeStr = "package action\n\nimport (\n\t\"pro2d/common/logger\"\n\t\"pro2d/pb\"\n)\n\nfunc GetActionMap() " \
"map[interface{{}}]interface{{}} {{\n\tlogger.Debug(\"init protocode...\")\n\tam := make(map[interface{{" \
"}}]interface{{}})\n{}\n\treturn am\n}}"
|
2e0d2609
zhangqijia
fix: 英雄升级返回值+prot...
|
17
|
GoProtoCodeLine = "\tam[uint32(pb.ProtoCode_{}Rpc)] = {}Rpc\n"
|
d500811b
zhangqijia
feat: 使用python3 自...
|
18
|
|
2ea16684
zhangqijia
fix: update
|
19
20
21
|
GoProtoCodeTestStr = "package action\n\nimport (\n\t\"pro2d/pb\"\n)\n\nfunc GetTestActionMap() " \
"map[interface{{}}]interface{{}} {{\n\tam := make(map[interface{{" \
"}}]interface{{}})\n{}\n\treturn am\n}}"
|
2e0d2609
zhangqijia
fix: 英雄升级返回值+prot...
|
22
|
GoProtoCodeTestReqLine = "\tam[uint32(pb.ProtoCode_{}Rpc)] = {}Rsp\n"
|
2ea16684
zhangqijia
fix: update
|
23
|
GoProtoCodeTestRspLine = "\tam[uint32(pb.ProtoCode_{}Rsp)] = {}Rsp\n"
|
30e6d227
zhangqijia
fix: add nty
|
24
|
GoProtoCodeTestNtyLine = "\tam[uint32(pb.ProtoCode_{}Nty)] = {}Nty\n"
|
d500811b
zhangqijia
feat: 使用python3 自...
|
25
26
|
def generatorProto(path):
|
e172952c
zhangqijia
feat: email 系统搭建
|
27
28
29
|
RpcStartCode = 500
NtyStartCode = 1000
|
d500811b
zhangqijia
feat: 使用python3 自...
|
30
|
files = os.listdir(path)
|
d500811b
zhangqijia
feat: 使用python3 自...
|
31
32
|
ProtoCodeData = ""
GoCodeData = ""
|
2ea16684
zhangqijia
fix: update
|
33
|
GoCodeTestData = ""
|
d500811b
zhangqijia
feat: 使用python3 自...
|
34
|
for file in files:
|
a7566463
zhangqijia
fix: update proto...
|
35
36
37
|
if file.find("account.proto") != -1:
continue
|
d500811b
zhangqijia
feat: 使用python3 自...
|
38
39
40
41
42
43
44
45
46
|
if os.path.isdir(file):
continue
with open(path + "/" + file, 'r', encoding='utf-8', errors='ignore') as f:
lines = f.readlines() # 读取所有行
firstline = lines[0]
if firstline.find("proto3") == -1:
continue
|
e172952c
zhangqijia
feat: email 系统搭建
|
47
|
# req + rar
|
d500811b
zhangqijia
feat: 使用python3 自...
|
48
49
50
|
for line in lines:
if line.find("message") == -1:
continue
|
d500811b
zhangqijia
feat: 使用python3 自...
|
51
52
53
54
55
56
|
sline = line.split(' ')
if len(sline) < 2:
continue
messageStr = sline[1].replace('\n', '').replace('{', "")
n1 = messageStr.find('Req')
|
e172952c
zhangqijia
feat: email 系统搭建
|
57
|
n2 = messageStr.find('Rar')
|
3e92be67
zhangqijia
fix: 优化协议,除了登录和创建...
|
58
|
loginReq = messageStr.find('LoginReq')
|
d500811b
zhangqijia
feat: 使用python3 自...
|
59
60
|
if n1 != -1:
|
e172952c
zhangqijia
feat: email 系统搭建
|
61
62
|
RpcStartCode = RpcStartCode + 1
ProtoCodeData += ProtoCodeLineReq.format(messageStr[:n1], RpcStartCode)
|
a7566463
zhangqijia
fix: update proto...
|
63
64
|
if loginReq != -1:
continue
|
d500811b
zhangqijia
feat: 使用python3 自...
|
65
|
GoCodeData += GoProtoCodeLine.format(messageStr[:n1], messageStr[:n1])
|
2ea16684
zhangqijia
fix: update
|
66
|
GoCodeTestData += GoProtoCodeTestReqLine.format(messageStr[:n1], messageStr[:n1])
|
e172952c
zhangqijia
feat: email 系统搭建
|
67
68
69
|
elif n2 != -1:
RpcStartCode = RpcStartCode + 1
ProtoCodeData += ProtoCodeLineReq.format(messageStr[:n2], RpcStartCode)
|
f8ce769e
zhangqijia
fix: rpc = rar + ...
|
70
71
72
73
|
if loginReq != -1:
continue
GoCodeData += GoProtoCodeLine.format(messageStr[:n2], messageStr[:n2])
GoCodeTestData += GoProtoCodeTestReqLine.format(messageStr[:n2], messageStr[:n2])
|
e172952c
zhangqijia
feat: email 系统搭建
|
74
|
ProtoCodeData += '\n'
|
30e6d227
zhangqijia
fix: add nty
|
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# nty
for line in lines:
if line.find("message") == -1:
continue
sline = line.split(' ')
if len(sline) < 2:
continue
messageStr = sline[1].replace('\n', '').replace('{', "")
n3 = messageStr.find('Nty')
loginReq = messageStr.find('LoginReq')
if n3 != -1:
|
e172952c
zhangqijia
feat: email 系统搭建
|
88
89
|
NtyStartCode = NtyStartCode + 1
ProtoCodeData += ProtoCodeLineNty.format(messageStr[:n3], NtyStartCode)
|
30e6d227
zhangqijia
fix: add nty
|
90
91
92
93
|
if loginReq != -1:
continue
GoCodeTestData += GoProtoCodeTestNtyLine.format(messageStr[:n3], messageStr[:n3])
|
f8ce769e
zhangqijia
fix: rpc = rar + ...
|
94
|
|
a0fb8df9
zhangqijia
fix: update nty
|
95
|
|
2ea16684
zhangqijia
fix: update
|
96
|
|
d500811b
zhangqijia
feat: 使用python3 自...
|
97
98
99
100
101
102
|
# protocode.go
gostr = GoProtoCodeStr.format(GoCodeData)
fo = open(ProtoCodeGO, "w")
fo.write(gostr)
fo.close()
|
2ea16684
zhangqijia
fix: update
|
103
104
105
106
107
108
|
# protocode.go
gostr = GoProtoCodeTestStr.format(GoCodeTestData)
fo = open(ProtoCodeGOTest, "w")
fo.write(gostr)
fo.close()
|
d500811b
zhangqijia
feat: 使用python3 自...
|
109
110
111
112
113
114
115
116
117
|
#protocode.proto
protostr = ProtoCodeStr.format(ProtoCodeData)
fo = open(ProtoCodeFile, "w")
fo.write(protostr)
fo.close()
if __name__ == "__main__":
generatorProto(ProtoFileDir)
|