diff --git a/plugins/example-plugin/plugin.yml b/plugins/example-plugin/plugin.yml index db46478bd..d5aab483d 100644 --- a/plugins/example-plugin/plugin.yml +++ b/plugins/example-plugin/plugin.yml @@ -1,2 +1,8 @@ -git_url: https://github.com/py-mine/example-plugin.git -module_folder: example_plugin +git_url: "https://github.com/py-mine/example-plugin.git" +module_folder: "example_plugin" +name: "example_plugin" +description: "This is an example plugin bada bing bada boom." +version: 1 +author: "PyMine Devs" +license: "GPLv3.0" +website: "https://www.youtube.com/watch?v=dQw4w9WgXcQ" diff --git a/pymine/logic/config.py b/pymine/logic/config.py index 274cf2ddf..ab5709e7c 100644 --- a/pymine/logic/config.py +++ b/pymine/logic/config.py @@ -25,6 +25,8 @@ "spawn_animals": True, "spawn_monsters": True, "generate_structures": True, + "enable_query": True, + "query_port": 25565, } diff --git a/pymine/logic/query.py b/pymine/logic/query.py new file mode 100644 index 000000000..263b876fa --- /dev/null +++ b/pymine/logic/query.py @@ -0,0 +1,69 @@ +from __future__ import annotations +import struct + +# from pymine.server import server # not yet ferb + + +class QueryBuffer: + """Buffer for the query protocol, will contain most relevant methods.""" + + def __init__(self, buf: bytes = None) -> None: + self.buf = b"" if buf is None else buf + self.pos = 0 + + def write(self, data: bytes) -> None: + """Writes data to the buffer.""" + + self.buf += data + + def read(self, length: int = None) -> bytes: + """ + Reads n bytes from the buffer, if the length is None + then all remaining data from the buffer is sent. + """ + + try: + if length is None: + length = len(self.buf) + return self.buf[self.pos :] + + return self.buf[self.pos : self.pos + length] + finally: + self.pos += length + + def reset(self) -> None: + """Resets the position in the buffer.""" + + self.pos = 0 + + @staticmethod + def pack_short(short: int) -> bytes: + return struct.pack(" int: + return struct.unpack(" bytes: + return b"\xFE\xFD" + + @staticmethod + def unpack_magic() -> int: + return 65277 # I hate myself. + + @staticmethod + def pack_string(string: str) -> bytes: + return bytes(string, "latin-1") + b"\x00" + + @staticmethod + def pack_int32(num: int) -> bytes: + return struct.pack(">i", num) + + @staticmethod + def unpack_int32(num: int) -> int: # I think. + return struct.unpack(">i", num) + + @staticmethod + def pack_byte(byte: int) -> bytes: + return struct.pack(">b", byte) diff --git a/pymine/types/query.py b/pymine/types/query.py new file mode 100644 index 000000000..e69de29bb