#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # #------------------------------------------------------------------------------- # #ʹÓÃProtocolStudio.CodeMaker.ÆÕͨ.NewParseNetPackStruct.pyÉú³É from ctypes import * from PackCommonDef import tagHead from Common import (CommFunc,) #------------------------------------------------------ #01 01µÇ¼»ØÓ¦°ü#tagPLLoginResult class tagPLLoginResult(Structure): Head = tagHead() Result = 0 #(BYTE Result)//µÇ¼½á¹û£¬³É¹¦1£¬Ê§°Ü0 ErrMsgLen = 0 #(BYTE ErrMsgLen)//ʧ°ÜÔ­Òò³¤¶È ErrMsg = "" #(String ErrMsg)//ʧ°ÜÔ­Òò data = None def __init__(self): self.Clear() self.Head.Cmd = 0x01 self.Head.SubCmd = 0x01 return def ReadData(self, _lpData, _pos=0, _Len=0): self.Clear() _pos = self.Head.ReadData(_lpData, _pos) self.Result,_pos = CommFunc.ReadBYTE(_lpData, _pos) self.ErrMsgLen,_pos = CommFunc.ReadBYTE(_lpData, _pos) self.ErrMsg,_pos = CommFunc.ReadString(_lpData, _pos,self.ErrMsgLen) return _pos def Clear(self): self.Head = tagHead() self.Head.Clear() self.Head.Cmd = 0x01 self.Head.SubCmd = 0x01 self.Result = 0 self.ErrMsgLen = 0 self.ErrMsg = "" return def GetLength(self): length = 0 length += self.Head.GetLength() length += 1 length += 1 length += len(self.ErrMsg) return length def GetBuffer(self): data = '' data = CommFunc.WriteString(data, self.Head.GetLength(), self.Head.GetBuffer()) data = CommFunc.WriteBYTE(data, self.Result) data = CommFunc.WriteBYTE(data, self.ErrMsgLen) data = CommFunc.WriteString(data, self.ErrMsgLen, self.ErrMsg) return data def OutputString(self): DumpString = ''' Head:%s, Result:%d, ErrMsgLen:%d, ErrMsg:%s '''\ %( self.Head.OutputString(), self.Result, self.ErrMsgLen, self.ErrMsg ) return DumpString #01 03ÐÄÌø°ü#tagPLHeartbeat class tagPLHeartbeat(Structure): _pack_ = 1 _fields_ = [ ("Cmd", c_ubyte), ("SubCmd", c_ubyte), ] def __init__(self): self.Clear() self.Cmd = 0x01 self.SubCmd = 0x03 return def ReadData(self, stringData, _pos=0, _len=0): self.Clear() memmove(addressof(self), stringData[_pos:], self.GetLength()) return _pos + self.GetLength() def Clear(self): self.Cmd = 0x01 self.SubCmd = 0x03 return def GetLength(self): return sizeof(tagPLHeartbeat) def GetBuffer(self): return string_at(addressof(self), self.GetLength()) def OutputString(self): DumpString = '''//01 03ÐÄÌø°ü//tagPLHeartbeat: Cmd:%s, SubCmd:%s '''\ %( self.Cmd, self.SubCmd ) return DumpString #------------------------------------------------------ #±¨Ãû¿ç·þÕ½½á¹û#tagMPRegisterPlayerResult class tagMPRegisterPlayerResult(Structure): Type = 0 #(BYTE Type) Result = 0 #(BYTE Result)//½á¹û£¬³É¹¦1£¬Ê§°Ü0 ErrorMsgLen = 0 #(DWORD ErrorMsgLen) ErrorMsg = "" #(String ErrorMsg)//´íÎóÃèÊö AccountLen = 0 #(BYTE AccountLen) Account = "" #(String Account)//ÕʺŠPwdLen = 0 #(BYTE PwdLen) Pwd = "" #(String Pwd)//ÃÜÂë data = None def __init__(self): self.Clear() return def ReadData(self, _lpData, _pos=0, _Len=0): self.Clear() self.Type,_pos = CommFunc.ReadBYTE(_lpData, _pos) self.Result,_pos = CommFunc.ReadBYTE(_lpData, _pos) self.ErrorMsgLen,_pos = CommFunc.ReadDWORD(_lpData, _pos) self.ErrorMsg,_pos = CommFunc.ReadString(_lpData, _pos,self.ErrorMsgLen) self.AccountLen,_pos = CommFunc.ReadBYTE(_lpData, _pos) self.Account,_pos = CommFunc.ReadString(_lpData, _pos,self.AccountLen) self.PwdLen,_pos = CommFunc.ReadBYTE(_lpData, _pos) self.Pwd,_pos = CommFunc.ReadString(_lpData, _pos,self.PwdLen) return _pos def Clear(self): self.Type = 0 self.Result = 0 self.ErrorMsgLen = 0 self.ErrorMsg = "" self.AccountLen = 0 self.Account = "" self.PwdLen = 0 self.Pwd = "" return def GetLength(self): length = 0 length += 1 length += 1 length += 4 length += len(self.ErrorMsg) length += 1 length += len(self.Account) length += 1 length += len(self.Pwd) return length def GetBuffer(self): data = '' data = CommFunc.WriteBYTE(data, self.Type) data = CommFunc.WriteBYTE(data, self.Result) data = CommFunc.WriteDWORD(data, self.ErrorMsgLen) data = CommFunc.WriteString(data, self.ErrorMsgLen, self.ErrorMsg) data = CommFunc.WriteBYTE(data, self.AccountLen) data = CommFunc.WriteString(data, self.AccountLen, self.Account) data = CommFunc.WriteBYTE(data, self.PwdLen) data = CommFunc.WriteString(data, self.PwdLen, self.Pwd) return data def OutputString(self): DumpString = ''' Type:%d, Result:%d, ErrorMsgLen:%d, ErrorMsg:%s, AccountLen:%d, Account:%s, PwdLen:%d, Pwd:%s '''\ %( self.Type, self.Result, self.ErrorMsgLen, self.ErrorMsg, self.AccountLen, self.Account, self.PwdLen, self.Pwd ) return DumpString #------------------------------------------------------ #²éѯ±¨Ãû½á¹û·µ»Ø#tagMPQueryRegisterResult class tagMPQueryRegisterResult(Structure): Type = 0 #(BYTE Type) Result = 0 #(BYTE Result)//²éѯ½á¹û£¬1³É¹¦£¬0ʧ°Ü AccountLen = 0 #(BYTE AccountLen) Account = "" #(String Account)//ÕʺŠPwdLen = 0 #(BYTE PwdLen) Pwd = "" #(String Pwd)//ÃÜÂë data = None def __init__(self): self.Clear() return def ReadData(self, _lpData, _pos=0, _Len=0): self.Clear() self.Type,_pos = CommFunc.ReadBYTE(_lpData, _pos) self.Result,_pos = CommFunc.ReadBYTE(_lpData, _pos) self.AccountLen,_pos = CommFunc.ReadBYTE(_lpData, _pos) self.Account,_pos = CommFunc.ReadString(_lpData, _pos,self.AccountLen) self.PwdLen,_pos = CommFunc.ReadBYTE(_lpData, _pos) self.Pwd,_pos = CommFunc.ReadString(_lpData, _pos,self.PwdLen) return _pos def Clear(self): self.Type = 0 self.Result = 0 self.AccountLen = 0 self.Account = "" self.PwdLen = 0 self.Pwd = "" return def GetLength(self): length = 0 length += 1 length += 1 length += 1 length += len(self.Account) length += 1 length += len(self.Pwd) return length def GetBuffer(self): data = '' data = CommFunc.WriteBYTE(data, self.Type) data = CommFunc.WriteBYTE(data, self.Result) data = CommFunc.WriteBYTE(data, self.AccountLen) data = CommFunc.WriteString(data, self.AccountLen, self.Account) data = CommFunc.WriteBYTE(data, self.PwdLen) data = CommFunc.WriteString(data, self.PwdLen, self.Pwd) return data def OutputString(self): DumpString = ''' Type:%d, Result:%d, AccountLen:%d, Account:%s, PwdLen:%d, Pwd:%s '''\ %( self.Type, self.Result, self.AccountLen, self.Account, self.PwdLen, self.Pwd ) return DumpString