Beispiel #1
0
def decodeCatalogItem(di, versionNumber, store):
    """decodeCatalogItem

    This function decodes a CatalogItem of an unknown type from the
    given datagram stream, reversing the logic used by
    encodeCatalogItem().  The new catalog item is returned.
    """

    import CatalogItemTypes
    global CatalogReverseType
    if CatalogReverseType == None:
        # First, we have to create the reverse lookup.
        CatalogReverseType = {}
        for itemClass, index in CatalogItemTypes.CatalogItemTypes.items():
            CatalogReverseType[index] = itemClass

    startIndex = di.getCurrentIndex()
    try:
        flags = di.getUint8()
        typeIndex = flags & CatalogItemTypes.CatalogItemTypeMask
        gift = None
        code = None
        if flags & CatalogItemTypes.CatalogItemGiftTag:

            gift = di.getUint32()
            code = di.getUint8()
        else:

            pass
        itemClass = CatalogReverseType[typeIndex]
        item = itemClass(di, versionNumber, store=store)

    except Exception, e:
        CatalogItem.notify.warning("Invalid catalog item in stream: %s, %s" %
                                   (sys.exc_info()[0], e))
        d = Datagram(di.getDatagram().getMessage()[startIndex:])
        d.dumpHex(Notify.out())
        #import pdb; pdb.set_trace()#debug on invalid catalog items
        import CatalogInvalidItem
        return CatalogInvalidItem.CatalogInvalidItem()
Beispiel #2
0
def decodeCatalogItem(di, versionNumber, store):
    global CatalogReverseType
    import CatalogItemTypes
    if CatalogReverseType == None:
        CatalogReverseType = {}
        for (itemClass, index) in CatalogItemTypes.CatalogItemTypes.items():
            CatalogReverseType[index] = itemClass

    startIndex = di.getCurrentIndex()

    try:
        flags = di.getUint8()
        typeIndex = flags & CatalogItemTypes.CatalogItemTypeMask
        gift = None
        code = None
        if flags & CatalogItemTypes.CatalogItemGiftTag:
            gift = di.getUint32()
            code = di.getUint8()

        itemClass = CatalogReverseType[typeIndex]
        item = itemClass(di, versionNumber, store=store)
    except Exception:
        e = None
        CatalogItem.notify.warning('Invalid catalog item in stream: %s, %s' %
                                   (sys.exc_info()[0], e))
        d = Datagram(di.getDatagram().getMessage()[startIndex:])
        d.dumpHex(Notify.out())
        import CatalogInvalidItem as CatalogInvalidItem
        return CatalogInvalidItem.CatalogInvalidItem()

    if flags & CatalogItemTypes.CatalogItemSaleFlag:
        item.saleItem = 1

    item.giftTag = gift
    item.giftCode = code
    return item