mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Bug fixes to ensure player stats display correctly
Add sync indicator to dashboard
This commit is contained in:
parent
52297829df
commit
ab7889914f
@ -7,6 +7,8 @@ import psutil
|
|||||||
from app.classes.models.management import Host_Stats
|
from app.classes.models.management import Host_Stats
|
||||||
|
|
||||||
from app.classes.shared.helpers import helper
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -118,6 +120,34 @@ class Stats:
|
|||||||
|
|
||||||
return level_total_size
|
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
|
@staticmethod
|
||||||
def parse_server_ping(ping_obj: object):
|
def parse_server_ping(ping_obj: object):
|
||||||
online_stats = {}
|
online_stats = {}
|
||||||
|
@ -799,7 +799,7 @@ class Server:
|
|||||||
'version': raw_ping_result.get('version'),
|
'version': raw_ping_result.get('version'),
|
||||||
'icon': raw_ping_result.get('icon')
|
'icon': raw_ping_result.get('icon')
|
||||||
})
|
})
|
||||||
if (len(websocket_helper.clients) > 0):
|
if len(websocket_helper.clients) > 0:
|
||||||
websocket_helper.broadcast_page_params(
|
websocket_helper.broadcast_page_params(
|
||||||
'/panel/server_detail',
|
'/panel/server_detail',
|
||||||
{
|
{
|
||||||
@ -834,9 +834,6 @@ class Server:
|
|||||||
|
|
||||||
self.record_server_stats()
|
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):
|
if (len(servers_ping) > 0) & (len(websocket_helper.clients) > 0):
|
||||||
try:
|
try:
|
||||||
websocket_helper.broadcast_page('/panel/dashboard', 'update_server_status', servers_ping)
|
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}')
|
logger.debug(f'Getting stats for server: {server_id}')
|
||||||
|
|
||||||
# get our server object, settings and data dictionaries
|
# get our server object, settings and data dictionaries
|
||||||
server_obj = server.get('server_obj', None)
|
|
||||||
self.reload_server_settings()
|
self.reload_server_settings()
|
||||||
|
|
||||||
# world data
|
# world data
|
||||||
world_name = server['server_name']
|
|
||||||
server_path = server['path']
|
server_path = server['path']
|
||||||
|
|
||||||
# process stats
|
# process stats
|
||||||
@ -987,7 +982,6 @@ class Server:
|
|||||||
logger.debug(f'Getting stats for server: {server_id}')
|
logger.debug(f'Getting stats for server: {server_id}')
|
||||||
|
|
||||||
# get our server object, settings and data dictionaries
|
# get our server object, settings and data dictionaries
|
||||||
server_obj = servers_helper.get_server_obj(server_id)
|
|
||||||
self.reload_server_settings()
|
self.reload_server_settings()
|
||||||
|
|
||||||
# world data
|
# world data
|
||||||
@ -1045,9 +1039,9 @@ class Server:
|
|||||||
ping_data = Stats.parse_server_RakNet_ping(int_mc_ping)
|
ping_data = Stats.parse_server_RakNet_ping(int_mc_ping)
|
||||||
try:
|
try:
|
||||||
server_icon = base64.encodebytes(ping_data['icon'])
|
server_icon = base64.encodebytes(ping_data['icon'])
|
||||||
except Exception as e:
|
except Exception as ex:
|
||||||
server_icon = False
|
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 = {
|
server_stats = {
|
||||||
'id': server_id,
|
'id': server_id,
|
||||||
@ -1134,4 +1128,3 @@ class Server:
|
|||||||
last_week = now.day - max_age
|
last_week = now.day - max_age
|
||||||
|
|
||||||
Server_Stats.delete().where(Server_Stats.created < last_week).execute()
|
Server_Stats.delete().where(Server_Stats.created < last_week).execute()
|
||||||
|
|
||||||
|
@ -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.minecraft.serverjars import server_jar_obj
|
||||||
from app.classes.models.management import management_helper
|
from app.classes.models.management import management_helper
|
||||||
from app.classes.controllers.users_controller import Users_Controller
|
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
|
from app.classes.models.users import users_helper
|
||||||
|
|
||||||
logger = logging.getLogger('apscheduler')
|
logger = logging.getLogger('apscheduler')
|
||||||
|
@ -363,13 +363,10 @@ class PanelHandler(BaseHandler):
|
|||||||
logger.error(f"Failed to get server waiting to start: {e}")
|
logger.error(f"Failed to get server waiting to start: {e}")
|
||||||
data['stats']['waiting_start'] = False
|
data['stats']['waiting_start'] = False
|
||||||
|
|
||||||
try:
|
#num players is set to zero here. If we poll all servers while dashboard is loading it takes FOREVER. We leave this to the
|
||||||
self.fetch_server_data(page_data)
|
#async polling once dashboard is served.
|
||||||
except:
|
|
||||||
page_data['num_players'] = 0
|
page_data['num_players'] = 0
|
||||||
|
|
||||||
IOLoop.current().add_callback(self.fetch_server_data, page_data)
|
|
||||||
|
|
||||||
template = "panel/dashboard.html"
|
template = "panel/dashboard.html"
|
||||||
|
|
||||||
elif page == 'server_detail':
|
elif page == 'server_detail':
|
||||||
|
@ -13,7 +13,10 @@
|
|||||||
<div class="row page-title-header">
|
<div class="row page-title-header">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h4 class="page-title">{{ translate('dashboard', 'dashboard', data['lang']) }}</h4>
|
<h4 class="page-title">{{ translate('dashboard', 'dashboard', data['lang']) }}
|
||||||
|
{% if data['server_stats']['running'] != 0 %}
|
||||||
|
<span id="sync" style="margin-left: 5px;"><i class="fas fa-sync fa-spin"></i></span></h4>
|
||||||
|
{% end %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -69,7 +72,6 @@
|
|||||||
<h5 class="mb-1 font-weight-medium text-primary">{{ translate('dashboard', 'players', data['lang']) }}
|
<h5 class="mb-1 font-weight-medium text-primary">{{ translate('dashboard', 'players', data['lang']) }}
|
||||||
</h5>
|
</h5>
|
||||||
<h3 class="mb-0 font-weight-semibold" id="total_players">{{ data['num_players'] }}</h3>
|
<h3 class="mb-0 font-weight-semibold" id="total_players">{{ data['num_players'] }}</h3>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="wrapper my-auto ml-auto ml-lg-4">
|
<div class="wrapper my-auto ml-auto ml-lg-4">
|
||||||
<p class="mb-0 text-warning"><span id="max_players">0</span> {{ translate('dashboard', 'max', data['lang']) }}</p>
|
<p class="mb-0 text-warning"><span id="max_players">0</span> {{ translate('dashboard', 'max', data['lang']) }}</p>
|
||||||
@ -242,6 +244,7 @@
|
|||||||
data['lang']) }}</span>
|
data['lang']) }}</span>
|
||||||
{% end %}
|
{% end %}
|
||||||
</td>
|
</td>
|
||||||
|
<span class="server-player-totals" id="server_players_{{server['server_data']['server_id']}}" data-players="{{ server['stats']['online']}}" data-max="{{ server['stats']['max'] }}"></span>
|
||||||
</tr>
|
</tr>
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
@ -346,6 +349,8 @@
|
|||||||
server_world = document.getElementById('server_world_' + server.id);
|
server_world = document.getElementById('server_world_' + server.id);
|
||||||
server_desc = document.getElementById('server_desc_' + server.id);
|
server_desc = document.getElementById('server_desc_' + server.id);
|
||||||
server_online_status = document.getElementById('server_running_status_' + 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);
|
console.log("Received Data : " + server.id + ": " + server);
|
||||||
/* TODO Update each element */
|
/* TODO Update each element */
|
||||||
@ -402,6 +407,24 @@
|
|||||||
if (server.players) {
|
if (server.players) {
|
||||||
server_desc.innerHTML = server.online + ` / ` + server.max + ` {{ translate('dashboard', 'max', data['lang']) }}<br />`
|
server_desc.innerHTML = server.online + ` / ` + server.max + ` {{ translate('dashboard', 'max', data['lang']) }}<br />`
|
||||||
|
|
||||||
|
server_players.setAttribute('data-players', server.online);
|
||||||
|
server_players.setAttribute('data-max', server.max);
|
||||||
|
let servers = document.getElementsByClassName("server-player-totals");
|
||||||
|
let all_total_players = 0;
|
||||||
|
let all_total_max_players = 0;
|
||||||
|
for(var i = 0; i < servers.length; i++){
|
||||||
|
try{
|
||||||
|
all_total_players += parseInt(servers[i].getAttribute('data-players'));
|
||||||
|
all_total_max_players += parseInt(servers[i].getAttribute('data-max'));
|
||||||
|
}catch{
|
||||||
|
console.log("Player totals are not of type int");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
total_players.innerHTML = all_total_players;
|
||||||
|
document.getElementById('max_players').innerHTML = all_total_max_players;
|
||||||
|
document.getElementById('sync').innerHTML = '';
|
||||||
|
|
||||||
|
|
||||||
server_infos = "";
|
server_infos = "";
|
||||||
server_infos = server.online + " / " + server.max + " {{ translate('dashboard', 'max', data['lang']) }}<br />"
|
server_infos = server.online + " / " + server.max + " {{ translate('dashboard', 'max', data['lang']) }}<br />"
|
||||||
}
|
}
|
||||||
@ -509,8 +532,7 @@
|
|||||||
cpu_usage = document.getElementById('cpu_usage');
|
cpu_usage = document.getElementById('cpu_usage');
|
||||||
mem_usage = document.getElementById('mem_usage');
|
mem_usage = document.getElementById('mem_usage');
|
||||||
mem_percent = document.getElementById('mem_percent');
|
mem_percent = document.getElementById('mem_percent');
|
||||||
total_players = document.getElementById('total_players');
|
|
||||||
max_players = document.getElementById('max_players');
|
|
||||||
|
|
||||||
webSocket.on('update_host_stats', function (hostStats) {
|
webSocket.on('update_host_stats', function (hostStats) {
|
||||||
var cpuDataTitle = `{% raw translate('dashboard', 'cpuCores', data['lang']) %}: ${hostStats.cpu_cores} <br /> {% raw translate("dashboard", "cpuCurFreq", data['lang']) %}: ${hostStats.cpu_cur_freq} <br /> {% raw translate("dashboard", "cpuMaxFreq", data['lang']) %}: ${hostStats.cpu_max_freq}`;
|
var cpuDataTitle = `{% raw translate('dashboard', 'cpuCores', data['lang']) %}: ${hostStats.cpu_cores} <br /> {% raw translate("dashboard", "cpuCurFreq", data['lang']) %}: ${hostStats.cpu_cur_freq} <br /> {% raw translate("dashboard", "cpuMaxFreq", data['lang']) %}: ${hostStats.cpu_max_freq}`;
|
||||||
@ -519,10 +541,6 @@
|
|||||||
mem_usage.setAttribute('data-original-title', `{% raw translate("dashboard", "memUsage", data['lang']) %}: ${hostStats.mem_usage}`);
|
mem_usage.setAttribute('data-original-title', `{% raw translate("dashboard", "memUsage", data['lang']) %}: ${hostStats.mem_usage}`);
|
||||||
mem_percent.textContent = hostStats.mem_percent + '%';
|
mem_percent.textContent = hostStats.mem_percent + '%';
|
||||||
});
|
});
|
||||||
webSocket.on('update_player_status', function (playerStats) {
|
|
||||||
total_players.innerHTML = playerStats.total_players;
|
|
||||||
max_players.innerHTML = playerStats.max_players;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (webSocket) {
|
if (webSocket) {
|
||||||
|
Loading…
Reference in New Issue
Block a user