Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
Binary file removed Server/classes/__pycache__/server.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
23 changes: 17 additions & 6 deletions Server/classes/filing/open_game.py → Server/open_game.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
"""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"}

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"
Expand All @@ -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))

Expand All @@ -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 = ""
Expand All @@ -70,7 +81,7 @@ def next(self):

def return_data(self):
"""Return the data rode."""
...
return self.final

if __name__ == "__main__":
exit(0)
File renamed without changes.
43 changes: 33 additions & 10 deletions Server/classes/server.py → Server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand All @@ -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"""
Expand All @@ -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...")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -115,27 +118,27 @@ 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"):
"""Create a new world.
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)
Expand Down Expand Up @@ -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):
Expand Down
Loading