Esempio n. 1
0
 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
Esempio n. 2
0
    def DeserializeBody(self, stream):
        # read the values
        try:
            flags = BinaryStructs.DeserializeUint8(stream)
            self.ServerName = BinaryStructs.DeserializeUTF8(stream, 64)
            self.ServerNewsURL = BinaryStructs.DeserializeUTF8(stream, 256)
        except BinaryStructs.EndOfFile:
            raise IncompletePacket
        except BinaryStructs.MaxLengthExceeded:
            raise CorruptPacket
        except:
            msg = "Unhandled exception in DeserializeBody, packet type 1.\n\n"
            msg += traceback.format_exc()
            logging.error(msg)
            raise CorruptPacket

        # process the flags
        if flags & self.Flag_NoRegister: self.RegistrationDisabled = True
        else: self.RegistrationDisabled = False
Esempio n. 3
0
 def DeserializeBody(self, stream):
     # Read values.
     try:
         self.Username = BinaryStructs.DeserializeUTF8(stream, maxlen=32)
     except BinaryStructs.EndOfFile:
         raise IncompletePacket
     except:
         msg = "Unhandled exception in DeserializeBody, packet type 6."
         msg += "\n%s" % traceback.format_exc()
         logging.error(msg)
         raise CorruptPacket
Esempio n. 4
0
    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")