Skip to content

Commit 386a53b

Browse files
Update minecraft.py
The packet may response with two json objects, so we need to get the json length exactly.
1 parent 67e77ba commit 386a53b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

opengsq/protocols/minecraft.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ async def get_status(self, version=47, strip_color=True) -> dict:
4646
br = BinaryReader(response)
4747
self._unpack_varint(br) # packet length
4848
self._unpack_varint(br) # packet id
49-
self._unpack_varint(br) # json length
49+
count = self._unpack_varint(br) # json length
5050

51-
data = json.loads(br.read().decode('utf-8'))
51+
# The packet may response with two json objects, so we need to get the json length exactly
52+
data = json.loads(br.read_bytes(count).decode('utf-8'))
5253

5354
if strip_color:
5455
if 'sample' in data['players']:
@@ -141,7 +142,7 @@ def _unpack_varint(self, br: BinaryReader):
141142
import asyncio
142143

143144
async def main_async():
144-
minecraft = Minecraft(host='51.83.219.117', port=25565, timeout=5.0)
145+
minecraft = Minecraft(host='valistar.site', port=25565, timeout=5.0)
145146
status = await minecraft.get_status(47, strip_color=True)
146147
print(json.dumps(status, indent=None, ensure_ascii=False) + '\n')
147148
status = await minecraft.get_status_pre17()

0 commit comments

Comments
 (0)