summaryrefslogtreecommitdiff
path: root/servergreps/hercules/src/tables.py
blob: ccfa4e0ce759ab11c7f34e5084f57eb9317cae38 (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
#! /usr/bin/env python2
# -*- coding: utf8 -*-
#
# Copyright (C) 2015-2016  Evol Online
# Author: Andrei Karas (4144)

import re
import os

from src.packetdb import PacketDb
from src.preproc import PreProc
from src.utils import Utils

filt = re.compile(".+[.](c|h)", re.IGNORECASE)

class Tables:
    inPacketsSorted = []
    inPackets = dict()
    knownLenPackets = dict()

    clientpacketre = re.compile(
        "^(?P<packet>[0-9a-fA-F]+) (?P<len>[\w-]+)")

    def collectInPackets(self, packetsH):
        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")), "")
                    self.knownLenPackets[data] = int(m.group("len"))

    def sortInPackets(self):
        for packet in self.inPackets:
            self.inPacketsSorted.append(packet)
        self.inPacketsSorted.sort()


    def findVersion(self, srcPath, packetDir):
        name = packetDir[:4] + "_" + packetDir[4:6] + "_" + packetDir[6:8]
        files = os.listdir(srcPath)
        for file1 in files:
            if file1[0] == ".":
                continue
            file2 = os.path.abspath(srcPath + os.path.sep + file1)
            if os.path.isdir(file2) and file1.find(name) > 0:
                self.collectInPackets(file2 + os.path.sep + "recvpackets.txt")
                self.sortInPackets()
                return

    def processPackets(self, codeDir, packetDir, packetVersion):
#        namedPacketsPath = packetDir + "/src/" + self.dirName + "/packets_struct.h"
        srcPath = "../links/" + self.dirName
#        packetsDbPath = "../links/" + codeDir + "/db/packet_db.txt"
#        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.findVersion(srcPath, packetDir)
#        self.collectCharInPackets(serverCharPackets);
#        self.sortOutPackets()