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): # create a buffer data = cStringIO.StringIO() # calculate the login screen flags flags = 0 if self.RegistrationDisabled: flags |= self.Flag_NoRegister BinaryStructs.SerializeUint8(data, flags) # store the other fields try: BinaryStructs.SerializeUTF8(data, self.ServerName) BinaryStructs.SerializeUTF8(data, self.ServerNewsURL) except: raise IncompletePacket # return the packet retval = data.getvalue() data.close() return retval
def Serialize(self, fileobj): """ Encodes and writes the header to a stream (usually a file). This will always encode the header as the latest version of the map file format. @type fileobj: C{file} @param fileobj: open file object to serialize to """ # nothing too special, just write everything in the right order try: BinaryStructs.SerializeUTF8(fileobj, self.MapName) BinaryStructs.SerializeUint32(fileobj, self.Width) BinaryStructs.SerializeUint32(fileobj, self.Height) BinaryStructs.SerializeUint32(fileobj, self.Depth) BinaryStructs.SerializeUint32(fileobj, self.PlayerDepth) BinaryStructs.SerializeUTF8(fileobj, self.NorthMap) BinaryStructs.SerializeUTF8(fileobj, self.EastMap) BinaryStructs.SerializeUTF8(fileobj, self.SouthMap) BinaryStructs.SerializeUTF8(fileobj, self.WestMap) BinaryStructs.SerializeUTF8(fileobj, self.BackgroundImage) except Exception as e: raise IOError("error while writing to map file", e) # pack the content flags try: contentFlags = 0 if self.Stripped: contentFlags |= self.Flag_ContentStripped BinaryStructs.SerializeUint32(fileobj, contentFlags) except Exception as e: raise IOError("error while writing to map file", e)
def SerializeBody(self): data = cStringIO.StringIO() BinaryStructs.SerializeUTF8(data, self.Username, maxlen=32) retval = data.getvalue() data.close() return retval