Skip to content

Commit

Permalink
Added TPS
Browse files Browse the repository at this point in the history
  • Loading branch information
HttpRafa committed Jan 8, 2022
1 parent b1847de commit 045c154
Show file tree
Hide file tree
Showing 35 changed files with 777 additions and 48 deletions.
13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

467 changes: 467 additions & 0 deletions .idea/dbnavigator.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ <h5 class="card-title" id="ram_title">RAM</h5>
</div>
</div>
</div>
<div class="col-sm-3 mb-2">
<div class="card">
<div class="card-body">
<h5 class="card-title" id="tps_title">TPS</h5>
<p class="card-text"><span id="tps">0</span> Ticks / <span id="maxTps">0</span> Ticks</p>
<div class="progress flat-progressbar">
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 0%;" id="TpsProgressBar"></div>
</div>
</div>
</div>
</div>
<div class="col-sm-3 mb-2">
<div class="card">
<div class="card-body">
Expand Down
68 changes: 43 additions & 25 deletions client/scripts/WebConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/

/**
* Global variables
*/
var persistenceManager = new WebConsolePersistenceManager();
var connectionManager = new WebConsoleManager();
var lang;
var autoPasswordCompleted = false; //When true, saved password was used. If a 401 is received, then saved password is not correct
var statusCommandsInterval = -1;
var commandHistoryIndex = -1; //Saves current command history index. -1 when not browsing history.
* Global variables
*/
const persistenceManager = new WebConsolePersistenceManager();
const connectionManager = new WebConsoleManager();
let lang;
let autoPasswordCompleted = false; //When true, saved password was used. If a 401 is received, then saved password is not correct
let statusCommandsInterval = -1;
let commandHistoryIndex = -1; //Saves current command history index. -1 when not browsing history.

/**
* Load list of servers in file servers.json
Expand Down Expand Up @@ -61,10 +61,10 @@ function openServer(serverName){
connectionManager.loadConnection(serverName);

//Load saved messages
var i;
var messages = connectionManager.activeConnection.messages;
let i;
const messages = connectionManager.activeConnection.messages;
for(i = 0; i < messages.length; i++){
if(messages[i].status != 401){
if(messages[i].status !== 401){
onWebSocketsMessage(messages[i]);
}
}
Expand All @@ -88,7 +88,7 @@ function onWebSocketsMessage(message){
$("#loggedUserTypeLabel").text(message.as);

//Disable command bar if user is viewer
if(message.as.toLowerCase() == "viewer"){
if(message.as.toLowerCase() === "viewer"){
$("#commandInput").prop("disabled", true);
$("#sendCommandButton").prop("disabled", true);
}
Expand All @@ -106,7 +106,7 @@ function onWebSocketsMessage(message){
break;
case 401:
//Waiting for login. Show password modal or retrieve password
var savedPwd = persistenceManager.getServer(connectionManager.activeConnection.serverName).serverPassword;
const savedPwd = persistenceManager.getServer(connectionManager.activeConnection.serverName).serverPassword;
if(typeof savedPwd !== "undefined" && !autoPasswordCompleted){
connectionManager.sendPassword(savedPwd);
autoPasswordCompleted = true;
Expand All @@ -127,13 +127,17 @@ function onWebSocketsMessage(message){
//RAM Usage
writeRamInfo(message.free, message.used, message.max);
break;
case 1003:
//Server TPS
writeTpsInfo(message.tps, 20);
break;
default:
console.log('Unknown server response:');
}
console.log(message);

//Add interval for Players, CPU and RAM info, if not set
if(statusCommandsInterval == -1 && message.status !== 401){
if(statusCommandsInterval === -1 && message.status !== 401){
statusCommandsInterval = setInterval(function(){
connectionManager.askForInfo();
}, 2500);
Expand All @@ -144,8 +148,8 @@ function onWebSocketsMessage(message){
* Write to console
*/
function writeToWebConsole(msg, time){
var isScrolledDown = document.getElementById("consoleTextArea").scrollHeight - document.getElementById("consoleTextArea").scrollTop - 40 == $("#consoleTextArea").height();
const isScrolledDown = document.getElementById("consoleTextArea").scrollHeight - document.getElementById("consoleTextArea").scrollTop - 40 === $("#consoleTextArea").height();

//Write to div, replacing < to &lt; (to avoid XSS) and replacing new line to br.
msg = msg.replace(/</g, "&lt;");
msg = msg.replace(/(?:\r\n|\r|\n)/g, "<br>");
Expand Down Expand Up @@ -209,7 +213,7 @@ function writeToWebConsole(msg, time){
$("#consoleTextArea").append(msg + "<br>");

if(isScrolledDown){
var textarea = document.getElementById('consoleTextArea');
const textarea = document.getElementById('consoleTextArea');
textarea.scrollTop = textarea.scrollHeight;
}
}
Expand All @@ -220,8 +224,8 @@ function writeToWebConsole(msg, time){
function writePlayerInfo(connected, maximum){
$("#connectedPlayers").text(connected);
$("#maxPlayers").text(maximum);
var percent = (connected/maximum)*100;

const percent = (connected / maximum) * 100;
$("#playerProgressBar").width(percent + "%");
}

Expand All @@ -240,16 +244,30 @@ function writeCpuInfo(usage){
function writeRamInfo(free, used, total){
$("#usedRam").text(used);
$("#totalRam").text(total);
var percent = (used/total)*100;

const percent = (used / total) * 100;
$("#RamProgressBar").width(percent + "%");
}

/**
* Fill TPS info card
*/
function writeTpsInfo(tps, max){
if(tps > 20) {
tps = 20;
}
$("#tps").text(tps);
$("#maxTps").text(max);

const percent = (tps / max) * 100;
$("#TpsProgressBar").width(percent + "%");
}

/**
* Called from WebConsoleConnector only.
*/
function closedConnection(serverName){
if(connectionManager.activeConnection.serverName == serverName){
if(connectionManager.activeConnection.serverName === serverName){
//Disable command input and button
$("#commandInput").prop("disabled", true);
$("#sendCommandButton").prop("disabled", true);
Expand Down Expand Up @@ -288,13 +306,13 @@ function updateServerList(){
$('.servermenuitem').remove();

//Add all servers
var servers = persistenceManager.getAllServers();
for(var i = 0; i < servers.length; i++){
const servers = persistenceManager.getAllServers();
for(let i = 0; i < servers.length; i++){
$('#ServerListDropDown').append('<a class="dropdown-item servermenuitem" href="#" onclick="openServer(\'' + servers[i].serverName + '\')">' + servers[i].serverName.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"").replace(/"/g,"") + '</a>');
}

//Show a "no servers" message when no servers are added
if(servers.length == 0){
if(servers.length === 0){
$('#ServerListDropDown').append('<a class="dropdown-item servermenuitem disabled" href="#" id="noServersAdded">No servers added</a>');
}
}
5 changes: 5 additions & 0 deletions client/scripts/WebConsoleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ class WebConsoleManager {
command: "RAMUSAGE",
token: this.activeConnection.token,
});

this.activeConnection.sendToServer({
command: "TPS",
token: this.activeConnection.token,
});
}

/**
Expand Down
3 changes: 3 additions & 0 deletions phrases.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ players-message = Connected {0} players for a maximum of {1}
# RamUsageCommand.java
ram-usage-message = {0} free, {1} used, {2} maximum memory

# TpsCommand.java
tps-message = {0} ticks from {1}

# WebConsoleCommand.java
webconsole-version = WebConsole version {0}.
webconsole-no-connections = There are no logged in WebConsole connections now.
Expand Down
3 changes: 3 additions & 0 deletions phrases_cs.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ players-message = Je připojeno {0} hráčů z maxima {1}
# RamUsageCommand.java
ram-usage-message = {0} volné, {1} použité, {2} maximální paměti

# TpsCommand.java
tps-message = {0} ticks from {1}

# WebConsoleCommand.java
webconsole-version = WebConsole verze {0}.
webconsole-no-connections = Nejsou žádné WebConsole připojení.
Expand Down
3 changes: 3 additions & 0 deletions phrases_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ players-message = {0} von {1} Spieler sind verbunden.
# RamUsageCommand.java
ram-usage-message = {0} frei, {1} benutzt, {2} maximal

# TpsCommand.java
tps-message = {0} ticks von {1}

# WebConsoleCommand.java
webconsole-version = Die WebConsole Version ist {0}.
webconsole-no-connections = Aktuell ist niemand mit der WebConsole verbunden
Expand Down
3 changes: 3 additions & 0 deletions phrases_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ players-message = Connected {0} players for a maximum of {1}
# RamUsageCommand.java
ram-usage-message = {0} free, {1} used, {2} maximum memory

# TpsCommand.java
tps-message = {0} ticks from {1}

# WebConsoleCommand.java
webconsole-version = WebConsole version {0}.
webconsole-no-connections = There are no logged in WebConsole connections now.
Expand Down
3 changes: 3 additions & 0 deletions phrases_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ players-message = Actualmente conectados {0} jugadores de un máximo de {1}
# RamUsageCommand.java
ram-usage-message = Memoria: {0} libre, {1} usada, {2} maxima

# TpsCommand.java
tps-message = {0} ticks from {1}

# WebConsoleCommand.java
webconsole-version = WebConsole version {0}.
webconsole-no-connections = No hay ninguna conexión activa a WebConsole en este momento.
Expand Down
3 changes: 3 additions & 0 deletions phrases_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ players-message = Joueurs {0} connectés pour un maximum de {1}
# RamUsageCommand.java
ram-usage-message = {0} gratuit, {1} utilisé, {2} mémoire maximale

# TpsCommand.java
tps-message = {0} ticks from {1}

# WebConsoleCommand.java
webconsole-version = version WebConsole {0}.
webconsole-no-connections = Aucune connexion WebConsole n'est connectée maintenant.
Expand Down
3 changes: 3 additions & 0 deletions phrases_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ players-message = Connessi {0} players su un massimo di {1}
# RamUsageCommand.java
ram-usage-message = {0} Libera, {1} Usata, {2} Memoria massima

# TpsCommand.java
tps-message = {0} ticks from {1}

# WebConsoleCommand.java
webconsole-version = Versione WebConsole {0}.
webconsole-no-connections = Non è stata effettuata ancora nessuna connessione tramite WebConsole.
Expand Down
3 changes: 3 additions & 0 deletions phrases_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ players-message = 接続数 | {0} ,最大接続数 | {1}
# RamUsageCommand.java
ram-usage-message = {0} 空き, {1} 使用済み, {2} 最大メモリ

# TpsCommand.java
tps-message = {0} ticks from {1}

# WebConsoleCommand.java
webconsole-version = WebConsoleのバージョン {0}.
webconsole-no-connections = 現在、WebConsoleのログイン接続はありません。
Expand Down
3 changes: 3 additions & 0 deletions phrases_ko.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ players-message = {0}/{1}명의 플레이어를 연결하였습니다
# RamUsageCommand.java
ram-usage-message = {0} 여유, {1} 사용, {2} 최대

# TpsCommand.java
tps-message = {0} ticks from {1}

# WebConsoleCommand.java
webconsole-version = WebConsole 버전 {0}.
webconsole-no-connections = 현재 로그인된 사람이 없습니다.
Expand Down
3 changes: 3 additions & 0 deletions phrases_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ players-message = {0} spelers verbonden voor een maximum van {1}
# RamUsageCommand.java
ram-usage-message = {0} ongebruikt, {1} gebruikt, {2} maximaal geheugen

# TpsCommand.java
tps-message = {0} ticks from {1}

# WebConsoleCommand.java
webconsole-version = WebConsole versie {0}.
webconsole-no-connections = Er zijn nu geen ingelogde Web Console-verbindingen.
Expand Down
3 changes: 3 additions & 0 deletions phrases_pt.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ players-message = Atualmente tem {0} jogador(es) de um total de {1}
# RamUsageCommand.java
ram-usage-message = Disponível: {0}, Consumo de RAM: {1} / {2}

# TpsCommand.java
tps-message = {0} ticks from {1}

# WebConsoleCommand.java
webconsole-version = WebConsole versão {0}.
webconsole-no-connections = Atualmente não tem nenhum usuário conectado.
Expand Down
3 changes: 3 additions & 0 deletions phrases_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ players-message = Подключено {0} игроков из максимум
# RamUsageCommand.java
ram-usage-message = {0} свободно, {1} используется, {2} макс. памяти

# TpsCommand.java
tps-message = {0} ticks from {1}

# WebConsoleCommand.java
webconsole-version = Версия WebConsole {0}.
webconsole-no-connections = В настоящее время нет подключений к WebConsole.
Expand Down
Loading

0 comments on commit 045c154

Please sign in to comment.