Skip to content

Commit 045c154

Browse files
author
HttpRafa
committed
Added TPS
1 parent b1847de commit 045c154

35 files changed

+777
-48
lines changed

.idea/compiler.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/dbnavigator.xml

Lines changed: 467 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/discord.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jsLibraryMappings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ <h5 class="card-title" id="ram_title">RAM</h5>
113113
</div>
114114
</div>
115115
</div>
116+
<div class="col-sm-3 mb-2">
117+
<div class="card">
118+
<div class="card-body">
119+
<h5 class="card-title" id="tps_title">TPS</h5>
120+
<p class="card-text"><span id="tps">0</span> Ticks / <span id="maxTps">0</span> Ticks</p>
121+
<div class="progress flat-progressbar">
122+
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 0%;" id="TpsProgressBar"></div>
123+
</div>
124+
</div>
125+
</div>
126+
</div>
116127
<div class="col-sm-3 mb-2">
117128
<div class="card">
118129
<div class="card-body">

client/scripts/WebConsole.js

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
*/
66

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

1717
/**
1818
* Load list of servers in file servers.json
@@ -61,10 +61,10 @@ function openServer(serverName){
6161
connectionManager.loadConnection(serverName);
6262

6363
//Load saved messages
64-
var i;
65-
var messages = connectionManager.activeConnection.messages;
64+
let i;
65+
const messages = connectionManager.activeConnection.messages;
6666
for(i = 0; i < messages.length; i++){
67-
if(messages[i].status != 401){
67+
if(messages[i].status !== 401){
6868
onWebSocketsMessage(messages[i]);
6969
}
7070
}
@@ -88,7 +88,7 @@ function onWebSocketsMessage(message){
8888
$("#loggedUserTypeLabel").text(message.as);
8989

9090
//Disable command bar if user is viewer
91-
if(message.as.toLowerCase() == "viewer"){
91+
if(message.as.toLowerCase() === "viewer"){
9292
$("#commandInput").prop("disabled", true);
9393
$("#sendCommandButton").prop("disabled", true);
9494
}
@@ -106,7 +106,7 @@ function onWebSocketsMessage(message){
106106
break;
107107
case 401:
108108
//Waiting for login. Show password modal or retrieve password
109-
var savedPwd = persistenceManager.getServer(connectionManager.activeConnection.serverName).serverPassword;
109+
const savedPwd = persistenceManager.getServer(connectionManager.activeConnection.serverName).serverPassword;
110110
if(typeof savedPwd !== "undefined" && !autoPasswordCompleted){
111111
connectionManager.sendPassword(savedPwd);
112112
autoPasswordCompleted = true;
@@ -127,13 +127,17 @@ function onWebSocketsMessage(message){
127127
//RAM Usage
128128
writeRamInfo(message.free, message.used, message.max);
129129
break;
130+
case 1003:
131+
//Server TPS
132+
writeTpsInfo(message.tps, 20);
133+
break;
130134
default:
131135
console.log('Unknown server response:');
132136
}
133137
console.log(message);
134138

135139
//Add interval for Players, CPU and RAM info, if not set
136-
if(statusCommandsInterval == -1 && message.status !== 401){
140+
if(statusCommandsInterval === -1 && message.status !== 401){
137141
statusCommandsInterval = setInterval(function(){
138142
connectionManager.askForInfo();
139143
}, 2500);
@@ -144,8 +148,8 @@ function onWebSocketsMessage(message){
144148
* Write to console
145149
*/
146150
function writeToWebConsole(msg, time){
147-
var isScrolledDown = document.getElementById("consoleTextArea").scrollHeight - document.getElementById("consoleTextArea").scrollTop - 40 == $("#consoleTextArea").height();
148-
151+
const isScrolledDown = document.getElementById("consoleTextArea").scrollHeight - document.getElementById("consoleTextArea").scrollTop - 40 === $("#consoleTextArea").height();
152+
149153
//Write to div, replacing < to &lt; (to avoid XSS) and replacing new line to br.
150154
msg = msg.replace(/</g, "&lt;");
151155
msg = msg.replace(/(?:\r\n|\r|\n)/g, "<br>");
@@ -209,7 +213,7 @@ function writeToWebConsole(msg, time){
209213
$("#consoleTextArea").append(msg + "<br>");
210214

211215
if(isScrolledDown){
212-
var textarea = document.getElementById('consoleTextArea');
216+
const textarea = document.getElementById('consoleTextArea');
213217
textarea.scrollTop = textarea.scrollHeight;
214218
}
215219
}
@@ -220,8 +224,8 @@ function writeToWebConsole(msg, time){
220224
function writePlayerInfo(connected, maximum){
221225
$("#connectedPlayers").text(connected);
222226
$("#maxPlayers").text(maximum);
223-
224-
var percent = (connected/maximum)*100;
227+
228+
const percent = (connected / maximum) * 100;
225229
$("#playerProgressBar").width(percent + "%");
226230
}
227231

@@ -240,16 +244,30 @@ function writeCpuInfo(usage){
240244
function writeRamInfo(free, used, total){
241245
$("#usedRam").text(used);
242246
$("#totalRam").text(total);
243-
244-
var percent = (used/total)*100;
247+
248+
const percent = (used / total) * 100;
245249
$("#RamProgressBar").width(percent + "%");
246250
}
247251

252+
/**
253+
* Fill TPS info card
254+
*/
255+
function writeTpsInfo(tps, max){
256+
if(tps > 20) {
257+
tps = 20;
258+
}
259+
$("#tps").text(tps);
260+
$("#maxTps").text(max);
261+
262+
const percent = (tps / max) * 100;
263+
$("#TpsProgressBar").width(percent + "%");
264+
}
265+
248266
/**
249267
* Called from WebConsoleConnector only.
250268
*/
251269
function closedConnection(serverName){
252-
if(connectionManager.activeConnection.serverName == serverName){
270+
if(connectionManager.activeConnection.serverName === serverName){
253271
//Disable command input and button
254272
$("#commandInput").prop("disabled", true);
255273
$("#sendCommandButton").prop("disabled", true);
@@ -288,13 +306,13 @@ function updateServerList(){
288306
$('.servermenuitem').remove();
289307

290308
//Add all servers
291-
var servers = persistenceManager.getAllServers();
292-
for(var i = 0; i < servers.length; i++){
309+
const servers = persistenceManager.getAllServers();
310+
for(let i = 0; i < servers.length; i++){
293311
$('#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>');
294312
}
295313

296314
//Show a "no servers" message when no servers are added
297-
if(servers.length == 0){
315+
if(servers.length === 0){
298316
$('#ServerListDropDown').append('<a class="dropdown-item servermenuitem disabled" href="#" id="noServersAdded">No servers added</a>');
299317
}
300318
}

client/scripts/WebConsoleManager.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ class WebConsoleManager {
9797
command: "RAMUSAGE",
9898
token: this.activeConnection.token,
9999
});
100+
101+
this.activeConnection.sendToServer({
102+
command: "TPS",
103+
token: this.activeConnection.token,
104+
});
100105
}
101106

102107
/**

0 commit comments

Comments
 (0)