Archiviert
1
0

Hotfix antiddos

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2020-03-08 21:58:11 +01:00
Ursprung e58860644c
Commit 63043ee677

Datei anzeigen

@ -4,15 +4,17 @@ import de.steamwar.bungeecore.sql.SWException;
import net.md_5.bungee.api.ProxyServer;
import java.text.MessageFormat;
import java.util.logging.Filter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
public class ErrorLogger extends Handler {
public class ErrorLogger extends Handler implements Filter {
private static ErrorLogger instance;
ErrorLogger(){
ProxyServer.getInstance().getLogger().addHandler(this);
ProxyServer.getInstance().getLogger().setFilter(this);
instance = this;
}
@ -20,6 +22,29 @@ public class ErrorLogger extends Handler {
ProxyServer.getInstance().getLogger().removeHandler(instance);
}
@Override
public boolean isLoggable(LogRecord record) {
if(record.getLevel() != Level.SEVERE)
return true;
StringBuilder stacktrace = new StringBuilder(record.getSourceClassName() + "\n" + record.getSourceMethodName());
Throwable thrown = record.getThrown();
while(thrown != null){
stacktrace.append("\nCaused by ").append(thrown.getMessage());
for(StackTraceElement ste : thrown.getStackTrace())
stacktrace.append("\n").append(ste.toString());
thrown = thrown.getCause();
}
String stacktraceString = stacktrace.toString();
if(stacktraceString.contains("Cannot request protocol")){
return false;
}
return true;
}
@Override
public void publish(LogRecord record) {
if(record.getLevel() != Level.SEVERE)
@ -28,7 +53,7 @@ public class ErrorLogger extends Handler {
StringBuilder stacktrace = new StringBuilder(record.getSourceClassName() + "\n" + record.getSourceMethodName());
Throwable thrown = record.getThrown();
while(thrown != null){
stacktrace.append("\nCaused by").append(thrown.getMessage());
stacktrace.append("\nCaused by ").append(thrown.getMessage());
for(StackTraceElement ste : thrown.getStackTrace())
stacktrace.append("\n").append(ste.toString());
@ -36,7 +61,8 @@ public class ErrorLogger extends Handler {
thrown = thrown.getCause();
}
SWException.log("Bungee", MessageFormat.format(record.getMessage(), record.getParameters()), stacktrace.toString());
String stacktraceString = stacktrace.toString();
SWException.log("Bungee", MessageFormat.format(record.getMessage(), record.getParameters()), stacktraceString);
}
@Override