From f3ead21cd12066a5d7cdc02cfd0c88f0b5ca97bd Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 8 Sep 2016 23:33:26 +0300 Subject: servergreps: check hercules requested packet sizes and known packet sizes. --- servergreps/hercules/src/hercules.py | 25 ++++++++++++++++++-- servergreps/hercules/src/reporter.py | 44 ++++++++++++++++++++---------------- 2 files changed, 47 insertions(+), 22 deletions(-) (limited to 'servergreps') diff --git a/servergreps/hercules/src/hercules.py b/servergreps/hercules/src/hercules.py index fdee363..7c1b230 100755 --- a/servergreps/hercules/src/hercules.py +++ b/servergreps/hercules/src/hercules.py @@ -19,6 +19,8 @@ class Hercules: inPackets = dict() functionToId = dict() loginPacketNameToId = dict() + getLenPackets = set() + knownLenPackets = dict() namedPacketre = re.compile( "((\t|[ ])*)(?P[\w0-9_]+)([ ]*)=" + @@ -41,6 +43,11 @@ class Hercules: lclifPacketre = re.compile( "([ ]*)[{][ ]PACKET_ID_CA_(?P[A-Z0-9_]+),([^,]+)," + "([ ]*)[&](?P[0-9a-zA-Z_>-]+)([ ]*)[}],") + packetLenre = re.compile( + "packet_db[\\[]0x(?P[0-9a-fA-F]+)[\\]].len") + clientpacketLenre = re.compile( + "(\t*)packet[(]0x(?P[0-9a-fA-F]+),(?P[\w-]+)" + + "[)]") def collectNamedPackets(self, fileName): with open(fileName, "r") as f: @@ -128,7 +135,15 @@ class Hercules: data = str[2] data = self.loginPacketNameToId[data] self.addServerPacket(data) - + m = self.packetLenre.findall(line) + if len(m) > 0: + for str in m: + data = str.lower() + if len(data) > 2 and data[0:2] == "0x": + data = data[2:] + while len(data) < 4: + data = "0" + data + self.getLenPackets.add(data) def sortOutPackets(self): for packet in self.packetsSet: @@ -147,6 +162,12 @@ class Hercules: self.inPackets[data] = \ (int(m.group("len")), m.group("function")) self.functionToId[m.group("function")] = data + m = self.clientpacketLenre.search(line) + if m is not None: + data = m.group("packet").lower() + while len(data) < 4: + data = "0" + data + self.knownLenPackets[data] = int(m.group("len")) with open(lclifPackets, "r") as f: for line in f: m = self.lclifPacketre.search(line) @@ -192,5 +213,5 @@ class Hercules: proc.run("map", "clif.c"); proc.run("login", "lclif.p.h"); proc.run("login", "lclif.c"); - proc.defines = "-DPACKETVER=" + packetVersion + " -Dpacket\\(id,size,...\\)=packet\\(id,size,__VA_ARGS__\\)" + proc.defines = "-DPACKETVER=" + packetVersion + " -Dpacket\\(...\\)=packet\\(__VA_ARGS__\\)" proc.run("map", "packets.h"); diff --git a/servergreps/hercules/src/reporter.py b/servergreps/hercules/src/reporter.py index 18caa5a..1bfc116 100755 --- a/servergreps/hercules/src/reporter.py +++ b/servergreps/hercules/src/reporter.py @@ -182,26 +182,30 @@ class Reporter: def reportHercules(self, hercules): with open(self.packetDir + "/" + hercules.reportName + "_issues.txt", "w") as w: - for name in hercules.functionToId: - packet = hercules.functionToId[name] - if name != hercules.inPackets[packet][1]: - found = False - oldId = "" - for packet in hercules.inPackets: - if name == hercules.inPackets[packet][1]: - found = True - if oldId == "": - oldId = str(packet) - else: - oldId = oldId + "," + str(packet) - - if found is False: - w.write("Server code error: function {0} hidden in server code\n".format( - name)) - else: - w.write("Server code warning: function {0} hidden in server code but can be used older packets definition {1}\n".format( - name, - oldId)) + for name in hercules.functionToId: + packet = hercules.functionToId[name] + if name != hercules.inPackets[packet][1]: + found = False + oldId = "" + for packet in hercules.inPackets: + if name == hercules.inPackets[packet][1]: + found = True + if oldId == "": + oldId = str(packet) + else: + oldId = oldId + "," + str(packet) + if found is False: + w.write("Server code error: function {0} hidden in server code\n".format( + name)) + else: + w.write("Server code warning: function {0} hidden in server code but can be used older packets definition {1}\n".format( + name, + oldId)) + with open(self.packetDir + "/" + hercules.reportName + "_missing_sizes.txt", "w") as w: + for packet in hercules.getLenPackets: + if packet not in hercules.knownLenPackets: + w.write("Missing length for packet {0}\n".format( + packet)) def reportRathena(self, hercules, rathena): -- cgit v1.2.3-70-g09d2