5
5
*/
6
6
7
7
/**
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.
16
16
17
17
/**
18
18
* Load list of servers in file servers.json
@@ -61,10 +61,10 @@ function openServer(serverName){
61
61
connectionManager . loadConnection ( serverName ) ;
62
62
63
63
//Load saved messages
64
- var i ;
65
- var messages = connectionManager . activeConnection . messages ;
64
+ let i ;
65
+ const messages = connectionManager . activeConnection . messages ;
66
66
for ( i = 0 ; i < messages . length ; i ++ ) {
67
- if ( messages [ i ] . status != 401 ) {
67
+ if ( messages [ i ] . status !== 401 ) {
68
68
onWebSocketsMessage ( messages [ i ] ) ;
69
69
}
70
70
}
@@ -88,7 +88,7 @@ function onWebSocketsMessage(message){
88
88
$ ( "#loggedUserTypeLabel" ) . text ( message . as ) ;
89
89
90
90
//Disable command bar if user is viewer
91
- if ( message . as . toLowerCase ( ) == "viewer" ) {
91
+ if ( message . as . toLowerCase ( ) === "viewer" ) {
92
92
$ ( "#commandInput" ) . prop ( "disabled" , true ) ;
93
93
$ ( "#sendCommandButton" ) . prop ( "disabled" , true ) ;
94
94
}
@@ -106,7 +106,7 @@ function onWebSocketsMessage(message){
106
106
break ;
107
107
case 401 :
108
108
//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 ;
110
110
if ( typeof savedPwd !== "undefined" && ! autoPasswordCompleted ) {
111
111
connectionManager . sendPassword ( savedPwd ) ;
112
112
autoPasswordCompleted = true ;
@@ -127,13 +127,17 @@ function onWebSocketsMessage(message){
127
127
//RAM Usage
128
128
writeRamInfo ( message . free , message . used , message . max ) ;
129
129
break ;
130
+ case 1003 :
131
+ //Server TPS
132
+ writeTpsInfo ( message . tps , 20 ) ;
133
+ break ;
130
134
default :
131
135
console . log ( 'Unknown server response:' ) ;
132
136
}
133
137
console . log ( message ) ;
134
138
135
139
//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 ) {
137
141
statusCommandsInterval = setInterval ( function ( ) {
138
142
connectionManager . askForInfo ( ) ;
139
143
} , 2500 ) ;
@@ -144,8 +148,8 @@ function onWebSocketsMessage(message){
144
148
* Write to console
145
149
*/
146
150
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
+
149
153
//Write to div, replacing < to < (to avoid XSS) and replacing new line to br.
150
154
msg = msg . replace ( / < / g, "<" ) ;
151
155
msg = msg . replace ( / (?: \r \n | \r | \n ) / g, "<br>" ) ;
@@ -209,7 +213,7 @@ function writeToWebConsole(msg, time){
209
213
$ ( "#consoleTextArea" ) . append ( msg + "<br>" ) ;
210
214
211
215
if ( isScrolledDown ) {
212
- var textarea = document . getElementById ( 'consoleTextArea' ) ;
216
+ const textarea = document . getElementById ( 'consoleTextArea' ) ;
213
217
textarea . scrollTop = textarea . scrollHeight ;
214
218
}
215
219
}
@@ -220,8 +224,8 @@ function writeToWebConsole(msg, time){
220
224
function writePlayerInfo ( connected , maximum ) {
221
225
$ ( "#connectedPlayers" ) . text ( connected ) ;
222
226
$ ( "#maxPlayers" ) . text ( maximum ) ;
223
-
224
- var percent = ( connected / maximum ) * 100 ;
227
+
228
+ const percent = ( connected / maximum ) * 100 ;
225
229
$ ( "#playerProgressBar" ) . width ( percent + "%" ) ;
226
230
}
227
231
@@ -240,16 +244,30 @@ function writeCpuInfo(usage){
240
244
function writeRamInfo ( free , used , total ) {
241
245
$ ( "#usedRam" ) . text ( used ) ;
242
246
$ ( "#totalRam" ) . text ( total ) ;
243
-
244
- var percent = ( used / total ) * 100 ;
247
+
248
+ const percent = ( used / total ) * 100 ;
245
249
$ ( "#RamProgressBar" ) . width ( percent + "%" ) ;
246
250
}
247
251
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
+
248
266
/**
249
267
* Called from WebConsoleConnector only.
250
268
*/
251
269
function closedConnection ( serverName ) {
252
- if ( connectionManager . activeConnection . serverName == serverName ) {
270
+ if ( connectionManager . activeConnection . serverName === serverName ) {
253
271
//Disable command input and button
254
272
$ ( "#commandInput" ) . prop ( "disabled" , true ) ;
255
273
$ ( "#sendCommandButton" ) . prop ( "disabled" , true ) ;
@@ -288,13 +306,13 @@ function updateServerList(){
288
306
$ ( '.servermenuitem' ) . remove ( ) ;
289
307
290
308
//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 ++ ) {
293
311
$ ( '#ServerListDropDown' ) . append ( '<a class="dropdown-item servermenuitem" href="#" onclick="openServer(\'' + servers [ i ] . serverName + '\')">' + servers [ i ] . serverName . replace ( / < / g, "<" ) . replace ( / > / g, ">" ) . replace ( / ' / g, "" ) . replace ( / " / g, "" ) + '</a>' ) ;
294
312
}
295
313
296
314
//Show a "no servers" message when no servers are added
297
- if ( servers . length == 0 ) {
315
+ if ( servers . length === 0 ) {
298
316
$ ( '#ServerListDropDown' ) . append ( '<a class="dropdown-item servermenuitem disabled" href="#" id="noServersAdded">No servers added</a>' ) ;
299
317
}
300
318
}
0 commit comments