diff --git a/Server/classes/filing/format.md b/Doc/format.md similarity index 100% rename from Server/classes/filing/format.md rename to Doc/format.md diff --git a/Server/LIB/README.md b/LIB/README.md similarity index 100% rename from Server/LIB/README.md rename to LIB/README.md diff --git a/Server/classes/__pycache__/server.cpython-311.pyc b/Server/classes/__pycache__/server.cpython-311.pyc deleted file mode 100644 index 71bd89c..0000000 Binary files a/Server/classes/__pycache__/server.cpython-311.pyc and /dev/null differ diff --git a/Server/classes/__pycache__/socket_classes.cpython-311.pyc b/Server/classes/__pycache__/socket_classes.cpython-311.pyc deleted file mode 100644 index 9fb6fb9..0000000 Binary files a/Server/classes/__pycache__/socket_classes.cpython-311.pyc and /dev/null differ diff --git a/Server/classes/filing/__pycache__/open_game.cpython-311.pyc b/Server/classes/filing/__pycache__/open_game.cpython-311.pyc deleted file mode 100644 index 1f5356b..0000000 Binary files a/Server/classes/filing/__pycache__/open_game.cpython-311.pyc and /dev/null differ diff --git a/Server/classes/filing/__pycache__/save_game.cpython-311.pyc b/Server/classes/filing/__pycache__/save_game.cpython-311.pyc deleted file mode 100644 index 817434c..0000000 Binary files a/Server/classes/filing/__pycache__/save_game.cpython-311.pyc and /dev/null differ diff --git a/Server/classes/errors/errors.py b/Server/no_interrract/errors/errors.py similarity index 100% rename from Server/classes/errors/errors.py rename to Server/no_interrract/errors/errors.py diff --git a/Server/classes/filing/generator.py b/Server/no_interrract/world/generator.py similarity index 100% rename from Server/classes/filing/generator.py rename to Server/no_interrract/world/generator.py diff --git a/Server/classes/filing/open_game.py b/Server/open_game.py similarity index 84% rename from Server/classes/filing/open_game.py rename to Server/open_game.py index cf2f7c1..556aada 100644 --- a/Server/classes/filing/open_game.py +++ b/Server/open_game.py @@ -1,5 +1,8 @@ """Open a world""" +import os +from time import * + class Open(object): """Open a world. File extention should be .mcpysrv""" BLOCKS = {0:"minecraft:air", 1:"minecraft:grass_block", 2:"minecraft:dirt", 3:"minecraft:stone", 4:"minecraft:cobble_stone"} @@ -7,15 +10,16 @@ class Open(object): def __init__(self, file): """Open a world""" self.file = file - self.decoded = None with open(file, "r") as file: self.data = file.read() def read(self): """read and decode the world file's data""" + self.init_dir = os.getcwd() + os.chdir(os.getcwd() + "\\Server\\worlds") self.curent_value = "" self.final = [] - self.chunk_actu = () + self.chunk_actu = [] self.chunk_dic = {} self.chunk_blocs = [] self.coord_state = "x" @@ -37,6 +41,9 @@ def read(self): if self.state == 1: self.state = 0 self.next() + self.chunk_actu.append(self.chunk_blocs) + self.final.append(self.chunk_actu) + self.chunk_actu = () else: raise LookupError("An error occured while decoding the file {0} : trying to stop reading chunk without be in a chunk (char {1}).".format(self.file, self.char)) @@ -46,19 +53,23 @@ def read(self): else: self.curent_value += item continue + + os.chdir(self.init_dir) + + return self.final def next(self): """Go to the next value and apply""" if self.state == 0: if self.coord_state == "x": self.chunk_dic["x"] = self.curent_value - self.chunk_dic = "y" + self.coord_state = "y" elif self.coord_state == "y": self.chunk_dic["y"] = self.curent_value - self.chunk_dic = "z" + self.coord_state = "z" elif self.coord_state == "z": self.chunk_dic["z"] = self.curent_value - self.chunk_dic = "x" + self.coord_state = "x" else: raise LookupError("Error while decoding chunk id. Please don't touch to the world files.") self.curent_value = "" @@ -70,7 +81,7 @@ def next(self): def return_data(self): """Return the data rode.""" - ... + return self.final if __name__ == "__main__": exit(0) \ No newline at end of file diff --git a/Server/classes/filing/save_game.py b/Server/save_game.py similarity index 100% rename from Server/classes/filing/save_game.py rename to Server/save_game.py diff --git a/Server/classes/server.py b/Server/server.py similarity index 86% rename from Server/classes/server.py rename to Server/server.py index 03eac27..2d47f0c 100644 --- a/Server/classes/server.py +++ b/Server/server.py @@ -13,8 +13,8 @@ from socket import * except ModuleNotFoundError: try: - import classes.errors.errors as errors - from classes.filing.generator import Generator as G + import Server.no_interrract.errors.errors as errors + from Server.no_interrract.world.generator import Generator as G except: raise RuntimeError("FATAL ERROR. PLEASE REINSTALL THIS REPO OR SET A NEW ISSUE ON GITHUB !") raise errors.DependenciesError("""You have to have this librairies installed on your computer : @@ -23,9 +23,9 @@ --> socket --> and more""") # Internals files -from classes.filing.generator import Generator as G -from classes.filing.save_game import Save as Saver -from classes.filing.open_game import Open as Opener +from Server.no_interrract.world.generator import Generator as G +from Server.save_game import Save as Saver +from Server.open_game import Open as Opener class MinecraftServer(object): """Class of the Minecraft server""" @@ -41,6 +41,9 @@ def __init__(self, addr=""): #self.addr = (addr, 25565) #Creating normal socket addr format #self.socket = MinecraftSocketServerGestionner(addr=self.addr, port=25565) self.log_warning("This version is a developpement version ; launch it will maybe cause some issues.") + self.debug_on = True + if self.debug_on: + self.log("Debug mode active") self.worlds = self.return_worlds() if len(self.worlds) == 0: self.log("No worlds found, creating 3 new...") @@ -76,7 +79,7 @@ def return_worlds(self, filter=None): for i in dir: #For every items in the directory if os.path.isfile(path + i) and i[-8:] == ".mcpysrv": - files.append(i) + files.append(i[:-8]) elif filter == "o": #With filter "overworld" (normal minecraft world) dir = os.listdir(path) @@ -115,7 +118,7 @@ def start(self): def load_worlds(self): """Load the worlds of the server""" for i in self.worlds: - opener = Opener("Server/worlds/" + i) + opener = Opener("Server/worlds/" + i + ".mcpysrv") self.worlds_data[i] = opener.read() def create_world(self, world_name, type="o"): @@ -123,19 +126,19 @@ def create_world(self, world_name, type="o"): Arguments: - world_name : the name of the world (str) - type : can be "o"(overworld), "n"(nether) or "e"(ender). Default : "o".""" - self.log("Starting creation of the world {0}...") + self.log("Starting creation of the world {0}...".format(world_name)) if not(type == "o" or type == "n" or type == "e"): #check type l = "The type of the world {0} isn't correct.".format(world_name) self.log_error(l) self.fatal_error("""Bad world type. At: - - Server/classes/server.py + - Server/server.py \_ Server().create_world() \_ #check_type section.""") name = world_name + "_" + type self.worlds.append(name) gen = G() - self.log("Generating the world with voidgenerator()...") + self.log_debug("Generating the world with voidgenerator()...") world = gen.void_generator() self.log("Done !") saver = Saver("Server/worlds/" + name + ".mcpysrv", world) @@ -237,6 +240,26 @@ def log_warning(self, basemsg): else: with open("logs.log", "w") as logfile: logfile.write(msg) + +def log_debug(self, basemsg:str): + """Log a debug message. + Argument : + - basemsg : the message to log.""" + if self.debug_on: + import time + t = time.asctime(time.localtime(time.time())) + PREFIX = "[{0}] [DEBUG] : ".format(t[-13:-5]) + msg = PREFIX + basemsg + print(msg) + import os + if os.path.exists("logs.log"): + with open("logs.log", "r") as logfile: + logs = logfile.read() + with open("logs.log", "w") as logfile: + logfile.write(logs + "\n" + msg) + else: + with open("logs.log", "w") as logfile: + logfile.write(msg) #class Listener(object): diff --git a/logs.log b/logs.log index 2e1dff2..8b13789 100644 --- a/logs.log +++ b/logs.log @@ -1,254 +1 @@ -[10:34:18] [INFO] : #Sat Apr 22 10:34:18 2023 -[10:34:18] [INFO] : _____________________________________ -[10:34:18] [INFO] : Starting Server class... -[10:34:18] [INFO] : _____________________________________ -[10:34:18] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[10:34:18] [INFO] : No worlds found, creating 3 new... -[10:34:18] [INFO] : Generating world {0} -[10:34:18] [WARN] : You are overwriting existing data if the world already exists ! -[10:34:18] [WARN] : Method doesn't be coded. -[10:34:18] [ERROR] : FATAL ERROR -[10:34:18] [ERROR] : Reason of the crash : -[10:34:18] [ERROR] : This method doesn't be coded. - At: - - Server/classes/server.py - \_ Server().generate() -[10:34:18] [ERROR] : If this isn't normal, please send an issue on github. Please check logs for more details. -[10:34:18] [ERROR] : The server is switching off. Closing server : Fatal Error -[10:34:18] [INFO] : Creating crash report file... -[10:34:18] [INFO] : Succes ! -[10:34:18] [INFO] : Stoping the server... -[10:36:09] [INFO] : #Sat Apr 22 10:36:09 2023 -[10:36:09] [INFO] : _____________________________________ -[10:36:09] [INFO] : Starting Server class... -[10:36:09] [INFO] : _____________________________________ -[10:36:09] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[10:36:09] [INFO] : No worlds found, creating 3 new... -[10:36:09] [INFO] : Generating world {0} -[10:36:09] [WARN] : You are overwriting existing data if the world already exists ! -[10:36:09] [WARN] : Method doesn't be coded. -[10:36:09] [ERROR] : FATAL ERROR -[10:36:09] [ERROR] : Reason of the crash : -[10:36:09] [ERROR] : This method doesn't be coded. - At: - - Server/classes/server.py - \_ Server().generate() -[10:36:09] [ERROR] : If this isn't normal, please send an issue on github. Please check logs for more details. -[10:36:09] [ERROR] : The server is switching off. Closing server : Fatal Error -[10:36:09] [INFO] : Creating crash report file... -[10:36:09] [INFO] : Succes ! -[10:36:09] [INFO] : Stoping the server... -[13:12:42] [INFO] : #Sat Apr 22 13:12:42 2023 -[13:12:42] [INFO] : _____________________________________ -[13:12:42] [INFO] : Starting Server class... -[13:12:43] [INFO] : _____________________________________ -[13:12:43] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[13:12:43] [INFO] : No worlds found, creating 3 new... -[13:12:43] [INFO] : Generating world {0} -[13:12:43] [WARN] : You are overwriting existing data if the world already exists ! -[13:12:43] [WARN] : Method doesn't be coded. -[13:12:43] [ERROR] : FATAL ERROR -[13:12:43] [ERROR] : Reason of the crash : -[13:12:43] [ERROR] : This method doesn't be coded. - At: - - Server/classes/server.py - \_ Server().generate() -[13:12:43] [ERROR] : If this isn't normal, please send an issue on github. Please check logs for more details. -[13:12:43] [ERROR] : The server is switching off. Closing server : Fatal Error -[13:12:43] [INFO] : Creating crash report file... -[13:12:43] [INFO] : Succes ! -[13:12:43] [INFO] : Stoping the server... -[10:51:45] [INFO] : #Sun Apr 23 10:51:45 2023 -[10:51:45] [INFO] : _____________________________________ -[10:51:45] [INFO] : Starting Server class... -[10:51:45] [INFO] : _____________________________________ -[10:51:45] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[10:51:45] [INFO] : No worlds found, creating 3 new... -[10:51:45] [INFO] : Starting creation of the world {0}... -[10:51:45] [INFO] : Generating world world_o -[10:51:45] [WARN] : You are overwriting existing data if the world already exists ! -[10:51:45] [WARN] : Method doesn't be coded. -[10:51:45] [ERROR] : FATAL ERROR -[10:51:45] [ERROR] : Reason of the crash : -[10:51:45] [ERROR] : This method doesn't be coded. - At: - - Server/classes/server.py - \_ Server().generate() -[10:51:45] [ERROR] : If this isn't normal, please send an issue on github. Please check logs for more details. -[10:51:45] [ERROR] : The server is switching off. Closing server : Fatal Error -[10:51:45] [INFO] : Creating crash report file... -[10:51:45] [INFO] : Succes ! -[10:51:46] [INFO] : Stoping the server... -[14:48:31] [INFO] : #Sat Jun 17 14:48:31 2023 -[14:48:31] [INFO] : _____________________________________ -[14:48:31] [INFO] : Starting Server class... -[14:48:31] [INFO] : _____________________________________ -[14:48:31] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[14:48:31] [INFO] : No worlds found, creating 3 new... -[14:48:31] [INFO] : Starting creation of the world {0}... -[14:49:10] [INFO] : #Sat Jun 17 14:49:10 2023 -[14:49:10] [INFO] : _____________________________________ -[14:49:10] [INFO] : Starting Server class... -[14:49:10] [INFO] : _____________________________________ -[14:49:10] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[14:49:10] [INFO] : No worlds found, creating 3 new... -[14:49:10] [INFO] : Starting creation of the world {0}... -[14:49:42] [INFO] : #Sat Jun 17 14:49:42 2023 -[14:49:42] [INFO] : _____________________________________ -[14:49:42] [INFO] : Starting Server class... -[14:49:42] [INFO] : _____________________________________ -[14:49:42] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[14:49:42] [INFO] : No worlds found, creating 3 new... -[14:49:42] [INFO] : Starting creation of the world {0}... -[14:50:34] [INFO] : #Sat Jun 17 14:50:34 2023 -[14:50:34] [INFO] : _____________________________________ -[14:50:34] [INFO] : Starting Server class... -[14:50:34] [INFO] : _____________________________________ -[14:50:34] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[14:50:34] [INFO] : No worlds found, creating 3 new... -[14:50:34] [INFO] : Starting creation of the world {0}... -[14:51:14] [INFO] : #Sat Jun 17 14:51:14 2023 -[14:51:14] [INFO] : _____________________________________ -[14:51:14] [INFO] : Starting Server class... -[14:51:14] [INFO] : _____________________________________ -[14:51:14] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[14:51:14] [INFO] : No worlds found, creating 3 new... -[14:51:14] [INFO] : Starting creation of the world {0}... -[14:51:14] [INFO] : Generating the world with voidgenerator()... -[14:51:14] [INFO] : Done ! -[14:52:10] [INFO] : #Sat Jun 17 14:52:10 2023 -[14:52:10] [INFO] : _____________________________________ -[14:52:10] [INFO] : Starting Server class... -[14:52:10] [INFO] : _____________________________________ -[14:52:10] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[14:52:10] [INFO] : No worlds found, creating 3 new... -[14:52:10] [INFO] : Starting creation of the world {0}... -[14:52:10] [INFO] : Generating the world with voidgenerator()... -[14:52:11] [INFO] : Done ! -[14:54:30] [INFO] : #Sat Jun 17 14:54:30 2023 -[14:54:30] [INFO] : _____________________________________ -[14:54:30] [INFO] : Starting Server class... -[14:54:30] [INFO] : _____________________________________ -[14:54:30] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[14:54:30] [INFO] : No worlds found, creating 3 new... -[14:54:30] [INFO] : Starting creation of the world {0}... -[14:54:30] [INFO] : Generating the world with voidgenerator()... -[14:54:30] [INFO] : Done ! -[14:55:01] [INFO] : #Sat Jun 17 14:55:01 2023 -[14:55:01] [INFO] : _____________________________________ -[14:55:01] [INFO] : Starting Server class... -[14:55:01] [INFO] : _____________________________________ -[14:55:01] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[14:55:18] [INFO] : #Sat Jun 17 14:55:18 2023 -[14:55:18] [INFO] : _____________________________________ -[14:55:18] [INFO] : Starting Server class... -[14:55:18] [INFO] : _____________________________________ -[14:55:18] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[14:55:18] [INFO] : #Sat Jun 17 14:55:18 2023 -[14:55:18] [INFO] : _____________________________________ -[14:55:18] [INFO] : Starting Server class... -[14:55:18] [INFO] : _____________________________________ -[14:55:18] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[14:59:22] [INFO] : #Sat Jun 17 14:59:22 2023 -[14:59:22] [INFO] : _____________________________________ -[14:59:22] [INFO] : Starting Server class... -[14:59:22] [INFO] : _____________________________________ -[14:59:22] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[14:59:49] [INFO] : #Sat Jun 17 14:59:49 2023 -[14:59:49] [INFO] : _____________________________________ -[14:59:49] [INFO] : Starting Server class... -[14:59:49] [INFO] : _____________________________________ -[14:59:49] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[15:00:31] [INFO] : #Sat Jun 17 15:00:31 2023 -[15:00:31] [INFO] : _____________________________________ -[15:00:31] [INFO] : Starting Server class... -[15:00:31] [INFO] : _____________________________________ -[15:00:31] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[15:01:30] [INFO] : #Sat Jun 17 15:01:30 2023 -[15:01:30] [INFO] : _____________________________________ -[15:01:30] [INFO] : Starting Server class... -[15:01:30] [INFO] : _____________________________________ -[15:01:30] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[15:01:55] [INFO] : #Sat Jun 17 15:01:55 2023 -[15:01:55] [INFO] : _____________________________________ -[15:01:55] [INFO] : Starting Server class... -[15:01:55] [INFO] : _____________________________________ -[15:01:55] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[15:02:22] [INFO] : #Sat Jun 17 15:02:22 2023 -[15:02:22] [INFO] : _____________________________________ -[15:02:22] [INFO] : Starting Server class... -[15:02:22] [INFO] : _____________________________________ -[15:02:22] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[15:02:57] [INFO] : #Sat Jun 17 15:02:57 2023 -[15:02:57] [INFO] : _____________________________________ -[15:02:57] [INFO] : Starting Server class... -[15:02:57] [INFO] : _____________________________________ -[15:02:57] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[15:02:57] [INFO] : Stoping the server... -[15:03:07] [INFO] : #Sat Jun 17 15:03:07 2023 -[15:03:07] [INFO] : _____________________________________ -[15:03:07] [INFO] : Starting Server class... -[15:03:07] [INFO] : _____________________________________ -[15:03:07] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[15:03:07] [INFO] : No worlds found, creating 3 new... -[15:03:07] [INFO] : Starting creation of the world {0}... -[15:03:07] [INFO] : Generating the world with voidgenerator()... -[15:03:07] [INFO] : Done ! -[15:03:43] [INFO] : #Sat Jun 17 15:03:43 2023 -[15:03:43] [INFO] : _____________________________________ -[15:03:43] [INFO] : Starting Server class... -[15:03:43] [INFO] : _____________________________________ -[15:03:43] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[15:03:43] [INFO] : Stoping the server... -[15:03:55] [INFO] : #Sat Jun 17 15:03:55 2023 -[15:03:55] [INFO] : _____________________________________ -[15:03:55] [INFO] : Starting Server class... -[15:03:55] [INFO] : _____________________________________ -[15:03:55] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[15:03:55] [INFO] : No worlds found, creating 3 new... -[15:03:55] [INFO] : Starting creation of the world {0}... -[15:03:55] [INFO] : Generating the world with voidgenerator()... -[15:03:55] [INFO] : Done ! -[15:04:26] [INFO] : #Sat Jun 17 15:04:26 2023 -[15:04:26] [INFO] : _____________________________________ -[15:04:26] [INFO] : Starting Server class... -[15:04:26] [INFO] : _____________________________________ -[15:04:26] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[15:04:26] [INFO] : No worlds found, creating 3 new... -[15:04:26] [INFO] : Starting creation of the world {0}... -[15:04:26] [INFO] : Generating the world with voidgenerator()... -[15:04:27] [INFO] : Done ! -[15:05:31] [INFO] : #Sat Jun 17 15:05:31 2023 -[15:05:31] [INFO] : _____________________________________ -[15:05:31] [INFO] : Starting Server class... -[15:05:31] [INFO] : _____________________________________ -[15:05:31] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[15:05:31] [INFO] : No worlds found, creating 3 new... -[15:05:31] [INFO] : Starting creation of the world {0}... -[15:05:31] [INFO] : Generating the world with voidgenerator()... -[15:05:31] [INFO] : Done ! -[15:05:55] [INFO] : #Sat Jun 17 15:05:55 2023 -[15:05:55] [INFO] : _____________________________________ -[15:05:55] [INFO] : Starting Server class... -[15:05:55] [INFO] : _____________________________________ -[15:05:55] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[15:05:55] [INFO] : No worlds found, creating 3 new... -[15:05:55] [INFO] : Starting creation of the world {0}... -[15:05:55] [INFO] : Generating the world with voidgenerator()... -[15:05:55] [INFO] : Done ! -[15:06:07] [INFO] : #Sat Jun 17 15:06:07 2023 -[15:06:07] [INFO] : _____________________________________ -[15:06:07] [INFO] : Starting Server class... -[15:06:07] [INFO] : _____________________________________ -[15:06:07] [WARN] : This version is a developpement version ; launch it will maybe cause some issues. -[15:06:07] [INFO] : No worlds found, creating 3 new... -[15:06:07] [INFO] : Starting creation of the world {0}... -[15:06:07] [INFO] : Generating the world with voidgenerator()... -[15:06:07] [INFO] : Done ! -[15:06:07] [INFO] : Starting creation of the world {0}... -[15:06:07] [INFO] : Generating the world with voidgenerator()... -[15:06:07] [INFO] : Done ! -[15:06:07] [INFO] : Starting creation of the world {0}... -[15:06:07] [INFO] : Generating the world with voidgenerator()... -[15:06:07] [INFO] : Done ! \ No newline at end of file diff --git a/Server/main.py b/main.py similarity index 92% rename from Server/main.py rename to main.py index 6f79a71..961462d 100644 --- a/Server/main.py +++ b/main.py @@ -1,5 +1,5 @@ """A Minecraft server in python 3""" -from classes.server import MinecraftServer as Server +from Server.server import MinecraftServer as Server VERSION = "Alpha-dev" CLIENT_VERSION = "1.19.4"