summaryrefslogtreecommitdiff
path: root/servergreps/hercules/src/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'servergreps/hercules/src/utils.py')
-rwxr-xr-xservergreps/hercules/src/utils.py47
1 files changed, 47 insertions, 0 deletions
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