Merge branch 'dev' into bug/fix-issue-#106

This commit is contained in:
Zedifus 2022-07-18 21:17:41 +01:00
commit 374454f11c
4 changed files with 5 additions and 40 deletions

View File

@ -7,6 +7,7 @@
- Toggle Visible servers on status page ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/399))
### Bug fixes
- Fixes stats recording for Oracle hosts ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/397))
- Improve the use of the object oriented architecture ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/400))
### Tweaks
None
### Lang

View File

@ -7,9 +7,7 @@ import base64
import typing as t
from app.classes.shared.null_writer import NullWriter
from app.classes.minecraft.mc_ping import ping
from app.classes.models.management import HostStats
from app.classes.models.servers import HelperServers
from app.classes.shared.helpers import Helpers
with redirect_stderr(NullWriter()):
@ -220,32 +218,6 @@ class Stats:
return level_total_size
def get_server_players(self, server_id):
server = HelperServers.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(f"Pinging {internal_ip} on port {server_port}")
if HelperServers.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 = {}

View File

@ -192,9 +192,9 @@ class PanelHandler(BaseHandler):
total_players = 0
for server in page_data["servers"]:
total_players += len(
self.controller.servers.stats.get_server_players(
self.controller.servers.get_server_instance_by_id(
server["server_data"]["server_id"]
)
).get_server_players()
)
page_data["num_players"] = total_players
@ -539,9 +539,7 @@ class PanelHandler(BaseHandler):
except Exception as e:
logger.error(f"Failed to get server waiting to start: {e}")
page_data["waiting_start"] = False
page_data[
"get_players"
] = lambda: self.controller.servers.stats.get_server_players(server_id)
page_data["get_players"] = server.get_server_players()
page_data["active_link"] = subpage
page_data["permissions"] = {
"Commands": EnumPermissionsServer.COMMANDS,
@ -877,9 +875,6 @@ class PanelHandler(BaseHandler):
page_data["schedules"] = HelpersManagement.get_schedules_by_server(
server_id
)
page_data[
"get_players"
] = lambda: self.controller.servers.stats.get_server_players(server_id)
page_data["active_link"] = "schedules"
page_data["permissions"] = {
"Commands": EnumPermissionsServer.COMMANDS,
@ -945,9 +940,6 @@ class PanelHandler(BaseHandler):
self.redirect("/panel/error?error=Invalid Schedule ID")
return
schedule = self.controller.management.get_scheduled_task_model(sch_id)
page_data[
"get_players"
] = lambda: self.controller.servers.stats.get_server_players(server_id)
page_data["active_link"] = "schedules"
page_data["permissions"] = {
"Commands": EnumPermissionsServer.COMMANDS,

View File

@ -73,7 +73,7 @@
</style>
<h2>{{ translate('serverPlayerManagement', 'players', data['lang']) }}:</h2>
<ul style="list-style: none;padding: 0px;margin: 0px; margin-bottom: 1rem;gap: 1rem;">
{% for player in data['get_players']() %}
{% for player in data['get_players'] %}
<li class="playerItem">
<h3>{{ player }}</h3>
<div class="buttons">