Skip to content

Commit

Permalink
Update minecraft.py
Browse files Browse the repository at this point in the history
The packet may response with two json objects, so we need to get the json length exactly.
  • Loading branch information
BattlefieldDuck committed Oct 24, 2023
1 parent 67e77ba commit 386a53b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions opengsq/protocols/minecraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ async def get_status(self, version=47, strip_color=True) -> dict:
br = BinaryReader(response)
self._unpack_varint(br) # packet length
self._unpack_varint(br) # packet id
self._unpack_varint(br) # json length
count = self._unpack_varint(br) # json length

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

if strip_color:
if 'sample' in data['players']:
Expand Down Expand Up @@ -141,7 +142,7 @@ def _unpack_varint(self, br: BinaryReader):
import asyncio

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

0 comments on commit 386a53b

Please sign in to comment.