def do_restart(self, line): if line == '': self.help_start() return 0 try: int(line) except ValueError: console.error("Server ID must be a number") self.help_start() return 0 try: server = MC_settings.get_by_id(line) except Exception as e: console.help("Unable to find a server with that ID: {}".format(e)) return 0 server = int(line) Remote.insert({ Remote.command: 'restart_mc_server', Remote.server_id: server, Remote.command_source: "localhost" }).execute() console.info("Restarting Minecraft Server in background")
def post(self): token = self.get_argument('token') user = self.authenticate_user(token) if user is None: self.access_denied('unknown') if not check_role_permission( user, 'api_access') and not check_role_permission( user, 'svr_control'): self.access_denied(user) server_id = self.get_argument('id') server = multi.get_server_obj(server_id) if server.check_running(): Remote.insert({ Remote.command: 'stop_mc_server', Remote.server_id: server_id, Remote.command_source: "localhost" }).execute() self.return_response(200, {}, {'code': 'SER_STOP_CALLED'}, {}) else: self.return_response(500, {'error': 'SER_NOT_RUNNING'}, {}, {})
def do_reload_webserver(self, line): Remote.insert({ Remote.command: 'restart_web_server', Remote.server_id: 1, Remote.command_source: 'localhost' }).execute() console.info( "Reloading Tornado Webserver, Please wait 5 seconds to reconnect")
def send_kill_command(): # load the remote commands obj from app.classes.remote_coms import remote_commands from app.classes.http import tornado_srv from app.classes.models import peewee, Remote # start the remote commands watcher thread remote_coms = remote_commands(tornado_srv) remote_coms_thread = threading.Thread(target=remote_coms.start_watcher, daemon=True, name="Remote_Coms") remote_coms_thread.start() Remote.insert({ Remote.command: 'exit_crafty', Remote.server_id: 1, Remote.command_source: 'local' }).execute() time.sleep(2) sys.exit(0)
def watch_for_commands(self): while True: command_instance = Remote.select().where(Remote.id == 1).exists() if command_instance: entry = Remote.get_by_id(1) command_data = model_to_dict(entry) command = command_data['command'] server_id = command_data['server_id'] source = command_data['command_source'] server_data = MC_settings.get_by_id(server_id) server_name = server_data.server_name logger.info( "Remote Command \"%s\" found for server \"%s\" from source %s. Executing!", command, server_name, source) self.handle_command(command, server_id) self.clear_all_commands() time.sleep(1)
def do_start(self, line): if line == '': self.help_start() return 0 try: int(line) except ValueError: console.error("Server ID must be a number") self.help_start() return 0 try: server = MC_settings.get_by_id(line) except Exception as e: console.help("Unable to find a server with that ID: {}".format(e)) return 0 server = int(line) if helper.is_setup_complete(): srv_obj = multi.get_server_obj(server) if srv_obj.check_running(): console.warning("Server already running") else: console.info("Starting Minecraft Server in background") Remote.insert({ Remote.command: 'start_mc_server', Remote.server_id: server, Remote.command_source: "localhost" }).execute() else: console.warning( "Unable to start server, please complete setup in the web GUI first" )
def do_revert_server_jar(self, line): if line == '': self.help_update_server_jar() return 0 try: int(line) except ValueError: console.error("Server ID must be a number") self.help_update_server_jar() return 0 try: server = MC_settings.get_by_id(line) except Exception as e: console.help("Unable to find a server with that ID: {}".format(e)) return 0 server = int(line) if helper.is_setup_complete(): srv_obj = multi.get_server_obj(server) console.info("Reverting updated Server Jar in background") Remote.insert({ Remote.command: 'revert_server_jar_console', Remote.server_id: server, Remote.command_source: "localhost" }).execute() else: console.warning( "Unable to update server jar, please complete setup in the web GUI first" )
def clear_all_commands(self): logger.info("Clearing all Remote Commands") Remote.delete().execute()
def restart_threaded_server(self): Remote.insert({ Remote.command: 'restart_mc_server', Remote.server_id: self.server_id, Remote.command_source: 'local' }).execute()