Moved reporting system to CoreBot; JSON-base reports
This commit is contained in:
@@ -40,7 +40,7 @@ public class Vars{
|
|||||||
//discord group URL
|
//discord group URL
|
||||||
public static final String discordURL = "https://discord.gg/BKADYds";
|
public static final String discordURL = "https://discord.gg/BKADYds";
|
||||||
public static final String releasesURL = "https://api.github.com/repos/Anuken/Mindustry/releases";
|
public static final String releasesURL = "https://api.github.com/repos/Anuken/Mindustry/releases";
|
||||||
public static final String crashReportURL = "http://localhost:8080/report";
|
public static final String crashReportURL = "http:/mindustry.us.to/report";
|
||||||
public static final int maxTextLength = 150;
|
public static final int maxTextLength = 150;
|
||||||
public static final int maxNameLength = 40;
|
public static final int maxNameLength = 40;
|
||||||
public static final float itemSize = 5f;
|
public static final float itemSize = 5f;
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public class Control extends Module{
|
|||||||
private Throwable error;
|
private Throwable error;
|
||||||
|
|
||||||
public Control(){
|
public Control(){
|
||||||
|
//TODO remove; only for testing
|
||||||
if(true) throw new RuntimeException("This should crash.");
|
if(true) throw new RuntimeException("This should crash.");
|
||||||
|
|
||||||
saves = new Saves();
|
saves = new Saves();
|
||||||
|
|||||||
@@ -1,21 +1,26 @@
|
|||||||
package io.anuke.mindustry.desktop;
|
package io.anuke.mindustry.desktop;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.utils.JsonValue;
|
||||||
|
import com.badlogic.gdx.utils.JsonValue.ValueType;
|
||||||
|
import com.badlogic.gdx.utils.JsonWriter.OutputType;
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.game.Version;
|
import io.anuke.mindustry.game.Version;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.ucore.core.Settings;
|
import io.anuke.ucore.core.Settings;
|
||||||
import io.anuke.ucore.util.Strings;
|
import io.anuke.ucore.util.Log;
|
||||||
|
|
||||||
import java.nio.file.Files;
|
import java.io.PrintWriter;
|
||||||
import java.nio.file.Paths;
|
import java.io.StringWriter;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class CrashHandler{
|
public class CrashHandler{
|
||||||
|
|
||||||
public static void handle(Throwable e){
|
public static void handle(Throwable e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
||||||
|
//don't create crash logs for me (anuke), as it's expected
|
||||||
|
//also don't create logs for custom builds
|
||||||
|
if(System.getProperty("user.name").equals("anuke") || Version.build == -1) return;
|
||||||
|
|
||||||
boolean netActive = false, netServer = false;
|
boolean netActive = false, netServer = false;
|
||||||
|
|
||||||
//attempt to close connections, if applicable
|
//attempt to close connections, if applicable
|
||||||
@@ -27,47 +32,38 @@ public class CrashHandler{
|
|||||||
p.printStackTrace();
|
p.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
//don't create crash logs for me (anuke), as it's expected
|
JsonValue value = new JsonValue(ValueType.object);
|
||||||
//if(System.getProperty("user.name").equals("anuke")) return;
|
|
||||||
|
|
||||||
String header = "--CRASH REPORT--\n";
|
boolean fn = netActive, fs = netServer;
|
||||||
|
|
||||||
try{
|
//add all relevant info, ignoring exceptions
|
||||||
header += "--GAME INFO--\n";
|
ex(() -> value.addChild("build", new JsonValue(Version.build)));
|
||||||
header += "Build: " + Version.build + "\n";
|
ex(() -> value.addChild("net", new JsonValue(fn)));
|
||||||
header += "Net Active: " + netActive + "\n";
|
ex(() -> value.addChild("server", new JsonValue(fs)));
|
||||||
header += "Net Server: " + netServer + "\n";
|
ex(() -> value.addChild("os", new JsonValue(System.getProperty("os.name"))));
|
||||||
header += "OS: " + System.getProperty("os.name") + "\n";
|
ex(() -> value.addChild("multithreading", new JsonValue(Settings.getBool("multithread"))));
|
||||||
header += "Multithreading: " + Settings.getBool("multithread") + "\n----\n";
|
ex(() -> value.addChild("trace", new JsonValue(parseException(e))));
|
||||||
}catch(Throwable e4){
|
|
||||||
header += "--error getting additional info--\n";
|
Log.info("Sending crash report.");
|
||||||
e4.printStackTrace();
|
//post to crash report URL
|
||||||
|
Net.http(Vars.crashReportURL, "POST", value.toJson(OutputType.json), r -> System.exit(1), t -> System.exit(1));
|
||||||
|
|
||||||
|
//sleep forever
|
||||||
|
try{ Thread.sleep(Long.MAX_VALUE); }catch(InterruptedException ignored){}
|
||||||
}
|
}
|
||||||
|
|
||||||
//parse exception
|
private static String parseException(Throwable e){
|
||||||
String result = header + Strings.parseFullException(e);
|
StringWriter sw = new StringWriter();
|
||||||
boolean failed = false;
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
e.printStackTrace(pw);
|
||||||
String filename = "";
|
return sw.toString();
|
||||||
|
|
||||||
Net.http(Vars.crashReportURL, "POST", result, r -> {}, Throwable::printStackTrace);
|
|
||||||
|
|
||||||
//try to write it
|
|
||||||
try{
|
|
||||||
filename = "crash-report-" + new SimpleDateFormat("dd-MM-yy h.mm.ss").format(new Date()) + ".txt";
|
|
||||||
Files.write(Paths.get(System.getProperty("user.home"), filename), result.getBytes());
|
|
||||||
}catch(Throwable i){
|
|
||||||
i.printStackTrace();
|
|
||||||
failed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ex(Runnable r){
|
||||||
try{
|
try{
|
||||||
javax.swing.JOptionPane.showMessageDialog(null, "An error has occured: \n" + result + "\n\n" +
|
r.run();
|
||||||
(!failed ? "A crash report has been written to " + Paths.get(System.getProperty("user.home"), filename).toFile().getAbsolutePath() + ".\nPlease send this file to the developer!"
|
}catch(Throwable t){
|
||||||
: "Failed to generate crash report.\nPlease send an image of this crash log to the developer!"));
|
t.printStackTrace();
|
||||||
}catch(Throwable i){
|
|
||||||
i.printStackTrace();
|
|
||||||
//what now?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
apply plugin: "java"
|
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
|
||||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
|
||||||
|
|
||||||
project.ext.mainClassName = "io.anuke.mindustry.reporter.Launcher"
|
|
||||||
|
|
||||||
task run(dependsOn: classes, type: JavaExec) {
|
|
||||||
main = project.mainClassName
|
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
|
||||||
standardInput = System.in
|
|
||||||
ignoreExitValue = true
|
|
||||||
}
|
|
||||||
|
|
||||||
task dist(type: Jar) {
|
|
||||||
dependsOn classes
|
|
||||||
from files(sourceSets.main.output.classesDirs)
|
|
||||||
from files(sourceSets.main.output.resourcesDir)
|
|
||||||
from {configurations.compile.collect {zipTree(it)}}
|
|
||||||
|
|
||||||
writeVersion()
|
|
||||||
|
|
||||||
manifest {
|
|
||||||
attributes 'Main-Class': project.mainClassName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package io.anuke.mindustry.reporter;
|
|
||||||
|
|
||||||
import com.sun.net.httpserver.HttpServer;
|
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import static java.lang.System.currentTimeMillis;
|
|
||||||
import static java.lang.System.out;
|
|
||||||
|
|
||||||
public class Launcher{
|
|
||||||
private static final long REQUEST_TIME = 1000 * 6;
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException{
|
|
||||||
ReportHandler handler = new ReportHandler();
|
|
||||||
HashMap<String, Long> rateLimit = new HashMap<>();
|
|
||||||
|
|
||||||
HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
|
|
||||||
server.createContext("/report", t -> {
|
|
||||||
String key = t.getRemoteAddress().getAddress().getHostName();
|
|
||||||
if(rateLimit.get(key) != null && (currentTimeMillis() - rateLimit.get(key)) < REQUEST_TIME){
|
|
||||||
rateLimit.put(key, currentTimeMillis());
|
|
||||||
out.println("connection " + key + " is being rate limited");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
rateLimit.put(key, currentTimeMillis());
|
|
||||||
byte[] bytes = new byte[t.getRequestBody().available()];
|
|
||||||
new DataInputStream(t.getRequestBody()).readFully(bytes);
|
|
||||||
handler.handle(new String(bytes));
|
|
||||||
|
|
||||||
t.sendResponseHeaders(200, 0);
|
|
||||||
});
|
|
||||||
server.setExecutor(null);
|
|
||||||
server.start();
|
|
||||||
out.println("server up");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package io.anuke.mindustry.reporter;
|
|
||||||
|
|
||||||
import static java.lang.System.out;
|
|
||||||
|
|
||||||
public class ReportHandler{
|
|
||||||
|
|
||||||
public void handle(String text){
|
|
||||||
out.println("recieved text: " + text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
./gradlew reporter:dist
|
|
||||||
java -jar reporter/build/libs/reporter-release.jar
|
|
||||||
Reference in New Issue
Block a user