summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xservergreps/hercules/src/brathena.py9
-rwxr-xr-xservergreps/hercules/src/hercules.py41
-rwxr-xr-xservergreps/hercules/src/idathena.py9
-rwxr-xr-xservergreps/hercules/src/ragemu.py9
-rwxr-xr-xservergreps/hercules/src/rathena.py9
-rwxr-xr-xservergreps/hercules/src/threeceam.py9
-rwxr-xr-xservergreps/hercules/src/utils.py47
7 files changed, 97 insertions, 36 deletions
diff --git a/servergreps/hercules/src/brathena.py b/servergreps/hercules/src/brathena.py
index c1ce5f3..b93d18e 100755
--- a/servergreps/hercules/src/brathena.py
+++ b/servergreps/hercules/src/brathena.py
@@ -8,6 +8,7 @@ import os
import re
from src.preproc import PreProc
+from src.utils import Utils
filt = re.compile(".+[.](c|h)", re.IGNORECASE)
@@ -165,6 +166,12 @@ class Brathena:
self.functionToId[m.group("function")] = data
+ def collectCharInPackets(self, charFilePackets):
+ for packets in Utils.enumCasePackets(charFilePackets, "int char_parse_char(int fd)"):
+ self.inPackets[packets[1]] = (0, packets[0])
+ self.functionToId[packets[0]] = packets[1]
+
+
def sortInPackets(self):
for packet in self.inPackets:
self.inPacketsSorted.append(packet)
@@ -175,9 +182,11 @@ class Brathena:
namedPacketsPath = packetDir + "/src/" + self.dirName + "/packets_struct.h"
srcPath = packetDir + "/src/" + self.dirName
serverInPacketsHPath = packetDir + "/src/" + self.dirName + "/packets.h"
+ serverCharPackets = packetDir + "/src/" + self.dirName + "/char.c"
self.collectNamedPackets(namedPacketsPath)
self.collectOutPackets(srcPath)
self.collectInPackets(serverInPacketsHPath)
+ self.collectCharInPackets(serverCharPackets);
self.sortInPackets()
self.sortOutPackets()
diff --git a/servergreps/hercules/src/hercules.py b/servergreps/hercules/src/hercules.py
index cb5c3d3..c2f41d3 100755
--- a/servergreps/hercules/src/hercules.py
+++ b/servergreps/hercules/src/hercules.py
@@ -8,6 +8,7 @@ import os
import re
from src.preproc import PreProc
+from src.utils import Utils
filt = re.compile(".+[.](c|h)", re.IGNORECASE)
@@ -51,9 +52,6 @@ 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:
@@ -201,39 +199,10 @@ class Hercules:
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
+ for packets in Utils.enumCasePackets(charFilePackets, "int char_parse_char(int fd)"):
+ self.inPackets[packets[1]] = (0, packets[0])
+ self.functionToId[packets[0]] = packets[1]
+
def sortInPackets(self):
for packet in self.inPackets:
diff --git a/servergreps/hercules/src/idathena.py b/servergreps/hercules/src/idathena.py
index 9e95237..a52b1d2 100755
--- a/servergreps/hercules/src/idathena.py
+++ b/servergreps/hercules/src/idathena.py
@@ -8,6 +8,7 @@ import os
import re
from src.preproc import PreProc
+from src.utils import Utils
filt = re.compile(".+[.](c|h)", re.IGNORECASE)
@@ -186,6 +187,12 @@ class Idathena:
self.functionToId[m.group("function")] = data
+ def collectCharInPackets(self, charFilePackets):
+ for packets in Utils.enumCasePackets(charFilePackets, "int char_parse_char(int fd)"):
+ self.inPackets[packets[1]] = (0, packets[0])
+ self.functionToId[packets[0]] = packets[1]
+
+
def sortInPackets(self):
for packet in self.inPackets:
self.inPacketsSorted.append(packet)
@@ -197,9 +204,11 @@ class Idathena:
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()
diff --git a/servergreps/hercules/src/ragemu.py b/servergreps/hercules/src/ragemu.py
index dc47ff6..e46d15b 100755
--- a/servergreps/hercules/src/ragemu.py
+++ b/servergreps/hercules/src/ragemu.py
@@ -8,6 +8,7 @@ import os
import re
from src.preproc import PreProc
+from src.utils import Utils
filt = re.compile(".+[.](c|h)", re.IGNORECASE)
@@ -176,6 +177,12 @@ class Ragemu:
self.functionToId[m.group("function")] = data
+ def collectCharInPackets(self, charFilePackets):
+ for packets in Utils.enumCasePackets(charFilePackets, "int char_parse_char(int fd)"):
+ self.inPackets[packets[1]] = (0, packets[0])
+ self.functionToId[packets[0]] = packets[1]
+
+
def sortInPackets(self):
for packet in self.inPackets:
self.inPacketsSorted.append(packet)
@@ -187,9 +194,11 @@ class Ragemu:
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()
diff --git a/servergreps/hercules/src/rathena.py b/servergreps/hercules/src/rathena.py
index 05dccc8..28c6c2e 100755
--- a/servergreps/hercules/src/rathena.py
+++ b/servergreps/hercules/src/rathena.py
@@ -8,6 +8,7 @@ import os
import re
from src.preproc import PreProc
+from src.utils import Utils
filt = re.compile(".+[.](c|h)", re.IGNORECASE)
@@ -186,6 +187,12 @@ class Rathena:
self.functionToId[m.group("function")] = data
+ def collectCharInPackets(self, charFilePackets):
+ for packets in Utils.enumCasePackets(charFilePackets, "int char_parse_char(int fd)"):
+ self.inPackets[packets[1]] = (0, packets[0])
+ self.functionToId[packets[0]] = packets[1]
+
+
def sortInPackets(self):
for packet in self.inPackets:
self.inPacketsSorted.append(packet)
@@ -197,9 +204,11 @@ class Rathena:
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_clif.c"
# self.collectNamedPackets(namedPacketsPath)
self.collectOutPackets(srcPath)
# self.collectInPackets(serverInPacketsHPath, serverLoginInPackets)
+# self.collectCharInPackets(serverCharPackets);
# self.sortInPackets()
self.sortOutPackets()
diff --git a/servergreps/hercules/src/threeceam.py b/servergreps/hercules/src/threeceam.py
index 4b9fd02..77e1f19 100755
--- a/servergreps/hercules/src/threeceam.py
+++ b/servergreps/hercules/src/threeceam.py
@@ -8,6 +8,7 @@ import os
import re
from src.preproc import PreProc
+from src.utils import Utils
filt = re.compile(".+[.](c|h)", re.IGNORECASE)
@@ -194,6 +195,12 @@ class Threeceam:
self.functionToId[m.group("function")] = data
+ def collectCharInPackets(self, charFilePackets):
+ for packets in Utils.enumCasePackets(charFilePackets, "int char_parse_char(int fd)"):
+ self.inPackets[packets[1]] = (0, packets[0])
+ self.functionToId[packets[0]] = packets[1]
+
+
def sortInPackets(self):
for packet in self.inPackets:
self.inPacketsSorted.append(packet)
@@ -205,9 +212,11 @@ class Threeceam:
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()
diff --git a/servergreps/hercules/src/utils.py b/servergreps/hercules/src/utils.py
new file mode 100755
index 0000000..e43d7e2
--- /dev/null
+++ b/servergreps/hercules/src/utils.py
@@ -0,0 +1,47 @@
+#! /usr/bin/env python2
+# -*- coding: utf8 -*-
+#
+# Copyright (C) 2015-2016 Evol Online
+# Author: Andrei Karas (4144)
+
+import os
+import re
+
+class Utils:
+ casere = re.compile("^case 0x(?P<packet>[0-9a-fA-F]+)[:]")
+ charParseFunctionre = re.compile(
+ "(?P<function>chr->[0-9a-zA-Z_>-]+)([(]|[ ][(])");
+
+ @staticmethod
+ def enumCasePackets(fileName, startCode):
+ startCode = startCode + "\n"
+ endCode = "}\n"
+ breakCode = "break;"
+ with open(fileName, "r") as f:
+ for line in f:
+ if line == startCode:
+ packets = []
+ for line in f:
+ line = line.strip()
+ m = Utils.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 = Utils.charParseFunctionre.search(line)
+ if m is not None:
+ func = m.group("function")
+ if len(packets) > 1:
+ for packet in packets:
+ fname = func + "_" + str(packet)
+ yield (fname, packet)
+ else:
+ yield (func, packets[0])
+ break