Skip to content
Permalink
Browse files

whole bunch of fixes

  • Loading branch information...
dries007 committed Nov 16, 2014
1 parent a824455 commit 6bd9f4f94b5f474164baf94bde68016cf2774459
Showing with 416 additions and 78 deletions.
  1. +1 −0 src/main/java/net/doubledoordev/backend/Main.java
  2. +10 −0 src/main/java/net/doubledoordev/backend/commands/CommandHandler.java
  3. +88 −0 src/main/java/net/doubledoordev/backend/server/RestartingInfo.java
  4. +22 −26 src/main/java/net/doubledoordev/backend/server/Server.java
  5. +1 −2 src/main/java/net/doubledoordev/backend/server/WorldManager.java
  6. +1 −0 src/main/java/net/doubledoordev/backend/util/Cache.java
  7. +2 −1 src/main/java/net/doubledoordev/backend/util/Constants.java
  8. +0 −3 src/main/java/net/doubledoordev/backend/util/Helper.java
  9. +0 −1 src/main/java/net/doubledoordev/backend/util/PortRange.java
  10. +195 −0 src/main/java/net/doubledoordev/backend/web/socket/AdvancedSettingsSocketApplication.java
  11. +3 −3 src/main/java/net/doubledoordev/backend/web/socket/FileManagerSocketApplication.java
  12. +3 −3 src/main/java/net/doubledoordev/backend/web/socket/ServerControlSocketApplication.java
  13. +8 −9 src/main/java/net/doubledoordev/backend/web/socket/ServerMonitorSocketApplication.java
  14. +2 −2 src/main/java/net/doubledoordev/backend/web/socket/ServerPropertiesSocketApplication.java
  15. +4 −4 src/main/java/net/doubledoordev/backend/web/socket/ServerconsoleSocketApplication.java
  16. +33 −0 src/main/resources/templates/advancedsettings.ftl
  17. +1 −1 src/main/resources/templates/filemanager.ftl
  18. +21 −0 src/main/resources/templates/footer.ftl
  19. +11 −5 src/main/resources/templates/header.ftl
  20. +9 −15 src/main/resources/templates/server.ftl
  21. +1 −3 src/main/resources/templates/{advancedproperties.ftl → worldmanager.ftl}
@@ -146,6 +146,7 @@ public static void main(String[] args) throws Exception
FileManagerSocketApplication.register();
ServerconsoleSocketApplication.register();
ConsoleSocketApplication.register();
AdvancedSettingsSocketApplication.register();

final NetworkListener networkListener = new NetworkListener("secured-listener");
//networkListener.setSecure(true);
@@ -220,4 +220,14 @@ public void cmdShutdown(@Optional @Switch('f') boolean force) throws CommandExce
if (force) System.exit(0);
Main.shutdown();
}

@Command(aliases = {"command", "cmd"}, desc = "Send a command to one or more servers", usage = "<server ID (regex)> <message ...>", min = 2)
public void cmdCommand(Server[] servers, @Text String cmd) throws CommandException
{
for (Server server : servers)
{
if (!server.getOnline()) continue;
server.sendCmd(cmd);
}
}
}
@@ -0,0 +1,88 @@
/*
* Unless otherwise specified through the '@author' tag or comments at
* the top of the file or on a specific portion of the code the following license applies:
*
* Copyright (c) 2014, DoubleDoorDevelopment
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* The header specified or the above copyright notice, this list of conditions
* and the following disclaimer below must be displayed at the top of the source code
* of any web page received while using any part of the service this software provides.
*
* The header to be displayed:
* This page was generated by DoubleDoorDevelopment's D3Backend or a derivative thereof.
*
* Neither the name of the project nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

package net.doubledoordev.backend.server;

import com.google.gson.annotations.Expose;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
* @author Dries007
*/
@SuppressWarnings("UnusedDeclaration")
public class RestartingInfo
{
@Expose
public int globalTimeout = 24;
@Expose
public int whenEmpty = 30;
@Expose
public boolean timer = false;
@Expose
public boolean restartDailyTimeout = false;

private boolean restartNextRun = false;
private Date lastRestart = new Date(0L);

public void run(Server server)
{
try
{
if (!server.getOnline() && !server.isDownloading() && restartNextRun)
{
restartNextRun = false;
server.startServer();
}
}
catch (Exception e)
{

e.printStackTrace();
}
}

public String getLastRestart(String format)
{
return new SimpleDateFormat(format).format(lastRestart);
}
}
@@ -49,6 +49,7 @@
import net.doubledoordev.backend.util.exceptions.ServerOfflineException;
import net.doubledoordev.backend.util.exceptions.ServerOnlineException;
import net.doubledoordev.backend.util.methodCaller.IMethodCaller;
import net.doubledoordev.backend.web.socket.ServerControlSocketApplication;
import net.doubledoordev.backend.web.socket.ServerconsoleSocketApplication;
import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
@@ -79,9 +80,6 @@
public static final String SERVER_PORT = "server-port";
public static final String QUERY_PORT = "query.port";
public static final String QUERY_ENABLE = "enable-query";
public static final String RCON_ENABLE = "enable-rcon";
public static final String RCON_PASSWORD = "rcon.password";
public static final String RCON_PORT = "rcon.port";
public static final String SERVER_IP = "server-ip";

/*
@@ -119,19 +117,21 @@
private List<String> coOwners = new ArrayList<>();
@Expose
private final Map<Integer, Dimension> dimensionMap = new HashMap<>();
@Expose
private RestartingInfo restartingInfo = new RestartingInfo();
/*
* END exposed Json data
*/
/**
* Diskspace var + timer to avoid long page load times.
*/
public int[] size = new int[3];
public int[] size = new int[3];
public QueryResponse cachedResponse;
/**
* Used to reroute server output to our console.
* NOT LOGGED TO FILE!
*/
Logger logger;
private Logger logger;
private File folder;
private File propertiesFile;
private long propertiesFileLastModified = 0L;
@@ -208,11 +208,6 @@ public String getRconPswd()
return rconPswd;
}

public Logger getLogger()
{
return logger;
}

public boolean isDownloading()
{
return downloading;
@@ -316,11 +311,6 @@ public int getServerPort()
return Integer.parseInt(properties.containsKey(SERVER_PORT) ? getProperty(SERVER_PORT) : "-1");
}

public int getRconPort()
{
return Integer.parseInt(properties.containsKey(RCON_PORT) ? getProperty(RCON_PORT) : "-1");
}

public int getOnlinePlayers()
{
return cachedResponse == null ? 0 : cachedResponse.getOnlinePlayers();
@@ -469,6 +459,12 @@ public String toString()
return getID();
}

public RestartingInfo getRestartingInfo()
{
if (restartingInfo == null) restartingInfo = new RestartingInfo();
return restartingInfo;
}

/*
* ========================================================================================
* SETTERS
@@ -658,10 +654,7 @@ public void run()
}
catch (Exception e)
{
printLine("##################################################################");
printLine("Error downloading a new minecraft jar (version " + version + ")");
printLine("##################################################################");
logger.error(e);
error(e);
}
downloading = false;
}
@@ -990,7 +983,7 @@ public void run()
}
catch (IOException e)
{
logger.error(e);
error(e);
}
}
}, ID.concat("-streamEater")).start();
@@ -999,7 +992,7 @@ public void run()
}
catch (IOException e)
{
logger.error(e);
error(e);
}
starting = false;
}
@@ -1012,6 +1005,14 @@ public void printLine(String line)
ServerconsoleSocketApplication.sendLine(this, line);
}

public void error(Throwable e)
{
logger.error(e);
StringWriter error = new StringWriter();
e.printStackTrace(new PrintWriter(error));
ServerconsoleSocketApplication.sendLine(this, error.toString());
}

/**
* Stop the server gracefully
*/
@@ -1127,12 +1128,7 @@ private void normalizeProperties()
if (Settings.SETTINGS.fixedIP) properties.setProperty(SERVER_IP, ip);
else ip = properties.getProperty(SERVER_IP, ip);

if (Settings.SETTINGS.fixedPorts) properties.setProperty(RCON_PORT, String.valueOf(rconPort));
else rconPort = Integer.parseInt(properties.getProperty(RCON_PORT, String.valueOf(rconPort)));

properties.put(RCON_ENABLE, "true");
properties.put(QUERY_ENABLE, "true");
properties.put(RCON_PASSWORD, rconPswd);
}

private void update()
@@ -154,8 +154,7 @@ public void doBackup(File zip, File folder, FilenameFilter filter)
catch (IOException | ZipException e)
{
if (server.getOnline()) server.sendCmd("say Error when making backup");
server.logger.warn(e);
e.printStackTrace();
server.error(e);
}
if (server.getOnline())
{
@@ -330,6 +330,7 @@ public void run()
for (Server server : Settings.SETTINGS.servers.values())
{
server.renewQuery();
server.getRestartingInfo().run(server);
}
}
}, "cache-rConAndQuery").start();
@@ -80,6 +80,7 @@
public static final String ERROR = "error";
public static final String DATA = "data";
public static final String DIM = "DIM";
public static final String RESTARTING_INFO = "RestartingInfo";
/*
* FilenameFilter constants
*/
@@ -136,7 +137,7 @@ public boolean accept(File dir, String name)
public static final long REALLY_LONG_CACHE_TIMEOUT = 1000 * 60 * 60 * 24; // 24 hours
public static final long LONG_CACHE_TIMEOUT = 1000 * 60 * 60; // 1 hour
public static final long MEDIUM_CACHE_TIMEOUT = 1000 * 60; // 1 minute
public static final long SHORT_CACHE_TIMEOUT = 1000 * 10; // 20 seconds
public static final long SHORT_CACHE_TIMEOUT = 1000 * 10; // 10 seconds
/*
* Pattern constants
*/
@@ -309,12 +309,9 @@ public static String getReadOnlyProperties()
{
array.add(new JsonPrimitive(Server.SERVER_PORT));
array.add(new JsonPrimitive(Server.QUERY_PORT));
array.add(new JsonPrimitive(Server.RCON_PORT));
}
if (SETTINGS.fixedIP) array.add(new JsonPrimitive(Server.SERVER_IP));

array.add(new JsonPrimitive(Server.RCON_ENABLE));
array.add(new JsonPrimitive(Server.RCON_PASSWORD));
array.add(new JsonPrimitive(Server.QUERY_ENABLE));

return array.toString();
@@ -61,7 +61,6 @@ public int getNextAvailablePort(int ignored) throws OutOfPortsException
for (Server server : Settings.SETTINGS.servers.values())
{
usedPorts.add(server.getServerPort());
usedPorts.add(server.getRconPort());
}
for (int port = min; port < max; port++)
{

0 comments on commit 6bd9f4f

Please sign in to comment.
You can’t perform that action at this time.