From a283f762f7763573d089d8e8ab250d72d525b2bc Mon Sep 17 00:00:00 2001 From: Lucino772 Date: Thu, 6 May 2021 14:30:45 +0100 Subject: [PATCH] Moved mojang.api.net.rcon to mojang.minecraft.proto.rcon --- mojang/minecraft/proto/rcon/__init__.py | 71 +++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 mojang/minecraft/proto/rcon/__init__.py diff --git a/mojang/minecraft/proto/rcon/__init__.py b/mojang/minecraft/proto/rcon/__init__.py new file mode 100644 index 00000000..1ab33b4e --- /dev/null +++ b/mojang/minecraft/proto/rcon/__init__.py @@ -0,0 +1,71 @@ +import random +import socket +import struct +from contextlib import contextmanager +from typing import IO, Tuple + + +def get_request_id(): + return random.randint(0,2**31) + +def _read_fully(buffer: IO, length: int): + data = buffer.read(length) + + while len(data) < length: + _data = buffer.read(length - len(data)) + if _data: + data += _data + + return data + +def _write_packet(sock: socket.socket, packet_type: int, payload: str): + packet_id = get_request_id() + payload = payload.encode('ascii') + b'\00' + packet = struct.pack('