diff --git a/app/classes/minecraft/stats.py b/app/classes/minecraft/stats.py index 0756b900..ae4f5908 100644 --- a/app/classes/minecraft/stats.py +++ b/app/classes/minecraft/stats.py @@ -7,6 +7,8 @@ import psutil from app.classes.models.management import Host_Stats from app.classes.shared.helpers import helper +from app.classes.models.servers import servers_helper +from app.classes.minecraft.mc_ping import ping logger = logging.getLogger(__name__) @@ -118,6 +120,34 @@ class Stats: return level_total_size + def get_server_players(self, server_id): + + server = servers_helper.get_server_data_by_id(server_id) + + logger.info(f"Getting players for server {server}") + + # get our settings and data dictionaries + # server_settings = server.get('server_settings', {}) + # server_data = server.get('server_data_obj', {}) + + + # TODO: search server properties file for possible override of 127.0.0.1 + internal_ip = server['server_ip'] + server_port = server['server_port'] + + logger.debug("Pinging {internal_ip} on port {server_port}") + if servers_helper.get_server_type_by_id(server_id) != 'minecraft-bedrock': + int_mc_ping = ping(internal_ip, int(server_port)) + + + ping_data = {} + + # if we got a good ping return, let's parse it + if int_mc_ping: + ping_data = Stats.parse_server_ping(int_mc_ping) + return ping_data['players'] + return [] + @staticmethod def parse_server_ping(ping_obj: object): online_stats = {} diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 0668e847..084fd77e 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -799,7 +799,7 @@ class Server: 'version': raw_ping_result.get('version'), 'icon': raw_ping_result.get('icon') }) - if (len(websocket_helper.clients) > 0): + if len(websocket_helper.clients) > 0: websocket_helper.broadcast_page_params( '/panel/server_detail', { @@ -834,9 +834,6 @@ class Server: self.record_server_stats() - #TODO How I do ? - #websocket_helper.broadcast_user_page('/panel/dashboard', user.user_id, 'update_player_status', players_ping) - if (len(servers_ping) > 0) & (len(websocket_helper.clients) > 0): try: websocket_helper.broadcast_page('/panel/dashboard', 'update_server_status', servers_ping) @@ -856,11 +853,9 @@ class Server: logger.debug(f'Getting stats for server: {server_id}') # get our server object, settings and data dictionaries - server_obj = server.get('server_obj', None) self.reload_server_settings() # world data - world_name = server['server_name'] server_path = server['path'] # process stats @@ -987,7 +982,6 @@ class Server: logger.debug(f'Getting stats for server: {server_id}') # get our server object, settings and data dictionaries - server_obj = servers_helper.get_server_obj(server_id) self.reload_server_settings() # world data @@ -1045,9 +1039,9 @@ class Server: ping_data = Stats.parse_server_RakNet_ping(int_mc_ping) try: server_icon = base64.encodebytes(ping_data['icon']) - except Exception as e: + except Exception as ex: server_icon = False - logger.info(f"Unable to read the server icon : {e}") + logger.info(f"Unable to read the server icon : {ex}") server_stats = { 'id': server_id, @@ -1134,4 +1128,3 @@ class Server: last_week = now.day - max_age Server_Stats.delete().where(Server_Stats.created < last_week).execute() - diff --git a/app/classes/shared/tasks.py b/app/classes/shared/tasks.py index ac785e4b..905894d2 100644 --- a/app/classes/shared/tasks.py +++ b/app/classes/shared/tasks.py @@ -16,8 +16,6 @@ from app.classes.web.websocket_helper import websocket_helper from app.classes.minecraft.serverjars import server_jar_obj from app.classes.models.management import management_helper from app.classes.controllers.users_controller import Users_Controller -from app.classes.controllers.servers_controller import Servers_Controller -from app.classes.models.servers import servers_helper from app.classes.models.users import users_helper logger = logging.getLogger('apscheduler') diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 11469e33..b41d36b6 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -363,12 +363,9 @@ class PanelHandler(BaseHandler): logger.error(f"Failed to get server waiting to start: {e}") data['stats']['waiting_start'] = False - try: - self.fetch_server_data(page_data) - except: - page_data['num_players'] = 0 - - IOLoop.current().add_callback(self.fetch_server_data, page_data) + #num players is set to zero here. If we poll all servers while dashboard is loading it takes FOREVER. We leave this to the + #async polling once dashboard is served. + page_data['num_players'] = 0 template = "panel/dashboard.html" diff --git a/app/frontend/templates/panel/dashboard.html b/app/frontend/templates/panel/dashboard.html index 2be0863b..46448d4d 100644 --- a/app/frontend/templates/panel/dashboard.html +++ b/app/frontend/templates/panel/dashboard.html @@ -13,7 +13,10 @@
0 {{ translate('dashboard', 'max', data['lang']) }}
@@ -242,6 +244,7 @@ data['lang']) }} {% end %} + {% end %} @@ -346,6 +349,8 @@ server_world = document.getElementById('server_world_' + server.id); server_desc = document.getElementById('server_desc_' + server.id); server_online_status = document.getElementById('server_running_status_' + server.id); + server_players = document.getElementById('server_players_' + server.id); + total_players = document.getElementById('total_players'); console.log("Received Data : " + server.id + ": " + server); /* TODO Update each element */ @@ -402,6 +407,24 @@ if (server.players) { server_desc.innerHTML = server.online + ` / ` + server.max + ` {{ translate('dashboard', 'max', data['lang']) }}