summaryrefslogtreecommitdiff
path: root/servergreps/packets.py
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-03-26 19:39:51 +0300
committerAndrei Karas <akaras@inbox.ru>2015-03-26 19:39:51 +0300
commit6a370ab699078afd98b851e2db3ffd1e14a3927c (patch)
tree538e651a87c670c1f8de51f5dcb58d7cb014a67a /servergreps/packets.py
parent2025f8821630621b17403493044b4a2812106539 (diff)
downloadevol-tools-6a370ab699078afd98b851e2db3ffd1e14a3927c.tar.gz
evol-tools-6a370ab699078afd98b851e2db3ffd1e14a3927c.tar.bz2
evol-tools-6a370ab699078afd98b851e2db3ffd1e14a3927c.tar.xz
evol-tools-6a370ab699078afd98b851e2db3ffd1e14a3927c.zip
servergreps: dump all unused client to server packets.
Also report probably wrong packets in protocol.h
Diffstat (limited to 'servergreps/packets.py')
-rwxr-xr-xservergreps/packets.py75
1 files changed, 67 insertions, 8 deletions
diff --git a/servergreps/packets.py b/servergreps/packets.py
index 1f7dbf2..13d8021 100755
--- a/servergreps/packets.py
+++ b/servergreps/packets.py
@@ -12,9 +12,14 @@ serverpacketre = re.compile("(WFIFOW|WBUFW)([ ]*)[(]([ ]*)([\w>_-]+),([ ]*)"
+ "(?P<offset>0)([ ]*)[)]([ ]*)=([ ]*)0x(?P<packet>[0-9a-fA-F]+)([ ]*)[;]")
serverpacketre2 = re.compile("[.]PacketType([ ]*)=([ ]*)(?P<name>[\w]+);")
protocolre = re.compile("#define[ ](?P<name>[A-Z0-9_]+)([ ]*)0x(?P<packet>[0-9a-fA-F]+)")
+protocolClientre = re.compile("#define[ ](?P<name>CMSG_[A-Z0-9_]+)([ ]*)0x(?P<packet>[0-9a-fA-F]+)")
+clientpacketre = re.compile("(\t*)packet[(]0x(?P<packet>[0-9a-fA-F]+),(?P<len>[\w-]+),(?P<function>[0-9a-zA-Z_>-]+)(,|[)])")
packetsSet = set()
-packets = []
+serverpacketsSorted = []
+clientpacketsSorted = []
+clientPacketsManaPlus = dict()
+clientPacketsManaPlusClient = dict()
clientPackets = dict()
def collectServerPackets(parentDir):
@@ -43,30 +48,84 @@ def collectServerPackets(parentDir):
def sortServerPackets():
for packet in packetsSet:
- packets.append(packet)
- packets.sort()
+ serverpacketsSorted.append(packet)
+ serverpacketsSorted.sort()
+
+def sortClientPackets():
+ for packet in clientPackets:
+ clientpacketsSorted.append(packet)
+ clientpacketsSorted.sort()
def collectManaPlusPackets(fileName):
with open(fileName, "r") as f:
for line in f:
m = protocolre.search(line)
if m is not None:
- clientPackets[m.group("packet").lower()] = m.group("name")
+ clientPacketsManaPlus[m.group("packet").lower()] = m.group("name")
+ m = protocolClientre.search(line)
+ if m is not None:
+ clientPacketsManaPlusClient[m.group("packet").lower()] = m.group("name")
+
+def collectClientPackets(fileName):
+ with open(fileName, "r") as f:
+ for line in f:
+ m = clientpacketre.search(line)
+ if m is not None:
+ data = m.group("packet").lower()
+ while len(data) < 4:
+ data = "0" + data
+ clientPackets[data] = (m.group("len"), m.group("function"));
+ #print "{0},{1},{2}".format(m.group("packet"), m.group("len"), m.group("function"))
def printPackets():
- for packet in packets:
+ with open("serverpackets.txt", "w") as w:
+ for packet in serverpacketsSorted:
+ data = packet
+ while data[0] == "0":
+ data = data[1:]
+ if packet in clientPacketsManaPlus:
+ w.write(data + " client name: " + clientPacketsManaPlus[packet])
+ else:
+ w.write(data)
+ w.write("\n")
+
+ funcDict = dict()
+ forRemove = []
+ for packet in clientpacketsSorted:
data = packet
while data[0] == "0":
data = data[1:]
if packet in clientPackets:
- print data + " client name: " + clientPackets[packet]
- else:
- print data
+ funcDict[clientPackets[packet][1]] = packet
+
+ with open("uselesspackets.txt", "w") as w:
+ for packet in clientPacketsManaPlusClient:
+ if packet not in clientPackets:
+ w.write("Useless packet {0}.\n".format(packet))
+
+ manaplusFunc = set()
+ rev = []
+ with open("clientpackets.txt", "w") as w:
+ for packet in clientPacketsManaPlusClient:
+ if packet in clientPackets:
+ manaplusFunc.add(clientPackets[packet][1])
+ for func in funcDict:
+ if func not in manaplusFunc:
+ packet = funcDict[func]
+ rev.append("{0:4} {1:>4} {2}".format(packet, clientPackets[packet][0], clientPackets[packet][1]))
+ rev.sort()
+
+ for data in rev:
+ w.write(data)
+ w.write("\n")
srcPath = "../../server-code/src/"
protocolPath = "../../manaplus/src/net/eathena/protocol.h"
+clientPacketsPath = srcPath + "map/packets.h"
collectServerPackets(srcPath)
+collectClientPackets(clientPacketsPath)
collectManaPlusPackets(protocolPath)
+sortClientPackets()
sortServerPackets()
printPackets()