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.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 = {}
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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')
|
||||
|
@ -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"
|
||||
|
||||
|
@ -13,7 +13,10 @@
|
||||
<div class="row page-title-header">
|
||||
<div class="col-12">
|
||||
<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>
|
||||
|
||||
@ -69,7 +72,6 @@
|
||||
<h5 class="mb-1 font-weight-medium text-primary">{{ translate('dashboard', 'players', data['lang']) }}
|
||||
</h5>
|
||||
<h3 class="mb-0 font-weight-semibold" id="total_players">{{ data['num_players'] }}</h3>
|
||||
|
||||
</div>
|
||||
<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>
|
||||
@ -242,6 +244,7 @@
|
||||
data['lang']) }}</span>
|
||||
{% end %}
|
||||
</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>
|
||||
{% 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']) }}<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.online + " / " + server.max + " {{ translate('dashboard', 'max', data['lang']) }}<br />"
|
||||
}
|
||||
@ -509,8 +532,7 @@
|
||||
cpu_usage = document.getElementById('cpu_usage');
|
||||
mem_usage = document.getElementById('mem_usage');
|
||||
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) {
|
||||
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_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) {
|
||||
|
Loading…
Reference in New Issue
Block a user