hxp
2018-08-10 ccfc87e02e2ae7d153bbab0754639a1a663d34d3
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/python
# -*- coding: GBK -*-
#×÷Õß : eggxp
 
import CommFunc
import Log4P
import binascii
 
 
 
 
#
class  tagHead:
    Cmd = None  # (BYTE Cmd )
    SubCmd = None   # (BYTE SubCmd )
    def __init__(self):
        self.Clear()
 
        return
    def ReadData(self, _lpData, _Len=0):
        self.Clear()
 
        pos = 0
 
        self.Cmd, pos = CommFunc.ReadBYTE(_lpData, pos)
        self.SubCmd, pos = CommFunc.ReadBYTE(_lpData, pos)
 
        if _Len != 0 and pos != _Len:
            Log4P.Warn("Error in tagHead : %s "% binascii.b2a_hex(_lpData))
            return 0
        return pos
 
    def Clear(self):
        self.Cmd = 0
        self.SubCmd = 0
        return
 
    def GetLength(self):
        length = 0
        length += 1
        length += 1
        return  length;
 
    def GetBuffer(self):
        data = ''
        data = CommFunc.WriteBYTE(data, self.Cmd)
        data = CommFunc.WriteBYTE(data, self.SubCmd)
        return data
 
    def OutputString(self):
        DumpString = (": "
                            "Cmd:%d,"
                            "SubCmd:%d"
                            %(
                            self.Cmd,
                            self.SubCmd
                            )
                            )
 
        return  DumpString
    
# //04 07 NPCÏûʧ#tagNPCDisappear
#
class  tagNPCDisappear:
    Head = tagHead()        # (tagHead Head )
    Count = 0       # (WORD Count )
    NPCID = list()      # (vector<DWORD> NPCID )     //size = Count
    data = None
    def __init__(self):
        self.Clear()
        self.Head.Cmd = 0x04
        self.Head.SubCmd = 0x07
        return
    def ReadData(self, _lpData, _pos=0, _Len=0):
        self.Clear()
 
        _pos = self.Head.ReadData(_lpData, _pos)
        self.Count, _pos = CommFunc.ReadWORD(_lpData, _pos)
        for i in range(self.Count):
            value, _pos = ReadDWORD(_lpData, _pos)
            NPCID.append(value)
 
        if _Len != 0 and _pos != _Len:
            Log4P.Warn("Error in tagNPCDisappear : %s "% binascii.b2a_hex(_lpData))
            return 0
        return _pos
 
    def Clear(self):
        self.Head = tagHead()
        self.Head.Clear()
        self.Count = 0
        self.NPCID = list()
        return
 
    def GetLength(self):
        length = 0
        length += self.Head.GetLength();
        length += 2
        length += 4 * self.Count
        return  length;
 
    def GetBuffer(self):
        data = ''
        data = CommFunc.WriteString(data, self.Head.GetLength(), self.Head.GetBuffer())
        data = CommFunc.WriteWORD(data, self.Count)
        for i in range(self.Count):
            data = CommFunc.WriteDWORD(data, self.NPCID[i])
        return data
 
    def OutputString(self):
        DumpString = '''//04 07 NPCÏûʧ#tagNPCDisappear:
                            Head:%s,
                            Count:%d,
                            NPCID:%s
                            '''\
                            %(
                            self.Head.OutputString(),
                            self.Count,
                            "..."
                            )
 
        return  DumpString
 
 
 
 
 
 
test = tagNPCDisappear()
test.Count = 0
test.NPCID.append(10)
print binascii.b2a_hex(test.GetBuffer())
 
print test.OutputString()