diff --git a/app/classes/shared/command.py b/app/classes/shared/command.py index 18b4f868..9acba552 100644 --- a/app/classes/shared/command.py +++ b/app/classes/shared/command.py @@ -6,6 +6,7 @@ import logging from app.classes.shared.console import console from app.classes.shared.helpers import helper +from app.classes.shared.import3 import import3 from app.classes.web.websocket_helper import websocket_helper logger = logging.getLogger(__name__) @@ -58,6 +59,10 @@ class MainPrompt(cmd.Cmd): else: print(f'Name: {thread.name} Identifier: {thread.ident}') + @staticmethod + def do_import3(): + import3.start_import() + def universal_exit(self): logger.info("Stopping all server daemons / threads") console.info("Stopping all server daemons / threads - This may take a few seconds") @@ -75,3 +80,7 @@ class MainPrompt(cmd.Cmd): @staticmethod def help_migrations(): console.help("Only for advanced users. Use with caution") + + @staticmethod + def help_import3(): + console.help("Import users and servers from Crafty 3") \ No newline at end of file diff --git a/app/classes/shared/import3.py b/app/classes/shared/import3.py new file mode 100644 index 00000000..8c451492 --- /dev/null +++ b/app/classes/shared/import3.py @@ -0,0 +1,33 @@ +import json +import os +import console +import logging +logger = logging.getLogger(__name__) + +from app.classes.controllers.users_controller import users_helper +from app.classes.shared.main_controller import Controller + +class import3: + def start_import(self): + folder = os.path.normpath(input("Please input the path to the migrations folder in your installation of Crafty 3: ")) + if not os.path.exists(folder): + console.log("Crafty cannot find the path you entered. Does Crafty's user have permission to access it?") + console.log("Please run the import3 command again and enter a valid path.") + else: + with open (os.path.join(folder, "users.json")) as f: + user_json = json.load(f.read()) + with open (os.path.join(folder, "mc_settings.json")) as f: + servers_json = json.load(f.read()) + self.import_users(user_json) + self.import_servers(servers_json) + + @staticmethod + def import_users(json_data): + for user in json_data: + users_helper.add_rawpass_user(user.username, user.password) + console.log(f"Imported user {user.username} from Crafty 3") + logger.info(f"Imported user {user.username} from Crafty 3") + + @staticmethod + def import_servers(json_data): + return \ No newline at end of file