Merge branch 'pretzel-branch' into 'dev'

If you want to start a server...or stop it... or send any command you should...

See merge request crafty-controller/crafty-commander!135
This commit is contained in:
Andrew 2022-01-18 20:44:12 +00:00
commit 7e6aa8c817
5 changed files with 20 additions and 14 deletions

View File

@ -45,6 +45,7 @@ class Management_Controller:
# Example: Admin issued command start_server for server Survival
management_helper.add_to_audit_log(user_id, "issued command {} for server {}".format(command, server_name),
server_id, remote_ip)
management_helper.add_command(server_id, user_id, remote_ip, command)
@staticmethod
def mark_command_complete(command_id=None):

View File

@ -156,7 +156,7 @@ class helpers_management:
@staticmethod
def get_unactioned_commands():
query = Commands.select().where(Commands.executed == 0)
return db_helper.return_rows(query)
return query
@staticmethod
def mark_command_complete(command_id=None):

View File

@ -386,14 +386,6 @@ class Server:
if not self.check_running() and command.lower() != 'start':
logger.warning("Server not running, unable to send command \"{}\"".format(command))
return False
elif command.lower() == self.settings['stop_command']:
logger.info("Stop command detected as terminal input - intercepting. Starting Crafty's stop process for server with id: {}.".format(self.server_id))
self.stop_threaded_server()
return
elif command.lower() == 'restart':
logger.info("Restart command detected as terminal input - intercepting. Starting Crafty's restart process for server with id: {}".format(self.server_id))
self.restart_threaded_server()
return
console.info("COMMAND TIME: {}".format(command))
logger.debug("Sending command {} to server".format(command))
@ -484,7 +476,7 @@ class Server:
def remove_watcher_thread(self):
logger.info("Removing old crash detection watcher thread")
console.info("Removing old crash detection watcher thread")
schedule.clear(self.name)
self.crash_watcher_schedule.remove(self.server_name)
def agree_eula(self, user_id):
file = os.path.join(self.server_path, 'eula.txt')

View File

@ -85,9 +85,14 @@ class TasksManager:
# select any commands waiting to be processed
commands = management_helper.get_unactioned_commands()
for c in commands:
svr = self.controller.get_server_obj(c['server_id']['server_id'])
user_id = c.get('user')['user_id']
command = c.get('command', None)
try:
svr = self.controller.get_server_obj(c.server_id)
except:
logger.error("Server value requested does note exist purging item from waiting commands.")
management_helper.mark_command_complete(c.command_id)
user_id = c.user_id
command = c.command
if command == 'start_server':
svr.run_threaded_server(user_id)
@ -105,7 +110,7 @@ class TasksManager:
svr.jar_update()
else:
svr.send_command(command)
management_helper.mark_command_complete(c.get('command_id', None))
management_helper.mark_command_complete(c.command_id)
time.sleep(1)

View File

@ -199,6 +199,14 @@ class AjaxHandler(BaseHandler):
srv_obj = self.controller.get_server_obj(server_id)
if command == srv_obj.settings['stop_command']:
logger.info("Stop command detected as terminal input - intercepting. Starting Crafty's stop process for server with id: {}.".format(server_id))
self.controller.management.send_command(exec_user['user_id'], server_id, self.get_remote_ip(), 'stop_server')
command = None
elif command == 'restart':
logger.info("Restart command detected as terminal input - intercepting. Starting Crafty's stop process for server with id: {}.".format(server_id))
self.controller.management.send_command(exec_user['user_id'], server_id, self.get_remote_ip(), 'restart_server')
command = None
if command:
if srv_obj.check_running():
srv_obj.send_command(command)