Skip to content
This repository was archived by the owner on Apr 27, 2019. It is now read-only.

Commit 9dd6a62

Browse files
committed
Fixed up worldstart, cleaned up some display of VariantVariants.
1 parent b92209f commit 9dd6a62

3 files changed

Lines changed: 25 additions & 19 deletions

File tree

packets/data_types.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from construct import Construct, Struct, Byte, BFloat64, Flag, \
3-
Array, LazyBound, String, Container
3+
String, Container
44
from construct.core import _read_stream, _write_stream, Adapter
55

66

@@ -70,18 +70,20 @@ def _encode(self, obj, context):
7070
def _decode(self, obj, context):
7171
return obj.string
7272

73-
73+
class Joiner(Adapter):
74+
def _encode(self, obj, context):
75+
return obj
76+
def _decode(self, obj, context):
77+
return "".join(obj)
7478
star_string_struct = lambda name="star_string": Struct(name,
7579
VLQ("length"),
7680
String("string", lambda ctx: ctx.length)
7781
)
7882

79-
variant_variant = Struct("data",
80-
VLQ("length"),
81-
Array(lambda ctx: ctx.length,
82-
LazyBound("data",
83-
lambda: Variant(""))))
84-
83+
class VariantVariant(Construct):
84+
def _parse(self, stream, context):
85+
l = VLQ("").parse_stream(stream)
86+
return [Variant("").parse_stream(stream) for _ in range(l)]
8587

8688
class DictVariant(Construct):
8789
def _parse(self, stream, context):
@@ -108,6 +110,13 @@ def _parse(self, stream, context):
108110
elif x == 5:
109111
return star_string().parse_stream(stream)
110112
elif x == 6:
111-
return variant_variant.parse_stream(stream)
113+
return VariantVariant("").parse_stream(stream)
112114
elif x == 7:
113115
return DictVariant("").parse_stream(stream)
116+
117+
class StarByteArray(Construct):
118+
def _parse(self, stream, context):
119+
l = VLQ("").parse_stream(stream)
120+
return _read_stream(stream, l)
121+
def _build(self, obj, stream, context):
122+
_write_stream(stream, len(obj), VLQ("").build(len(obj))+obj)

packets/packet_types.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from construct import *
22
from enum import IntEnum
3-
from data_types import SignedVLQ, VLQ, Variant, star_string, DictVariant
3+
from data_types import SignedVLQ, VLQ, Variant, star_string, DictVariant, StarByteArray
44

55

66
class Direction(IntEnum):
@@ -180,16 +180,13 @@ def _decode(self, obj, context):
180180
world_start = lambda name="world_start": Struct(name,
181181
Variant("planet"),
182182
Variant("world_structure"),
183-
VLQ("sky_size"),
184-
Bytes("sky",
185-
lambda ctx: ctx.sky_size),
186-
VLQ("server_weather_size"),
187-
Bytes("server_weather", lambda ctx: ctx.server_weather_size),
183+
StarByteArray("sky_structure"),
184+
StarByteArray("weather_data"),
188185
BFloat32("spawn_x"),
189186
BFloat32("spawn_y"),
190-
update_world_properties("world_properties"),
187+
Variant("world_properties"),
191188
UBInt32("client_id"),
192-
Flag("local"))
189+
Flag("local_interpolation"))
193190

194191
world_stop = lambda name="world_stop": Struct(name,
195192
star_string("status"))

plugins/core/player_manager/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def after_connect_response(self, data):
8484
self.protocol.transport.getPeer().host))
8585

8686
def after_world_start(self, data):
87-
world_start = packets.Variant("").parse(data.data)
88-
coords = world_start['config']['coordinate']
87+
world_start = packets.world_start().parse(data.data)
88+
coords = world_start.planet['config']['coordinate']
8989
if coords is not None:
9090
parent_system = coords['parentSystem']
9191
location = parent_system['location']

0 commit comments

Comments
 (0)