From ba31b7241cb1482083ade459da115903b0cad843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alve=20Svar=C3=A9n?= Date: Fri, 9 Oct 2020 18:53:50 +0200 Subject: [PATCH] Apparently forgot how docstrings worked --- main.py | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/main.py b/main.py index f851a85..96d00eb 100644 --- a/main.py +++ b/main.py @@ -3,10 +3,12 @@ from sys import argv # Currently the only possible value SERVER_SUFFIX = "-Master-1" -""" -Generates the bytearray with the specified values -""" + def gen_file(region_name: str, ip_address: str = "127.0.0.1", port: int = 22023) -> bytearray: + """ + Generates the bytearray with the specified values + """ + # Make sure all variables are within the correct length range if (len(region_name + SERVER_SUFFIX) > 0xff): raise ValueError("Region name too long") @@ -18,17 +20,17 @@ def gen_file(region_name: str, ip_address: str = "127.0.0.1", port: int = 22023) # Append region name data = bytearray(len(region_name).to_bytes(5, "big")) data += region_name.encode("ascii") - + # Append ip address data.append(len(ip_address)) data += ip_address.encode("ascii") data.extend(0x1.to_bytes(4, "little")) - + # Append server name server_name = region_name + SERVER_SUFFIX data.append(len(server_name)) data += server_name.encode("ascii") - + # Append ip address in byte form ip_address_bytes = bytearray() for value in ip_address.split("."): @@ -39,24 +41,27 @@ def gen_file(region_name: str, ip_address: str = "127.0.0.1", port: int = 22023) return data -""" -Creates and writes the among us regionInfo.dat file -Example: -```py -try: - writeFile("Example server", "169.0.0.1", port=12345)) - print("Success!") -except Exception as error: - print(error) -``` -Port should currently always be 22023 for it to work -""" + def write_file(region_name: str, ip_address: str = "127.0.0.1", file_name: str = "regionInfo.dat", port: int = 22023): + """ + Creates and writes the among us regionInfo.dat file + Example: + ```py + try: + writeFile("Example server", "169.0.0.1", port=12345)) + print("Success!") + except Exception as error: + print(error) + ``` + Port should currently always be 22023 for it to work + """ + # Generate the file and save to the specified file_name data = gen_file(region_name, ip_address, port) with open(file_name, "wb") as file: file.write(data) + if __name__ == "__main__": print(f"Creating file using {argv[1:]}") - write_file(*argv[1:]) \ No newline at end of file + write_file(*argv[1:])