fix dev mode, add @ cmd
This commit is contained in:
parent
53a4f5f1a8
commit
06517a0d34
13 changed files with 238 additions and 395 deletions
|
@ -1,23 +1,7 @@
|
|||
package common.init;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadInfo;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public abstract class Registry {
|
||||
private static boolean crashed;
|
||||
|
||||
private static void register() {
|
||||
public static void register() {
|
||||
NameRegistry.register();
|
||||
BlockRegistry.register();
|
||||
FlammabilityRegistry.register();
|
||||
|
@ -30,105 +14,4 @@ public abstract class Registry {
|
|||
EntityRegistry.register();
|
||||
DispenserRegistry.register();
|
||||
}
|
||||
|
||||
public static void setup(String thread) {
|
||||
Thread.currentThread().setName(thread);
|
||||
Locale.setDefault(Locale.ROOT);
|
||||
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
|
||||
public void uncaughtException(Thread thread, Throwable e) {
|
||||
System.err.println("Fehler in Thread '" + thread.getName() + "'");
|
||||
e.printStackTrace(System.err);
|
||||
if(crashed)
|
||||
System.exit(1);
|
||||
if(e instanceof OutOfMemoryError) {
|
||||
System.gc();
|
||||
System.gc();
|
||||
}
|
||||
if(!thread.getName().startsWith("Thread-") || e instanceof OutOfMemoryError) {
|
||||
System.err.println("Beende!");
|
||||
crashed = true;
|
||||
if(System.getProperty("crash.nodump") == null) {
|
||||
PrintStream ps = null;
|
||||
File report = null;
|
||||
try {
|
||||
Date date = new Date();
|
||||
File file = new File("crash-" + new SimpleDateFormat("dd.MM.yyyy_HH.mm.ss").format(date) + ".txt");
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
ps = new PrintStream(out);
|
||||
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
|
||||
ThreadInfo[] info = bean.dumpAllThreads(true, true);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Error error = new Error();
|
||||
for(ThreadInfo threadinfo : info) {
|
||||
if(threadinfo.getThreadId() == thread.threadId())
|
||||
error.setStackTrace(threadinfo.getStackTrace());
|
||||
sb.append(threadinfo);
|
||||
}
|
||||
ps.println("************************************************ " + new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(date) + " ************************************************");
|
||||
ps.println();
|
||||
ps.println("\"Wie haste das denn nu wieder geschafft, Bursche?\"");
|
||||
ps.println("Unerwarteter Fehler in Thread '" + thread.getName() + "':");
|
||||
e.printStackTrace(ps);
|
||||
ps.println();
|
||||
ps.println("---------------------------------------------- Thread-Dump (" + info.length + " Threads) ---------------------------------------------");
|
||||
ps.println();
|
||||
ps.print(sb.toString());
|
||||
ps.println("*********************************************************************************************************************");
|
||||
report = file;
|
||||
}
|
||||
catch(Throwable t) {
|
||||
System.err.println("Konnte Absturzbericht nicht speichern:");
|
||||
t.printStackTrace(System.err);
|
||||
}
|
||||
finally {
|
||||
if(ps != null)
|
||||
ps.close();
|
||||
}
|
||||
if(report != null) {
|
||||
System.err.println("Absturzbericht gespeichert unter " + report.getPath());
|
||||
try {
|
||||
Desktop.getDesktop().browse(report.toURI());
|
||||
}
|
||||
catch(Throwable e1) {
|
||||
System.err.println("Konnte " + report + " nicht öffnen: " + e1);
|
||||
}
|
||||
}
|
||||
}
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
ImageIO.setUseCache(false);
|
||||
Thread timer = new Thread("Timer Hack Thread") {
|
||||
public void run() {
|
||||
while(true) {
|
||||
try {
|
||||
Thread.sleep(2147483647L);
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
timer.setDaemon(true);
|
||||
timer.start();
|
||||
System.setProperty("java.net.preferIPv4Stack", "true");
|
||||
register();
|
||||
}
|
||||
|
||||
public static void addShutdownHook(final Runnable hook) {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread("Game Shutdown Thread") {
|
||||
public void run() {
|
||||
if(!crashed) {
|
||||
try {
|
||||
hook.run();
|
||||
}
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,29 @@
|
|||
package common.util;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadInfo;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import common.Version;
|
||||
import common.collect.Lists;
|
||||
import common.collect.Maps;
|
||||
import common.log.Log;
|
||||
import common.rng.Random;
|
||||
|
||||
public abstract class Util {
|
||||
private static final long START = getTime();
|
||||
|
@ -20,6 +32,8 @@ public abstract class Util {
|
|||
public static final boolean DEVMODE = System.getProperty("runtime.devmode") != null;
|
||||
public static final int PROTOCOL = Version.MAJOR << 16 | Version.MINOR << 8 | Version.PATCH;
|
||||
public static final String VERSION = "v" + Version.MAJOR + "." + Version.MINOR + "." + Version.PATCH + Version.RELEASE;
|
||||
|
||||
private static boolean crashed;
|
||||
|
||||
public static String strip(String str, int offset, int len, char newl, char tab, char unk) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
@ -44,100 +58,7 @@ public abstract class Util {
|
|||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
uint utf_read(const char **ptr) {
|
||||
uint ch;
|
||||
byte utf;
|
||||
char c = *((*ptr)++);
|
||||
for(utf = 0; (utf < 6) && (c & (0x80 >> utf)); utf++) {
|
||||
;
|
||||
}
|
||||
if(utf == 1)
|
||||
return CHR_UNK;
|
||||
for(ch = ((!utf) || ((((uint)c) << 6) | (((**ptr) & 0x3f) & ~(0xff >> utf)))) ? (c & (0x7f >> utf)) : 0; utf > 1; utf--) {
|
||||
if(((c = **ptr) & 0xc0) == 0x80) {
|
||||
// if(ch) {
|
||||
ch <<= 6;
|
||||
ch |= c & 0x3f;
|
||||
// }
|
||||
}
|
||||
else {
|
||||
return c ? CHR_UNK : 0;
|
||||
}
|
||||
(*ptr)++;
|
||||
}
|
||||
// fprintf(stderr, "%d / %c\n", ch, ch);
|
||||
return (utf && !ch) ? CHR_UNK : ch;
|
||||
}
|
||||
|
||||
uint utf_readn(const char *ptr, int *pos) {
|
||||
const char *str = &ptr[*pos];
|
||||
uint ch = utf_read(&str);
|
||||
*pos = (int)(str-ptr);
|
||||
return ch;
|
||||
}
|
||||
|
||||
byte utf_write(char **ptr, int *len, uint ch) {
|
||||
uint test;
|
||||
uint mask = 0xffffff80;
|
||||
char utf;
|
||||
char c;
|
||||
if(ch & 0x80000000) {
|
||||
return 1;
|
||||
}
|
||||
for(utf = 0; ch & mask & ~(test = (0xffffffff << ((utf + 1) * 6 + (5 - utf)))); utf++) {
|
||||
mask &= test;
|
||||
}
|
||||
// fprintf(stderr, "%d\n", utf);
|
||||
if(utf + 1 >= (*len)) {
|
||||
return 0;
|
||||
}
|
||||
(*len) -= utf + 1;
|
||||
*((*ptr)++) = utf ? (~(0x7f >> utf) | (((uint)(ch >> (utf * 6))) & (0x3f >> utf))) : ch;
|
||||
for(--utf; utf >= 0; utf--) {
|
||||
*((*ptr)++) = 0x80 | (((uint)(ch >> (utf * 6))) & 0x3f);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
byte utf_rwriten(char *ptr, int *pos, int len, uint ch) {
|
||||
char *str = &ptr[*pos];
|
||||
len -= (*pos);
|
||||
byte res = utf_write(&str, &len, ch);
|
||||
*pos = (int)(str-ptr);
|
||||
return res;
|
||||
}
|
||||
|
||||
uint utf_rread(const char **ptr, const char *start) {
|
||||
const char *tp = *ptr;
|
||||
uint ch;
|
||||
char c;
|
||||
do {
|
||||
if(tp == start)
|
||||
return 0;
|
||||
tp--;
|
||||
} while(((c = (*tp)) & 0xc0) == 0x80);
|
||||
*ptr = tp;
|
||||
return (ch = utf_read(&tp)) ? ch : CHR_UNK;
|
||||
}
|
||||
|
||||
uint utf_rreadn(const char *ptr, int *pos) {
|
||||
const char *str = &ptr[*pos];
|
||||
uint ch = utf_rread(&str, ptr);
|
||||
*pos = (int)(str-ptr);
|
||||
return ch;
|
||||
}
|
||||
|
||||
int utf_len(const char *str) {
|
||||
int len;
|
||||
for(len = 0; utf_read(&str); len++) {
|
||||
;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public static int compareLower(String str1, String str2) {
|
||||
if(str2.length() > str1.length())
|
||||
return 0;
|
||||
|
@ -339,6 +260,124 @@ int utf_len(const char *str) {
|
|||
}
|
||||
}
|
||||
|
||||
public static void setupHandlers() {
|
||||
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
|
||||
public void uncaughtException(Thread thread, Throwable e) {
|
||||
System.err.println("Fehler in Thread '" + thread.getName() + "'");
|
||||
e.printStackTrace(System.err);
|
||||
if(crashed)
|
||||
System.exit(1);
|
||||
if(e instanceof OutOfMemoryError) {
|
||||
System.gc();
|
||||
System.gc();
|
||||
}
|
||||
if(!thread.getName().startsWith("Thread-") || e instanceof OutOfMemoryError) {
|
||||
System.err.println("Beende!");
|
||||
crashed = true;
|
||||
if(!DEVMODE) {
|
||||
PrintStream ps = null;
|
||||
File report = null;
|
||||
try {
|
||||
Date date = new Date();
|
||||
File file = new File("crash-" + new SimpleDateFormat("dd.MM.yyyy_HH.mm.ss").format(date) + ".txt");
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
ps = new PrintStream(out);
|
||||
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
|
||||
ThreadInfo[] info = bean.dumpAllThreads(true, true);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Error error = new Error();
|
||||
for(ThreadInfo threadinfo : info) {
|
||||
if(threadinfo.getThreadId() == thread.threadId())
|
||||
error.setStackTrace(threadinfo.getStackTrace());
|
||||
sb.append(threadinfo);
|
||||
}
|
||||
ps.println("************************************************ " + new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(date) + " ************************************************");
|
||||
ps.println();
|
||||
ps.println("\"Wie haste das denn nu wieder geschafft, Bursche?\"");
|
||||
ps.println("Unerwarteter Fehler in Thread '" + thread.getName() + "':");
|
||||
e.printStackTrace(ps);
|
||||
ps.println();
|
||||
ps.println("---------------------------------------------- Thread-Dump (" + info.length + " Threads) ---------------------------------------------");
|
||||
ps.println();
|
||||
ps.print(sb.toString());
|
||||
ps.println("*********************************************************************************************************************");
|
||||
report = file;
|
||||
}
|
||||
catch(Throwable t) {
|
||||
System.err.println("Konnte Absturzbericht nicht speichern:");
|
||||
t.printStackTrace(System.err);
|
||||
}
|
||||
finally {
|
||||
if(ps != null)
|
||||
ps.close();
|
||||
}
|
||||
if(report != null) {
|
||||
System.err.println("Absturzbericht gespeichert unter " + report.getPath());
|
||||
try {
|
||||
Desktop.getDesktop().browse(report.toURI());
|
||||
}
|
||||
catch(Throwable e1) {
|
||||
System.err.println("Konnte " + report + " nicht öffnen: " + e1);
|
||||
}
|
||||
}
|
||||
}
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
ImageIO.setUseCache(false);
|
||||
Thread timer = new Thread("Timer Hack Thread") {
|
||||
public void run() {
|
||||
while(true) {
|
||||
try {
|
||||
Thread.sleep(2147483647L);
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
timer.setDaemon(true);
|
||||
timer.start();
|
||||
System.setProperty("java.net.preferIPv4Stack", "true");
|
||||
}
|
||||
|
||||
public static void addShutdownHook(final Runnable hook) {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread("Game Shutdown Thread") {
|
||||
public void run() {
|
||||
if(!crashed) {
|
||||
try {
|
||||
hook.run();
|
||||
}
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// plr_play("/home/sen/Musik/midi50k/Video_Games/ff/ff2cecil.mid", 0);
|
||||
public static void meltdown() {
|
||||
Random rand = new Random();
|
||||
Log.SYSTEM.error("CORE_MELTDOWN: Nuclear processor core meltdown imminent\n\n" +
|
||||
" ************************ CAUTION ************************\n" +
|
||||
" KCTL: Processor core #%02d has reached a critical\n" +
|
||||
" temperature, system explosion is imminent! \n" +
|
||||
" According to the general core density \n" +
|
||||
" calculation routine defined by the SKC \n" +
|
||||
" (Hard) Warfare Testing Facility (SKC-WTF) \n" +
|
||||
" your processor will cause a detonation with \n" +
|
||||
" a radius of (roughly) %d.%d kilometers. \n" +
|
||||
" In addition, it will release appoximately \n" +
|
||||
" %d megajoules of ionizing radiation. \n" +
|
||||
" You have an estimate time of %d minutes and \n" +
|
||||
" %d seconds left to clear the detonation area. \n" +
|
||||
" ************************ CAUTION ************************\n"
|
||||
, rand.range(1, 64), rand.range(1, 9), rand.range(0, 9), rand.range(10000, 39999), rand.range(3, 9), rand.range(2, 59));
|
||||
}
|
||||
|
||||
public static Pair<String, String> getKeyValue(String text, char separator) {
|
||||
int index = text.indexOf(separator);
|
||||
if(index == -1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue