Added parameter on 1000 response, added MC info cmd and more changes
This commit is contained in:
@ -0,0 +1,31 @@
|
||||
package com.mesacarlos.webconsole.websocket.response;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class ConsoleOutput implements JSONOutput{
|
||||
private String message;
|
||||
|
||||
public ConsoleOutput(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusCode() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("status", getStatusCode());
|
||||
object.addProperty("statusDescription", "Console Output");
|
||||
object.addProperty("message", getMessage());
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.mesacarlos.webconsole.websocket.response;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class CpuUsage implements JSONOutput{
|
||||
private String message;
|
||||
private double usage;
|
||||
|
||||
public CpuUsage(String message, double usage) {
|
||||
this.message = message;
|
||||
this.usage = usage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusCode() {
|
||||
return 1001;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets system CPU Usage
|
||||
* @return Global CPU Usage
|
||||
*/
|
||||
public double getUsage() {
|
||||
return usage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("status", getStatusCode());
|
||||
object.addProperty("statusDescription", "CPU Usage");
|
||||
object.addProperty("usage", getUsage());
|
||||
object.addProperty("message", getMessage());
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.mesacarlos.webconsole.websocket.response;
|
||||
|
||||
public interface JSONOutput {
|
||||
/**
|
||||
* Gets status code representing this message. See docs for code meanings.
|
||||
* @return Status code representing this message
|
||||
*/
|
||||
int getStatusCode();
|
||||
|
||||
/**
|
||||
* Explanatory message of this response
|
||||
* @return Explanatory message of this response
|
||||
*/
|
||||
String getMessage();
|
||||
|
||||
/**
|
||||
* Coverts this object into JSON, ready to send it over WS
|
||||
* @return JSON Object Stringified
|
||||
*/
|
||||
String toJSON();
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.mesacarlos.webconsole.websocket.response;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class LoginRequired implements JSONOutput{
|
||||
private String message;
|
||||
|
||||
public LoginRequired(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusCode() {
|
||||
return 401;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("status", getStatusCode());
|
||||
object.addProperty("statusDescription", "Login Required");
|
||||
object.addProperty("message", getMessage());
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.mesacarlos.webconsole.websocket.response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
public Players(String message, int connectedPlayers, int maxPlayers, List<String> connectedPlayersList) {
|
||||
this.message = message;
|
||||
this.connectedPlayers = connectedPlayers;
|
||||
this.maxPlayers = maxPlayers;
|
||||
this.connectedPlayersList = connectedPlayersList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusCode() {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public int getConnectedPlayers() {
|
||||
return connectedPlayers;
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
return maxPlayers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("status", getStatusCode());
|
||||
object.addProperty("statusDescription", "Players");
|
||||
object.addProperty("connectedPlayers", getConnectedPlayers());
|
||||
object.addProperty("maxPlayers", getMaxPlayers());
|
||||
object.addProperty("players", new Gson().toJson(connectedPlayersList));
|
||||
object.addProperty("message", getMessage());
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.mesacarlos.webconsole.websocket.response;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class Processed implements JSONOutput{
|
||||
private String message;
|
||||
private String respondsTo;
|
||||
|
||||
public Processed(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Processed(String message, String respondsTo) {
|
||||
this.message = message;
|
||||
this.respondsTo = respondsTo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusCode() {
|
||||
return 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* The command that originated this response
|
||||
* @return WebSockets full command and parameters
|
||||
*/
|
||||
private String getRespondsTo() {
|
||||
return respondsTo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("status", getStatusCode());
|
||||
object.addProperty("statusDescription", "Processed");
|
||||
object.addProperty("respondsTo", getRespondsTo());
|
||||
object.addProperty("message", getMessage());
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.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;
|
||||
|
||||
public RamUsage(String message, long free, long used, long max) {
|
||||
this.message = message;
|
||||
this.free = free;
|
||||
this.used = used;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusCode() {
|
||||
return 1002;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free amount of RAM, in MB
|
||||
* @return
|
||||
*/
|
||||
public long getFree() {
|
||||
return free;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used amount of RAM, in MB
|
||||
* @return
|
||||
*/
|
||||
public long getUsed() {
|
||||
return used;
|
||||
}
|
||||
|
||||
/**
|
||||
* Max amount of RAM, in MB
|
||||
* @return
|
||||
*/
|
||||
public long getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("status", getStatusCode());
|
||||
object.addProperty("statusDescription", "RAM Usage");
|
||||
object.addProperty("free", getFree());
|
||||
object.addProperty("used", getUsed());
|
||||
object.addProperty("max", getMax());
|
||||
object.addProperty("message", getMessage());
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.mesacarlos.webconsole.websocket.response;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class UnknownCommand implements JSONOutput{
|
||||
private String message;
|
||||
private String respondsTo;
|
||||
|
||||
public UnknownCommand(String message, String respondsTo) {
|
||||
this.message = message;
|
||||
this.respondsTo = respondsTo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusCode() {
|
||||
return 400;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* The command that originated this response
|
||||
* @return WebSockets full command and parameters
|
||||
*/
|
||||
public String getRespondsTo() {
|
||||
return respondsTo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("status", getStatusCode());
|
||||
object.addProperty("statusDescription", "Unknown Command");
|
||||
object.addProperty("respondsTo", getRespondsTo());
|
||||
object.addProperty("message", getMessage());
|
||||
return object.toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user