commit
b284b00a9b
3
.gitignore
vendored
3
.gitignore
vendored
@ -69,3 +69,6 @@ local.properties
|
||||
.cache-main
|
||||
.scala_dependencies
|
||||
.worksheet
|
||||
|
||||
#idea
|
||||
.idea
|
@ -79,8 +79,8 @@
|
||||
<div class="container" id="serverContainer" style="display: none;">
|
||||
<h1 class="mt-4" id="serverTitle"></h1>
|
||||
|
||||
<div class="row p-3">
|
||||
<div class="col-sm-3 mb-2">
|
||||
<div class="row p-2">
|
||||
<div class="col-sm-3">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title" id="players_online">Players Online</h5>
|
||||
@ -91,7 +91,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-3 mb-2">
|
||||
<div class="col-sm-3">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title" id="cpu_title">CPU</h5>
|
||||
@ -102,7 +102,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-3 mb-2">
|
||||
<div class="col-sm-3">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title" id="ram_title">RAM</h5>
|
||||
@ -113,19 +113,32 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-3 mb-2">
|
||||
<div class="col-sm-3">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<p class="card-text">
|
||||
<span id="user_title">Logged as</span>
|
||||
<span id="loggedUsernameLabel">Unknown</span>
|
||||
(<span id="loggedUserTypeLabel">Unknown</span>)
|
||||
</p>
|
||||
<button type="button" class="btn btn-danger btn-sm" id="deleteServerButton">Delete server</button>
|
||||
<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>
|
||||
<div class="row p-2 mb-2">
|
||||
<div class="col-sm-9">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<span id="user_title">Logged as</span> <span id="loggedUsernameLabel">Unknown</span> (<span id="loggedUserTypeLabel">Unknown</span>)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<div class="card">
|
||||
<button type="button" class="btn btn-danger btn-sm" id="deleteServerButton">Delete server</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mb-2">
|
||||
<div class="card-body overflow-auto text-light bg-dark console" id="consoleTextArea"></div>
|
||||
|
@ -7,12 +7,12 @@
|
||||
/**
|
||||
* 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.
|
||||
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
|
||||
@ -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]);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
@ -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;
|
||||
@ -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);
|
||||
@ -144,7 +148,7 @@ 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 < (to avoid XSS) and replacing new line to br.
|
||||
msg = msg.replace(/</g, "<");
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -221,7 +225,7 @@ function writePlayerInfo(connected, maximum){
|
||||
$("#connectedPlayers").text(connected);
|
||||
$("#maxPlayers").text(maximum);
|
||||
|
||||
var percent = (connected/maximum)*100;
|
||||
const percent = (connected / maximum) * 100;
|
||||
$("#playerProgressBar").width(percent + "%");
|
||||
}
|
||||
|
||||
@ -241,15 +245,29 @@ 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);
|
||||
@ -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,"<").replace(/>/g,">").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>');
|
||||
}
|
||||
}
|
||||
|
@ -97,6 +97,11 @@ class WebConsoleManager {
|
||||
command: "RAMUSAGE",
|
||||
token: this.activeConnection.token,
|
||||
});
|
||||
|
||||
this.activeConnection.sendToServer({
|
||||
command: "TPS",
|
||||
token: this.activeConnection.token,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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.
|
||||
|
@ -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í.
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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のログイン接続はありません。
|
||||
|
@ -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 = 현재 로그인된 사람이 없습니다.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -34,6 +34,9 @@ players-message = {0} oyuncu bağlandı, toplam {1} oyuncu bağlanabilir.
|
||||
# RamUsageCommand.java
|
||||
ram-usage-message = {0} boş, {1} kullanılıyor, {2} maksimum bellek
|
||||
|
||||
# TpsCommand.java
|
||||
tps-message = {0} ticks from {1}
|
||||
|
||||
# WebConsoleCommand.java
|
||||
webconsole-version = WebConsole sürümü {0}.
|
||||
webconsole-no-connections = Şuanda oturum açılmış WebSocket bağlantısı yok.
|
||||
|
@ -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 = 網站控制台版本 {0}.
|
||||
webconsole-no-connections = 現在沒有連接登錄網站控制台。
|
||||
|
@ -23,7 +23,8 @@ import es.mesacarlos.webconsole.websocket.response.LoggedIn;
|
||||
import es.mesacarlos.webconsole.websocket.response.UnknownCommand;
|
||||
|
||||
public class WSServer extends WebSocketServer {
|
||||
private HashMap<String, WSCommand> commands = WSCommandFactory.getCommandsHashMap();
|
||||
|
||||
private final HashMap<String, WSCommand> commands = WSCommandFactory.getCommandsHashMap();
|
||||
|
||||
public WSServer(InetSocketAddress address) {
|
||||
super(address);
|
||||
|
@ -0,0 +1,47 @@
|
||||
package es.mesacarlos.webconsole.websocket.command;
|
||||
|
||||
//------------------------------
|
||||
//
|
||||
// This class was developed by Rafael K.
|
||||
// On 1/8/2022 at 10:22 PM
|
||||
// In the project WebConsole
|
||||
//
|
||||
//------------------------------
|
||||
|
||||
import es.mesacarlos.webconsole.util.Internationalization;
|
||||
import es.mesacarlos.webconsole.websocket.WSServer;
|
||||
import es.mesacarlos.webconsole.websocket.response.Tps;
|
||||
import org.java_websocket.WebSocket;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class TpsCommand implements WSCommand {
|
||||
|
||||
@Override
|
||||
public void execute(WSServer wsServer, WebSocket conn, String params) {
|
||||
try {
|
||||
double tps = getTps()[0];
|
||||
wsServer.sendToClient(conn, new Tps(Internationalization.getPhrase("tps-message", tps), tps));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current server Tps
|
||||
*/
|
||||
public double[] getTps() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
|
||||
Class<?> minecraftServerClass = Class.forName("net.minecraft.server.MinecraftServer");
|
||||
Method getServerMethod = minecraftServerClass.getDeclaredMethod("getServer");
|
||||
Object serverInstance = getServerMethod.invoke(null);
|
||||
Field recentTpsField = serverInstance.getClass().getField("recentTps");
|
||||
double[] recentTps = (double[]) recentTpsField.get(serverInstance);
|
||||
for (int i = 0; i < recentTps.length; i++) {
|
||||
recentTps[i] = Math.round(recentTps[i]);
|
||||
}
|
||||
return recentTps;
|
||||
}
|
||||
|
||||
}
|
@ -11,6 +11,7 @@ public class WSCommandFactory {
|
||||
commands.put("PLAYERS", new PlayersCommand());
|
||||
commands.put("CPUUSAGE", new CpuUsageCommand());
|
||||
commands.put("RAMUSAGE", new RamUsageCommand());
|
||||
commands.put("TPS", new TpsCommand());
|
||||
commands.put("READLOGFILE", new ReadLogFileCommand());
|
||||
return commands;
|
||||
}
|
||||
|
@ -3,8 +3,9 @@ package es.mesacarlos.webconsole.websocket.response;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class ConsoleOutput implements JSONOutput {
|
||||
private String message;
|
||||
private String time;
|
||||
|
||||
private final String message;
|
||||
private final String time;
|
||||
|
||||
public ConsoleOutput(String message, String time) {
|
||||
this.message = message;
|
||||
|
@ -3,8 +3,9 @@ package es.mesacarlos.webconsole.websocket.response;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class CpuUsage implements JSONOutput {
|
||||
private String message;
|
||||
private double usage;
|
||||
|
||||
private final String message;
|
||||
private final double usage;
|
||||
|
||||
public CpuUsage(String message, double usage) {
|
||||
this.message = message;
|
||||
|
@ -5,7 +5,8 @@ import com.google.gson.JsonObject;
|
||||
import es.mesacarlos.webconsole.config.UserType;
|
||||
|
||||
public class LoggedIn implements JSONOutput {
|
||||
private String message;
|
||||
|
||||
private final String message;
|
||||
private String respondsTo;
|
||||
private String username;
|
||||
private UserType as;
|
||||
|
@ -3,7 +3,8 @@ package es.mesacarlos.webconsole.websocket.response;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class LoginRequired implements JSONOutput {
|
||||
private String message;
|
||||
|
||||
private final String message;
|
||||
|
||||
public LoginRequired(String message) {
|
||||
this.message = message;
|
||||
|
@ -6,10 +6,11 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class Players implements JSONOutput {
|
||||
private String message;
|
||||
private int connectedPlayers;
|
||||
private int maxPlayers;
|
||||
private List<String> connectedPlayersList;
|
||||
|
||||
private final String message;
|
||||
private final int connectedPlayers;
|
||||
private final int maxPlayers;
|
||||
private final List<String> connectedPlayersList;
|
||||
|
||||
public Players(String message, int connectedPlayers, int maxPlayers, List<String> connectedPlayersList) {
|
||||
this.message = message;
|
||||
|
@ -3,10 +3,11 @@ package es.mesacarlos.webconsole.websocket.response;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class RamUsage implements JSONOutput {
|
||||
private String message;
|
||||
private long free;
|
||||
private long used;
|
||||
private long max;
|
||||
|
||||
private final String message;
|
||||
private final long free;
|
||||
private final long used;
|
||||
private final long max;
|
||||
|
||||
public RamUsage(String message, long free, long used, long max) {
|
||||
this.message = message;
|
||||
|
51
src/es/mesacarlos/webconsole/websocket/response/Tps.java
Normal file
51
src/es/mesacarlos/webconsole/websocket/response/Tps.java
Normal file
@ -0,0 +1,51 @@
|
||||
package es.mesacarlos.webconsole.websocket.response;
|
||||
|
||||
//------------------------------
|
||||
//
|
||||
// This class was developed by Rafael K.
|
||||
// On 1/8/2022 at 10:23 PM
|
||||
// In the project WebConsole
|
||||
//
|
||||
//------------------------------
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class Tps implements JSONOutput {
|
||||
|
||||
private final String message;
|
||||
private final double tps;
|
||||
|
||||
public Tps(String message, double tps) {
|
||||
this.message = message;
|
||||
this.tps = tps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusCode() {
|
||||
return 1003;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets current server TPS
|
||||
* @return Global Server TPS
|
||||
*/
|
||||
public double getTps() {
|
||||
return tps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("status", getStatusCode());
|
||||
object.addProperty("statusDescription", "TPS Usage");
|
||||
object.addProperty("tps", getTps());
|
||||
object.addProperty("message", getMessage());
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
}
|
@ -3,8 +3,9 @@ package es.mesacarlos.webconsole.websocket.response;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class UnknownCommand implements JSONOutput {
|
||||
private String message;
|
||||
private String respondsTo;
|
||||
|
||||
private final String message;
|
||||
private final String respondsTo;
|
||||
|
||||
public UnknownCommand(String message, String respondsTo) {
|
||||
this.message = message;
|
||||
|
Loading…
x
Reference in New Issue
Block a user