Skip to content

Commit

Permalink
Check patches earlier in startup process if possible.
Browse files Browse the repository at this point in the history
Signed-off-by: Ross Allan <rallanpcl@gmail.com>
  • Loading branch information
LunNova committed Jul 17, 2013
1 parent 8d95daa commit d7a77dc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/common/nallar/patched/server/PatchMinecraftServer.java
Expand Up @@ -84,6 +84,7 @@ public void construct() {
}

public static void staticConstruct() {
PatchUtil.checkPatches();
setTargetTPS(20);
setNetworkTPS(40);
}
Expand Down
23 changes: 1 addition & 22 deletions src/common/nallar/tickthreading/minecraft/TickThreading.java
@@ -1,7 +1,6 @@
package nallar.tickthreading.minecraft;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -39,8 +38,6 @@
import nallar.tickthreading.minecraft.entitylist.LoadedTileEntityList;
import nallar.tickthreading.minecraft.profiling.EntityTickProfiler;
import nallar.tickthreading.minecraft.profiling.Timings;
import nallar.tickthreading.util.CollectionsUtil;
import nallar.tickthreading.util.LocationUtil;
import nallar.tickthreading.util.PatchUtil;
import nallar.tickthreading.util.ReflectUtil;
import nallar.tickthreading.util.TableFormatter;
Expand Down Expand Up @@ -123,25 +120,7 @@ public class TickThreading {

public TickThreading() {
Log.LOGGER.getLevel(); // Force log class to load
try {
PatchUtil.writePatchRunners();
} catch (IOException e) {
Log.severe("Failed to write patch runners", e);
}
List<File> filesToCheck = LocationUtil.getJarLocations();
if (PatchUtil.shouldPatch(filesToCheck)) {
Log.severe("TickThreading is disabled, because your server has not been patched" +
" or the patches are out of date" +
"\nTo patch your server, simply run the PATCHME.bat/sh file in your server directory" +
"\n\nAlso, make a full backup of your server if you haven't already!" +
"\n\nFiles checked for patches: " + CollectionsUtil.join(filesToCheck));
MinecraftServer.getServer().initiateShutdown();
if (!System.getProperty("os.name").startsWith("Windows")) {
PatchUtil.startPatch();
}
Runtime.getRuntime().exit(1);
}
ContextAccess.$.getContext(0);
PatchUtil.checkPatches();
}

@Mod.Init
Expand Down
31 changes: 31 additions & 0 deletions src/common/nallar/tickthreading/util/PatchUtil.java
Expand Up @@ -8,6 +8,7 @@
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Scanner;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
Expand All @@ -19,6 +20,8 @@
import nallar.tickthreading.patcher.PatchMain;
import nallar.tickthreading.patcher.PatchManager;
import nallar.tickthreading.patcher.Patches;
import nallar.tickthreading.util.contextaccess.ContextAccess;
import net.minecraft.server.MinecraftServer;

public enum PatchUtil {
;
Expand Down Expand Up @@ -103,4 +106,32 @@ public void run() {
}
}).start();
}

private static boolean patchesChecked = false;

public static void checkPatches() {
if (patchesChecked) {
return;
}
patchesChecked = true;
try {
PatchUtil.writePatchRunners();
} catch (IOException e) {
Log.severe("Failed to write patch runners", e);
}
List<File> filesToCheck = LocationUtil.getJarLocations();
if (PatchUtil.shouldPatch(filesToCheck)) {
Log.severe("TickThreading is disabled, because your server has not been patched" +
" or the patches are out of date" +
"\nTo patch your server, simply run the PATCHME.bat/sh file in your server directory" +
"\n\nAlso, make a full backup of your server if you haven't already!" +
"\n\nFiles checked for patches: " + CollectionsUtil.join(filesToCheck));
MinecraftServer.getServer().initiateShutdown();
if (!System.getProperty("os.name").startsWith("Windows")) {
PatchUtil.startPatch();
}
Runtime.getRuntime().exit(1);
}
ContextAccess.$.getContext(0);
}
}

0 comments on commit d7a77dc

Please sign in to comment.