blob: 1f7dbf224ccf1380e597cf19e569fe153425653c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#! /usr/bin/env python2.7
# -*- coding: utf8 -*-
#
# Copyright (C) 2015 Evol Online
# Author: Andrei Karas (4144)
import os
import re
filt = re.compile(".+[.]c", re.IGNORECASE)
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]+)")
packetsSet = set()
packets = []
clientPackets = dict()
def collectServerPackets(parentDir):
global itemNamesByName
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):
collectServerPackets(file2)
elif filt.search(file1):
with open(file2, "r") as f:
for line in f:
m = serverpacketre.findall(line)
if len(m) > 0:
for str in m:
data = str[9]
while len(data) < 4:
data = "0" + data
packetsSet.add(data.lower())
m = serverpacketre2.findall(line)
if len(m) > 0:
for str in m:
packetsSet.add(str[2].lower())
def sortServerPackets():
for packet in packetsSet:
packets.append(packet)
packets.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")
def printPackets():
for packet in packets:
data = packet
while data[0] == "0":
data = data[1:]
if packet in clientPackets:
print data + " client name: " + clientPackets[packet]
else:
print data
srcPath = "../../server-code/src/"
protocolPath = "../../manaplus/src/net/eathena/protocol.h"
collectServerPackets(srcPath)
collectManaPlusPackets(protocolPath)
sortServerPackets()
printPackets()
|