summaryrefslogtreecommitdiff
path: root/servergreps/hercules/src/hercules.py
diff options
context:
space:
mode:
Diffstat (limited to 'servergreps/hercules/src/hercules.py')
-rwxr-xr-xservergreps/hercules/src/hercules.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/servergreps/hercules/src/hercules.py b/servergreps/hercules/src/hercules.py
index e08e559..cb5c3d3 100755
--- a/servergreps/hercules/src/hercules.py
+++ b/servergreps/hercules/src/hercules.py
@@ -51,6 +51,9 @@ class Hercules:
clientpacketLenre = re.compile(
"(\t*)packet[(]0x(?P<packet>[0-9a-fA-F]+),(?P<len>[\w-]+)" +
"[)]")
+ casere = re.compile("^case 0x(?P<packet>[0-9a-fA-F]+)[:]")
+ charParseFunctionre = re.compile(
+ "(?P<function>chr->[0-9a-zA-Z_>-]+)([(]|[ ][(])");
def collectNamedPackets(self, fileName):
with open(fileName, "r") as f:
@@ -197,6 +200,41 @@ class Hercules:
self.functionToId[m.group("function")] = data
+ def collectCharInPackets(self, charFilePackets):
+ startCode = "int char_parse_char(int fd)\n"
+ endCode = "}\n"
+ breakCode = "break;"
+ with open(charFilePackets, "r") as f:
+ for line in f:
+ if line == startCode:
+ packets = []
+ for line in f:
+ line = line.strip()
+ m = self.casere.search(line)
+ if m is not None:
+ data = m.group("packet").lower()
+ while len(data) < 4:
+ data = "0" + data
+ if int(data, 16) < 4096:
+ packets.append(data)
+ if line == breakCode:
+ packets = []
+ if line == endCode:
+ break
+ if len(packets) > 0:
+ m = self.charParseFunctionre.search(line)
+ if m is not None:
+ func = m.group("function")
+ if len(packets) > 1:
+ for packet in packets:
+ fname = func + "_" + str(packet)
+ self.inPackets[packet] = (0, fname)
+ self.functionToId[fname] = packet
+ else:
+ self.inPackets[packets[0]] = (0, func)
+ self.functionToId[func] = packets[0]
+ break
+
def sortInPackets(self):
for packet in self.inPackets:
self.inPacketsSorted.append(packet)
@@ -208,9 +246,11 @@ class Hercules:
srcPath = packetDir + "/src/" + self.dirName
serverInPacketsHPath = packetDir + "/src/" + self.dirName + "/packets.h"
serverLoginInPackets = packetDir + "/src/" + self.dirName + "/lclif.c"
+ serverCharPackets = packetDir + "/src/" + self.dirName + "/char.c"
self.collectNamedPackets(namedPacketsPath)
self.collectOutPackets(srcPath)
self.collectInPackets(serverInPacketsHPath, serverLoginInPackets)
+ self.collectCharInPackets(serverCharPackets);
self.sortInPackets()
self.sortOutPackets()