#!/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()
|