summaryrefslogtreecommitdiff
path: root/servergreps
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-09-05 22:08:53 +0300
committerAndrei Karas <akaras@inbox.ru>2016-09-05 22:10:22 +0300
commit01403803a7550baeef2ae58c2563cdada7992c37 (patch)
treed471610ccb9ce28e4ce95fd92ccf1e91534f81bf /servergreps
parent23a81e27da1a84b9a85b0e09fd5f8421257f8d4f (diff)
downloadevol-tools-01403803a7550baeef2ae58c2563cdada7992c37.tar.gz
evol-tools-01403803a7550baeef2ae58c2563cdada7992c37.tar.bz2
evol-tools-01403803a7550baeef2ae58c2563cdada7992c37.tar.xz
evol-tools-01403803a7550baeef2ae58c2563cdada7992c37.zip
servergreps: add basic parsing for 3CeaM
Diffstat (limited to 'servergreps')
-rwxr-xr-xservergreps/hercules/packets.py7
-rwxr-xr-xservergreps/hercules/src/reporter.py9
-rwxr-xr-xservergreps/hercules/src/threeceam.py209
3 files changed, 224 insertions, 1 deletions
diff --git a/servergreps/hercules/packets.py b/servergreps/hercules/packets.py
index cd6ce5f..7638957 100755
--- a/servergreps/hercules/packets.py
+++ b/servergreps/hercules/packets.py
@@ -12,6 +12,7 @@ from src.manaplus import ManaPlus
from src.ragemu import Ragemu
from src.rathena import Rathena
from src.reporter import Reporter
+from src.threeceam import Threeceam
def showHelp():
@@ -38,6 +39,9 @@ brathena.reportName = "brathena"
ragemu = Ragemu()
ragemu.dirName = "ragemu"
ragemu.reportName = "ragemu"
+threeceam = Threeceam()
+threeceam.dirName = "3ceam"
+threeceam.reportName = "3ceam"
manaplus = ManaPlus()
reporter = Reporter()
@@ -51,6 +55,8 @@ brathena.prepareTempFiles("brathena", packetDir, packetVersion)
brathena.processPackets(packetDir, packetVersion)
ragemu.prepareTempFiles("ragemu", packetDir, packetVersion)
ragemu.processPackets(packetDir, packetVersion)
+threeceam.prepareTempFiles("3ceam", packetDir, packetVersion)
+threeceam.processPackets(packetDir, packetVersion)
manaplus.processPackets(packetVersion);
reporter.reportManaplus(hercules, manaplus)
@@ -58,3 +64,4 @@ reporter.reportHercules(hercules)
reporter.reportRathena(hercules, rathena)
reporter.reportHerculesFork(hercules, brathena, "brAthena")
reporter.reportHerculesFork(hercules, ragemu, "RagEmu")
+reporter.reportThreeceam(hercules, threeceam)
diff --git a/servergreps/hercules/src/reporter.py b/servergreps/hercules/src/reporter.py
index a3ecb17..2d0b4c5 100755
--- a/servergreps/hercules/src/reporter.py
+++ b/servergreps/hercules/src/reporter.py
@@ -210,13 +210,20 @@ class Reporter:
if packet not in hercules.packetsSet:
w.write("Exists only in rAthena: " + packet + "\n")
+
def reportHerculesFork(self, hercules, fork, name):
with open(self.packetDir + "/" + hercules.reportName + "_" + fork.reportName + "_outpackets.txt", "w") as w:
for packet in fork.outPacketsSorted:
if packet not in hercules.packetsSet:
w.write("Exists only in " + name + ": " + packet + "\n")
-
with open(self.packetDir + "/" + hercules.reportName + "_" + fork.reportName + "_inpackets.txt", "w") as w:
for packet in fork.inPacketsSorted:
if packet not in hercules.inPackets:
w.write("Exists only in " + name + ": " + packet + "\n")
+
+
+ def reportThreeceam(self, hercules, threeceam):
+ with open(self.packetDir + "/" + hercules.reportName + "_" + threeceam.reportName + "_outpackets.txt", "w") as w:
+ for packet in threeceam.outPacketsSorted:
+ if packet not in hercules.packetsSet:
+ w.write("Exists only in 3CeaM: " + packet + "\n")
diff --git a/servergreps/hercules/src/threeceam.py b/servergreps/hercules/src/threeceam.py
new file mode 100755
index 0000000..7d4c73d
--- /dev/null
+++ b/servergreps/hercules/src/threeceam.py
@@ -0,0 +1,209 @@
+#! /usr/bin/env python2
+# -*- coding: utf8 -*-
+#
+# Copyright (C) 2015-2016 Evol Online
+# Author: Andrei Karas (4144)
+
+import os
+import re
+
+from src.preproc import PreProc
+
+filt = re.compile(".+[.](c|h)", re.IGNORECASE)
+
+class Threeceam:
+ namedPackets = dict()
+ packetsSet = set()
+ outPacketsSorted = []
+ inPacketsSorted = []
+ inPackets = dict()
+ functionToId = dict()
+ loginPacketNameToId = dict()
+
+ namedPacketre = re.compile(
+ "((\t|[ ])*)(?P<name>[\w0-9_]+)([ ]*)=" +
+ "([ ]*)0x(?P<value>[0-9a-fA-F]+)")
+ ourPacketre = re.compile(
+ "(WFIFOW|WBUFW)([ ]*)[(]([ ]*)([\w>_-]+),([ ]*)" +
+ "(?P<offset>0)([ ]*)[)]([ ]*)=([ ]*)0x(?P<packet>[0-9a-fA-F]+)([ ]*)[;]")
+ ourPacketre2 = re.compile("PacketType([ ]*)=([ ]*)(?P<name>[\w_]+);")
+ ourPacketre3 = re.compile(
+ "(WFIFOW|WBUFW)([ ]*)[(]([ ]*)([\w>_-]+),([ ]*)" +
+ "(?P<offset>0)([ ]*)[)]([ ]*)=([ ]*)(?P<packet>[0-9\w]+)([ ]*)[;]")
+ ourPacketre4 = re.compile("int cmd([ ]*)=([ ]*)0x(?P<packet>[0-9a-fA-F]+);")
+ ourPacketre5 = re.compile("int cmde([ ]*)=([ ]*)0x(?P<packet>[0-9a-fA-F]+);")
+ ourPacketre6 = re.compile(" (packet|packet_num|PacketType|packet_type)([ ]*)=([ ]*)0x(?P<packet>[0-9a-fA-F]+);")
+ outPacketLoginre = re.compile(
+ "([ ]*)PACKET_ID_(?P<name>[A-Z0-9_]+)([ ]*)=" +
+ "([ ]*)0x(?P<packet>[0-9a-fA-F]+),")
+ serverpacketLoginOutre = re.compile("packet_id([ ]*)=([ ]*)(?P<name>[\w_]+);")
+ clientpacketre = re.compile(
+ "(\t*)packet[(]0x(?P<packet>[0-9a-fA-F]+),(?P<len>[\w-]+)" +
+ ",(?P<function>[0-9a-zA-Z_>-]+)(,|[)])")
+ lclifPacketre = re.compile(
+ "([ ]*)[{][ ]PACKET_ID_CA_(?P<name>[A-Z0-9_]+),([^,]+)," +
+ "([ ]*)[&](?P<function>[0-9a-zA-Z_>-]+)([ ]*)[}],")
+
+ def collectNamedPackets(self, fileName):
+ with open(fileName, "r") as f:
+ for line in f:
+ m = self.namedPacketre.search(line)
+ if m is not None:
+ if m.group("name") not in self.namedPackets:
+ self.namedPackets[m.group("name")] = []
+ data = m.group("value").lower()
+ while len(data) < 4:
+ data = "0" + data
+ self.namedPackets[m.group("name")].append(data)
+
+
+ def addServerPacket(self, data):
+ if data == "cmde" or data == "packet" or data == "PacketType" or data == "packet_type" or data == "packet_num":
+ return
+ if data in self.namedPackets:
+ for val in self.namedPackets[data]:
+ if int(val, 16) > 4096:
+ return
+ self.packetsSet.add(val)
+ else:
+ try:
+ if int(data, 16) > 4096:
+ return
+ except:
+ pass
+ self.packetsSet.add(data.lower())
+
+
+ def collectOutPackets(self, parentDir):
+ files = os.listdir(parentDir)
+ for file1 in files:
+ if file1[0] == ".":
+ continue
+ file2 = os.path.abspath(parentDir + os.path.sep + file1)
+ if not os.path.isfile(file2):
+ if file2.find("/src/evol") <= 0:
+ self.collectOutPackets(file2)
+ elif filt.search(file1):
+ with open(file2, "r") as f:
+ for line in f:
+ m = self.ourPacketre4.findall(line)
+ if len(m) > 0:
+ for str in m:
+ data = str[2]
+ while len(data) < 4:
+ data = "0" + data
+ self.addServerPacket(data)
+ m = self.ourPacketre5.findall(line)
+ if len(m) > 0:
+ for str in m:
+ data = str[2]
+ while len(data) < 4:
+ data = "0" + data
+ self.addServerPacket(data)
+ m = self.ourPacketre6.findall(line)
+ if len(m) > 0:
+ for str in m:
+ data = str[3]
+ while len(data) < 4:
+ data = "0" + data
+ self.addServerPacket(data)
+ m = self.outPacketLoginre.findall(line)
+ if len(m) > 0:
+ for str in m:
+ data = str[4]
+ while len(data) < 4:
+ data = "0" + data
+ self.loginPacketNameToId["PACKET_ID_" + str[1]] = data
+ m = self.ourPacketre.findall(line)
+ if len(m) == 0:
+ m = self.ourPacketre3.findall(line)
+ if len(m) > 0:
+ for str in m:
+ if str[9] == "0":
+ continue
+ data = str[9]
+ if data == "cmd":
+ continue
+ while len(data) < 4:
+ data = "0" + data
+ self.addServerPacket(data)
+
+ m = self.ourPacketre2.findall(line)
+ if len(m) > 0:
+ for str in m:
+ if str[2] == "0":
+ continue
+ data = str[2]
+ if len(data) > 2 and data[0:2] == "0x":
+ data = data[2:]
+ while len(data) < 4:
+ data = "0" + data
+ self.addServerPacket(data)
+ m = self.serverpacketLoginOutre.findall(line)
+ if len(m) > 0:
+ for str in m:
+ if str[2] in self.loginPacketNameToId:
+ data = str[2]
+ data = self.loginPacketNameToId[data]
+ self.addServerPacket(data)
+
+
+ def sortOutPackets(self):
+ for packet in self.packetsSet:
+ self.outPacketsSorted.append(packet)
+ self.outPacketsSorted.sort()
+
+
+ def collectInPackets(self, packetsH, lclifPackets):
+ with open(packetsH, "r") as f:
+ for line in f:
+ m = self.clientpacketre.search(line)
+ if m is not None:
+ data = m.group("packet").lower()
+ while len(data) < 4:
+ data = "0" + data
+ self.inPackets[data] = \
+ (int(m.group("len")), m.group("function"))
+ self.functionToId[m.group("function")] = data
+ with open(lclifPackets, "r") as f:
+ for line in f:
+ m = self.lclifPacketre.search(line)
+ if m is not None:
+ name = "PACKET_ID_CA_" + m.group("name")
+ if name not in self.loginPacketNameToId:
+ print "Wrong login packet name: " + name
+ continue
+ data = self.loginPacketNameToId[name]
+ self.inPackets[data] = (0, m.group("function"))
+ self.functionToId[m.group("function")] = data
+
+
+ def sortInPackets(self):
+ for packet in self.inPackets:
+ self.inPacketsSorted.append(packet)
+ self.inPacketsSorted.sort()
+
+
+ def processPackets(self, packetDir, packetVersion):
+# namedPacketsPath = packetDir + "/src/" + self.dirName + "/packets_struct.h"
+ srcPath = packetDir + "/src/" + self.dirName
+# serverInPacketsHPath = packetDir + "/src/" + self.dirName + "/packets.h"
+# serverLoginInPackets = packetDir + "/src/" + self.dirName + "/lclif.c"
+# self.collectNamedPackets(namedPacketsPath)
+ self.collectOutPackets(srcPath)
+# self.collectInPackets(serverInPacketsHPath, serverLoginInPackets)
+# self.sortInPackets()
+ self.sortOutPackets()
+
+
+ def prepareTempFiles(self, codeDir, packetDir, packetVersion):
+ proc = PreProc()
+ proc.init(packetDir + "/src/" + self.dirName)
+ proc.defines = "-DPACKETVER=" + packetVersion + " -D_SOCKET_H_ -DWFIFOW\\(fd,pos\\)=WFIFOW\\(fd,pos\\) -DWBUFW\\(p,pos\\)=WBUFW\\(p,pos\\)"
+ proc.includes = "-I../links/" + codeDir + "/src -I../links/" + codeDir + "/3rdparty"
+ proc.inDir = "../links/" + codeDir + "/src/"
+ proc.outDir = packetDir + "/src/" + self.dirName + "/"
+ proc.run("char", "char.c");
+ proc.run("char_sql", "char.c");
+ proc.run("login", "login.c");
+ proc.run("map", "clif.c");