diff --git a/app/classes/minecraft/stats.py b/app/classes/minecraft/stats.py index 619c591e..2d4a4209 100644 --- a/app/classes/minecraft/stats.py +++ b/app/classes/minecraft/stats.py @@ -9,6 +9,7 @@ import datetime from app.classes.shared.helpers import helper from app.classes.minecraft.mc_ping import ping from app.classes.shared.controller import controller +from app.classes.shared.models import db_helper from app.classes.shared.models import Host_Stats, Server_Stats logger = logging.getLogger(__name__) @@ -151,6 +152,32 @@ class Stats: } return ping_data + + def get_server_players(self, server_id): + + server = db_helper.get_server_data_by_id(server_id) + + logger.info("Getting players for server {}".format(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_data.get('server_ip', "127.0.0.1") + server_port = server_settings.get('server_port', "25565") + + logger.debug("Pinging {} on port {}".format(internal_ip, server_port)) + 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 = self.parse_server_ping(int_mc_ping) + return ping_data['players'] + return [] def get_servers_stats(self): diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index bc05420c..e010df81 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -516,6 +516,22 @@ class Helpers: @staticmethod def in_path(x, y): return os.path.abspath(y).__contains__(os.path.abspath(x)) + + @staticmethod + def get_banned_players(server_id, db_helper): + stats = db_helper.get_server_stats_by_id(server_id) + server_path = stats[0]['server_id']['path'] + path = os.path.join(server_path, 'banned-players.json') + + try: + with open(path) as file: + content = file.read() + file.close() + except Exception as ex: + print (ex) + return None + + return json.loads(content) helper = Helpers() diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 616074dd..5a434439 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -12,6 +12,7 @@ from app.classes.web.base_handler import BaseHandler from app.classes.shared.controller import controller from app.classes.shared.models import db_helper, Servers from app.classes.shared.helpers import helper +from app.classes.minecraft.stats import stats logger = logging.getLogger(__name__) @@ -109,7 +110,7 @@ class PanelHandler(BaseHandler): self.redirect("/panel/error?error=Invalid Server ID") return False - valid_subpages = ['term', 'logs', 'config', 'files'] + valid_subpages = ['term', 'logs', 'config', 'files', 'admin_controls'] if subpage not in valid_subpages: logger.debug('not a valid subpage') @@ -119,6 +120,29 @@ class PanelHandler(BaseHandler): # server_data isn't needed since the server_stats also pulls server data # page_data['server_data'] = db_helper.get_server_data_by_id(server_id) page_data['server_stats'] = db_helper.get_server_stats_by_id(server_id) + page_data['get_players'] = lambda: stats.get_server_players(server_id) + + def get_banned_players_html(): + banned_players = helper.get_banned_players(server_id, db_helper) + if banned_players is None: + return """ +