def SerializeBody(self): # Write values. data = cStringIO.StringIO() BinaryStructs.SerializeBinary(data, self.Salt, maxlen=16) BinaryStructs.SerializeBinary(data, self.Challenge, maxlen=32) retval = data.getvalue() data.close() return retval
def SerializeBody(self): # Write data. data = cStringIO.StringIO() BinaryStructs.SerializeUint32(data, self.RequestSerial) BinaryStructs.SerializeUTF8(data, self.Username, maxlen=32) BinaryStructs.SerializeBinary(data, self.Salt, maxlen=16) BinaryStructs.SerializeBinary(data, self.PasswordHash, maxlen=64) BinaryStructs.SerializeUTF8(data, self.Email, maxlen=64) retval = data.getvalue() data.close() return retval
def SerializeBody(self): # Write data. data = cStringIO.StringIO() BinaryStructs.SerializeUint32(data, self.RequestSerial) BinaryStructs.SerializeBinary(data, self.ChallengeSolution, maxlen=32) retval = data.getvalue() data.close() return retval
def GetBinaryForm(self): ''' Encodes the packet to a binary string for network transmission. Do not subclass this method for custom packets; instead, subclass the SerializeBody() interface method. @return: Network-safe binary string containing the packet. ''' # let's figure out what we're sending flags = 0 body = self.SerializeBody() if body: # there's a body that needs to be compressed compressed = self.CompressIfNeeded(body) if compressed != None: bodywriter = cStringIO.StringIO() BinaryStructs.SerializeBinary(bodywriter, compressed, maxlen=MaxCompressedSize) body = bodywriter.getvalue() bodywriter.close() flags |= HeaderFlag_zlib # okay, build the packet packetwriter = cStringIO.StringIO() # first, the header BinaryStructs.SerializeUint16(packetwriter, self.PacketType) BinaryStructs.SerializeUint16(packetwriter, flags) # then the body if body: packetwriter.write(body) # return the packet data retval = packetwriter.getvalue() packetwriter.close() return retval