def _Deserialize_CurrentVer(self, fileobj): """ Deserializes a tile in the current map file format. @type fileobj: C{file} @param fileobj: File (or compatible stream) to read from. """ # first: the flags try: flags = BinaryStructs.DeserializeUint32(fileobj) except Exception as e: raise MapError("invalid/corrupt map file", e) # Check for the end-of-tiles flag. if flags & self.EndOfTilesFlag: # End of tiles. raise EndOfSectionException # Read in the rest of the title data. # Validation should happen in the map deserialization (since it has # access to the map header for dimensional validation). Just store # the values for now. try: self.x = BinaryStructs.DeserializeUint32(fileobj) self.y = BinaryStructs.DeserializeUint32(fileobj) self.z = BinaryStructs.DeserializeUint32(fileobj) self.tileid = BinaryStructs.DeserializeUint32(fileobj) except Exception as e: raise MapError("invalid/corrupt map file", e)
def DeserializeBody(self, stream): # Read data. try: self.RequestSerial = BinaryStructs.DeserializeUint32(stream) self.ChallengeSolution = BinaryStructs.DeserializeBinary(stream, maxlen=32) except BinaryStructs.EndOfFile: raise IncompletePacket
def DeserializeBody(self, stream): # Read data. try: self.RequestSerial = BinaryStructs.DeserializeUint32(stream) self.Username = BinaryStructs.DeserializeUTF8(stream, maxlen=32) self.Salt = BinaryStructs.DeserializeBinary(stream, maxlen=16) self.PasswordHash = BinaryStructs.DeserializeBinary(stream, 64) self.Email = BinaryStructs.DeserializeUTF8(stream, maxlen=64) except BinaryStructs.EndOfFile: raise IncompletePacket
def DeserializeBody(self, stream): # Read values. try: self.RequestSerial = BinaryStructs.DeserializeUint32(stream) self.ReasonCode = BinaryStructs.DeserializeUint16(stream) except BinaryStructs.EndOfFile: raise IncompletePacket except: msg = "Unhandled exception in DeserializeBody, packet type 4.\n\n" msg += traceback.format_exc() logging.error(msg) raise CorruptPacket
def Deserialize(self, fileobj, formatver=CurrentMapVersion): """ Reads and decodes the header from a stream (usually a file). @type fileobj: C{file} @param fileobj: File object to read the header from. @type formatver: integer @param formatver: version of the map file format to process """ # which version are we reading from? if formatver == CurrentMapVersion: # latest version of the header format! # again, we're just reading everything in the right order # first up is the basic file information try: self.MapName = BinaryStructs.DeserializeUTF8(fileobj) self.MapName.strip() self.Width = BinaryStructs.DeserializeUint32(fileobj) self.Height = BinaryStructs.DeserializeUint32(fileobj) self.Depth = BinaryStructs.DeserializeUint32(fileobj) self.PlayerDepth = BinaryStructs.DeserializeUint32(fileobj) except: msg = "Map file is invalid/corrupt.\n" msg += traceback.format_exc() mainlog.error(msg) raise # validate the basic file information if self.Width < 1 or self.Height < 1 or self.Depth < 1: # invalid dimensions raise MapError("Map file is invalid/corrupt: dimensions") if self.PlayerDepth < 0 or self.PlayerDepth >= self.Depth: # render depth out of bounds raise MapError("Player/object render depth out of bounds.") # now we read in the links try: self.NorthMap = BinaryStructs.DeserializeUTF8(fileobj) self.NorthMap.strip() self.EastMap = BinaryStructs.DeserializeUTF8(fileobj) self.EastMap.strip() self.SouthMap = BinaryStructs.DeserializeUTF8(fileobj) self.SouthMap.strip() self.WestMap = BinaryStructs.DeserializeUTF8(fileobj) self.WestMap.strip() self.BackgroundImage = BinaryStructs.DeserializeUTF8(fileobj) self.BackgroundImage.strip() except Exception as e: raise MapError("Map file is invalid/corrupt.", e) # and then we read in the content flags... try: contentflags = BinaryStructs.DeserializeUint32(fileobj) except Exception as e: raise MapError("Map file is invalid/corrupt.", e) self.Stripped = contentflags & self.Flag_ContentStripped else: # unrecognized future version raise FutureFormatException("unrecognized format version")