Initial proof-of-concept for crash report server
This commit is contained in:
@@ -232,6 +232,10 @@ project(":kryonet") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
project(":reporter"){
|
||||||
|
apply plugin: "java"
|
||||||
|
}
|
||||||
|
|
||||||
tasks.eclipse.doLast {
|
tasks.eclipse.doLast {
|
||||||
delete ".project"
|
delete ".project"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +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 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(){
|
||||||
|
if(true) throw new RuntimeException("This should crash.");
|
||||||
|
|
||||||
saves = new Saves();
|
saves = new Saves();
|
||||||
db = new ContentDatabase();
|
db = new ContentDatabase();
|
||||||
|
|||||||
@@ -309,8 +309,12 @@ public class Net{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void http(String url, String method, Consumer<String> listener, Consumer<Throwable> failure){
|
public static void http(String url, String method, Consumer<String> listener, Consumer<Throwable> failure){
|
||||||
|
http(url, method, null, listener, failure);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void http(String url, String method, String body, Consumer<String> listener, Consumer<Throwable> failure){
|
||||||
HttpRequest req = new HttpRequestBuilder().newRequest()
|
HttpRequest req = new HttpRequestBuilder().newRequest()
|
||||||
.method(method).url(url).build();
|
.method(method).url(url).content(body).build();
|
||||||
|
|
||||||
Gdx.net.sendHttpRequest(req, new HttpResponseListener(){
|
Gdx.net.sendHttpRequest(req, new HttpResponseListener(){
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package io.anuke.mindustry.desktop;
|
package io.anuke.mindustry.desktop;
|
||||||
|
|
||||||
|
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;
|
||||||
@@ -13,7 +14,6 @@ import java.util.Date;
|
|||||||
public class CrashHandler{
|
public class CrashHandler{
|
||||||
|
|
||||||
public static void handle(Throwable e){
|
public static void handle(Throwable e){
|
||||||
//TODO send full error report to server via HTTP
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
||||||
boolean netActive = false, netServer = false;
|
boolean netActive = false, netServer = false;
|
||||||
@@ -28,7 +28,7 @@ public class CrashHandler{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//don't create crash logs for me (anuke), as it's expected
|
//don't create crash logs for me (anuke), as it's expected
|
||||||
if(System.getProperty("user.name").equals("anuke")) return;
|
//if(System.getProperty("user.name").equals("anuke")) return;
|
||||||
|
|
||||||
String header = "--CRASH REPORT--\n";
|
String header = "--CRASH REPORT--\n";
|
||||||
|
|
||||||
@@ -50,6 +50,8 @@ public class CrashHandler{
|
|||||||
|
|
||||||
String filename = "";
|
String filename = "";
|
||||||
|
|
||||||
|
Net.http(Vars.crashReportURL, "POST", result, r -> {}, Throwable::printStackTrace);
|
||||||
|
|
||||||
//try to write it
|
//try to write it
|
||||||
try{
|
try{
|
||||||
filename = "crash-report-" + new SimpleDateFormat("dd-MM-yy h.mm.ss").format(new Date()) + ".txt";
|
filename = "crash-report-" + new SimpleDateFormat("dd-MM-yy h.mm.ss").format(new Date()) + ".txt";
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package io.anuke.mindustry.reporter;
|
||||||
|
|
||||||
|
import static java.lang.System.out;
|
||||||
|
|
||||||
|
public class ReportHandler{
|
||||||
|
|
||||||
|
public void handle(String text){
|
||||||
|
out.println("recieved text: " + text);
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+2
@@ -0,0 +1,2 @@
|
|||||||
|
./gradlew reporter:dist
|
||||||
|
java -jar reporter/build/libs/reporter-release.jar
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
include 'desktop', 'html', 'core', 'android', 'kryonet', 'server', 'ios', 'annotations', 'packer'
|
include 'desktop', 'html', 'core', 'android', 'kryonet', 'server', 'ios', 'annotations', 'packer', 'reporter'
|
||||||
|
|
||||||
if(System.properties["release"] == null || System.properties["release"].equals("false")){
|
if(System.properties["release"] == null || System.properties["release"].equals("false")){
|
||||||
if (new File(settingsDir, '../uCore').exists()) {
|
if (new File(settingsDir, '../uCore').exists()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user