Skip to content

Commit

Permalink
Update to fix some minor annoyances
Browse files Browse the repository at this point in the history
  • Loading branch information
dries007 committed Jul 13, 2016
1 parent 000e317 commit e87c773
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 14 deletions.
11 changes: 7 additions & 4 deletions src/main/java/net/doubledoordev/backend/server/FileManager.java
Expand Up @@ -126,6 +126,8 @@ public static boolean canEdit(File file)
case "exe":
case "mca":
case "mcr":
case "gz":
case "lock":
return false;

default:
Expand All @@ -135,10 +137,6 @@ public static boolean canEdit(File file)

public String getEditor()
{
if (file.getName().equals("ops.json")) return "ops.ftl";
if (file.getName().equals("whitelist.json")) return "whitelist.ftl";
if (file.getName().equals("banned-players.json")) return "banned-players.ftl";
if (file.getName().equals("banned-ips.json")) return "banned-ips.ftl";
if (file.getName().equals("server.properties")) return "serverProperties.ftl";
switch (getExtension())
{
Expand All @@ -147,6 +145,8 @@ public String getEditor()
case "disabled":
case "mca":
case "mcr":
case "gz":
case "lock":
return null;

case "json":
Expand Down Expand Up @@ -182,6 +182,7 @@ public static String getIcon(File file)
case "jar":
case "zip":
case "disabled":
case "gz":
return "file-archive-o";

case "jpg":
Expand Down Expand Up @@ -220,6 +221,8 @@ public String getFileContents() throws IOException
case "disabled":
case "mca":
case "mcr":
case "gz":
case "lock":
return null;
default:
return StringEscapeUtils.escapeHtml4(FileUtils.readFileToString(file));
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/doubledoordev/backend/server/Server.java
Expand Up @@ -41,6 +41,7 @@

import java.io.*;
import java.lang.reflect.Field;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.file.Files;
Expand Down Expand Up @@ -834,6 +835,10 @@ public void renewQuery()
try
{
cachedResponse = getQuery().fullStat();
}
catch (SocketTimeoutException ignored)
{

}
catch (IOException e)
{
Expand Down Expand Up @@ -904,6 +909,7 @@ public void run()
*/
List<String> arguments = new ArrayList<>();
arguments.add(Constants.getJavaPath());
arguments.add("-DServerOwner=\"" + owner + '"');
arguments.add("-server");
{
int amount = getJvmData().ramMin;
Expand Down Expand Up @@ -973,6 +979,7 @@ public void run()

public void printLine(String line)
{
line = Helper.stripColor(line);
logger.info(line);
ServerconsoleSocketApplication.sendLine(this, line);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/doubledoordev/backend/util/Cache.java
Expand Up @@ -97,7 +97,7 @@ public void run()
forgeBuild.branch = object.get("branch").isJsonNull() ? null : object.get("branch").getAsString();
forgeBuild.build = object.get("build").getAsInt();
forgeBuild.forgeVersion = object.get("version").getAsString();
forgeBuild.mcVersion = object.get("mcversion").getAsString();
forgeBuild.mcVersion = object.get("mcversion").isJsonNull() ? "0" : object.get("mcversion").getAsString();
StringBuilder sb = new StringBuilder(forgeBuild.mcVersion).append('-').append(forgeBuild.forgeVersion);
if (forgeBuild.branch != null) sb.append('-').append(forgeBuild.branch);
forgeBuild.id = sb.toString();
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/doubledoordev/backend/util/Helper.java
Expand Up @@ -36,6 +36,7 @@
import java.net.ServerSocket;
import java.net.URL;
import java.net.URLConnection;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

Expand All @@ -55,6 +56,7 @@ public class Helper
public static final Map<String, String> UUID_USERNMAME_MAP = new HashMap<>();
private static final SimpleDateFormat BAN_SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##");
private static final char[] symbols = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();

private Helper()
Expand Down Expand Up @@ -341,4 +343,9 @@ public static String formatDate(long time)
{
return SIMPLE_DATE_FORMAT.format(time);
}

public static String stripColor(String txt)
{
return txt.replaceAll("(?i)\u00a7[0-9a-fk-or]", "");
}
}
Expand Up @@ -145,7 +145,7 @@ public JsonObject getData(Server server)
root.addProperty("mapName", server.getMapName());
root.addProperty("version", server.getVersion());
root.addProperty("size", server.getDiskspaceUse()[2] + " MB");
root.addProperty("motd", server.getMotd());
root.addProperty("motd", Helper.stripColor(server.getMotd()));
root.addProperty("online", server.getOnline());
root.addProperty("owner", server.getOwner());
root.addProperty("gameMode", server.getGameMode());
Expand All @@ -159,6 +159,7 @@ public JsonObject getData(Server server)
root.add("diskspace", object);
root.add("coOwners", GSON.toJsonTree(server.getCoOwners()));
root.add("admins", GSON.toJsonTree(server.getAdmins()));
root.addProperty("ram", Helper.DECIMAL_FORMAT.format(server.getJvmData().ramMin / 1024.0) + " GB to " + Helper.DECIMAL_FORMAT.format(server.getJvmData().ramMax / 1024.0) + " GB");

return root;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/editors/serverProperties.ftl
Expand Up @@ -13,7 +13,7 @@
</tbody>
</table>
<script>
const readOnlyProperties = ${Helper.getReadOnlyProperties()?js_string};
const readOnlyProperties = ${Helper.getReadOnlyProperties()};
function change(field)
{
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/templates/server.ftl
Expand Up @@ -35,7 +35,7 @@
</tr>
</thead>
<tbody>
<#list ["onlinePlayers", "slots", "motd", "gameMode", "mapName", "playerList", "plugins", "version", "gameID"] as key>
<#list ["onlinePlayers", "slots", "motd", "gameMode", "mapName", "playerList", "plugins", "version", "gameID", "ram"] as key>
<tr>
<td style="text-align: right;">${key}</td>
<td style="text-align: left;" id="${key}"></td>
Expand Down Expand Up @@ -273,6 +273,7 @@
document.getElementById("gameMode").innerHTML = data.gameMode;
document.getElementById("plugins").innerHTML = data.plugins;
document.getElementById("gameID").innerHTML = data.gameID;
document.getElementById("ram").innerHTML = data.ram;
document.getElementById("diskspace_server").innerHTML = data.diskspace.server;
document.getElementById("diskspace_backup").innerHTML = data.diskspace.backups;
Expand Down
14 changes: 8 additions & 6 deletions src/main/resources/templates/servers.ftl
@@ -1,14 +1,14 @@
<#include "header.ftl">
<h1>Server list</h1>
<table class="table table-hover tablesorter" id="servers">
<table class="table table-hover tablesorter" id="servers" style="table-layout: fixed">
<thead>
<tr>
<th class="col-sm-2">Server Name</th>
<th class="col-sm-4">Server Name</th>
<th class="col-sm-2">Server Address</th>
<th class="col-sm-1">Players</th>
<th class="col-sm-1">Total Size</th>
<th class="col-sm-2"></th>
<th class="col-sm-4">MOTD</th>
<th class="col-sm-2" style="min-width: 174px;"></th>
<th class="col-sm-2">RAM (Min Max)</th>
</tr>
</thead>
</table>
Expand Down Expand Up @@ -45,10 +45,12 @@
columns: [
{data: 'id', createdCell: makeClickable},
{data: 'displayAddress', createdCell: makeClickable},
{data: 'onlinePlayers', createdCell: makeClickable},
{data: function (row) {
return row['onlinePlayers'] + " / " + row['slots']
}, createdCell: makeClickable},
{data: 'size', createdCell: makeClickable},
{data: createBtnGroup},
{data: 'motd', createdCell: makeClickable}
{data: 'ram', createdCell: makeClickable},
]
});
var websocket = new WebSocket(wsurl("serverlist"));
Expand Down

0 comments on commit e87c773

Please sign in to comment.