Exemplo n.º 1
0
class Variant(Construct):
    RESPONSES = {
        2: BFloat64('').parse_stream,
        3: Flag('').parse_stream,
        4: SignedVLQ('').parse_stream,
        5: star_string().parse_stream,
        6: VariantVariant('').parse_stream,
        7: DictVariant('').parse_stream
    }

    def _parse(self, stream, context):
        x = Byte('').parse_stream(stream)
        return self.RESPONSES.get(x, lambda x: None)(stream)
Exemplo n.º 2
0
 def _parse(self, stream, context):
     x = Byte("").parse_stream(stream)
     if x == 1:
         return None
     elif x == 2:
         return BFloat64("").parse_stream(stream)
     elif x == 3:
         return Flag("").parse_stream(stream)
     elif x == 4:
         return SignedVLQ("").parse_stream(stream)
     elif x == 5:
         return star_string().parse_stream(stream)
     elif x == 6:
         return VariantVariant("").parse_stream(stream)
     elif x == 7:
         return DictVariant("").parse_stream(stream)
Exemplo n.º 3
0
from construct import BFloat32, BFloat64
from construct import BitStruct, BitField

DUMP_ALL_PACKETS = False

# Our tricky Java string decoder.
# Note that Java has a weird encoding for the NULL byte which we do not
# respect or honor since no client will generate it. Instead, we will get two
# NULL bytes in a row.
AlphaString = functools.partial(PascalString,
                                length_field=UBInt16("length"),
                                encoding="utf8")

# Flying, position, and orientation, reused in several places.
grounded = Struct("grounded", UBInt8("grounded"))
position = Struct("position", BFloat64("x"), BFloat64("y"), BFloat64("stance"),
                  BFloat64("z"))
orientation = Struct("orientation", BFloat32("rotation"), BFloat32("pitch"))

# Notchian item packing
items = Struct(
    "items",
    SBInt16("primary"),
    If(
        lambda context: context["primary"] >= 0,
        Embed(
            Struct(
                "item_information",
                UBInt8("count"),
                UBInt16("secondary"),
            )),
Exemplo n.º 4
0
def universe_time_update(name='universe_time'):
    return Struct(name, BFloat64('universe_time'))
Exemplo n.º 5
0
                MetaField("data", lambda ctx: ctx["length"] * 2),
            )),
        encoding="ucs2",
    )


# Boolean converter.


def Bool(*args, **kwargs):
    return Flag(*args, default=True, **kwargs)


# Flying, position, and orientation, reused in several places.
grounded = Struct("grounded", UBInt8("grounded"))
position = Struct("position", BFloat64("x"), BFloat64("y"), BFloat64("stance"),
                  BFloat64("z"))
orientation = Struct("orientation", BFloat32("yaw"), BFloat32("pitch"))


def ByteString(name, size_name, encoding=None):
    return StringAdapter(MetaField("data", lambda ctx: ctx[size_name]),
                         encoding=encoding)


class NBTAdapter(Adapter):
    def _decode(self, obj, context):
        return NBTFile(StringIO(obj), compression=NBTFile.Compression.GZIP)


def NBTdata(name, size_name):
Exemplo n.º 6
0
            Sequence(name,
                UBInt16("length"),
                MetaField("data", lambda ctx: ctx["length"] * 2),
            )
        ),
        encoding="ucs2",
    )

# Boolean converter.
def Bool(*args, **kwargs):
    return Flag(*args, default=True, **kwargs)

# Flying, position, and orientation, reused in several places.
grounded = Struct("grounded", UBInt8("grounded"))
position = Struct("position",
    BFloat64("x"),
    BFloat64("y"),
    BFloat64("stance"),
    BFloat64("z")
)
orientation = Struct("orientation", BFloat32("rotation"), BFloat32("pitch"))

# Notchian item packing
items = Struct("items",
    SBInt16("primary"),
    If(lambda context: context["primary"] >= 0,
        Embed(Struct("item_information",
            UBInt8("count"),
            UBInt16("secondary"),
            Magic("\xff\xff"),
        )),
Exemplo n.º 7
0
from construct import BFloat32, BFloat64

DUMP_ALL_PACKETS = False

# Our tricky Java string decoder.
# Note that Java has a weird encoding for the NULL byte which we do not
# respect or honor since no client will generate it. Instead, we will get two
# NULL bytes in a row.
AlphaString = functools.partial(PascalString,
    length_field=UBInt16("length"),
    encoding="utf8")

# Flying, position, and orientation, reused in several places.
grounded = Struct("grounded", UBInt8("grounded"))
position = Struct("position",
    BFloat64("x"),
    BFloat64("y"),
    BFloat64("stance"),
    BFloat64("z")
)
orientation = Struct("orientation", BFloat32("rotation"), BFloat32("pitch"))

# Notchian item packing
items = Struct("items",
    SBInt16("primary"),
    If(lambda context: context["primary"] >= 0,
        Embed(Struct("item_information",
            UBInt8("count"),
            UBInt16("secondary"),
        )),
    ),