Archiviert
1
0

Merge branch 'master' into nodeSystem

# Conflicts:
#	src/de/steamwar/bungeecore/BungeeCore.java
Dieser Commit ist enthalten in:
Lixfel 2021-09-17 07:47:22 +02:00
Commit 563a5f45f6
2 geänderte Dateien mit 35 neuen und 59 gelöschten Zeilen

Datei anzeigen

@ -165,7 +165,6 @@ public class BungeeCore extends Plugin {
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
ErrorLogger.stop();
Statement.close(); Statement.close();
} }

Datei anzeigen

@ -20,83 +20,47 @@
package de.steamwar.bungeecore; package de.steamwar.bungeecore;
import de.steamwar.bungeecore.sql.SWException; import de.steamwar.bungeecore.sql.SWException;
import net.md_5.bungee.api.ProxyServer;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.logging.Filter; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Handler; import java.util.logging.Handler;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class ErrorLogger extends Handler implements Filter { public class ErrorLogger extends Handler {
private static ErrorLogger instance;
private int ddosRate = 0; private int ddosRate = 0;
ErrorLogger(){ ErrorLogger(){
ProxyServer.getInstance().getLogger().addHandler(this); Logger.getLogger("").addHandler(this);
ProxyServer.getInstance().getLogger().setFilter(this);
instance = this;
}
static void stop(){
ProxyServer.getInstance().getLogger().removeHandler(instance);
} }
@Override @Override
public boolean isLoggable(LogRecord record) { public void publish(LogRecord logRecord) {
if(record.getLevel() != Level.SEVERE) if(logRecord.getLevel().intValue() < Level.WARNING.intValue())
return true; return;
StringBuilder stacktrace = new StringBuilder(record.getSourceClassName() + "\n" + record.getSourceMethodName()); String message = MessageFormat.format(logRecord.getMessage(), logRecord.getParameters());
Throwable thrown = record.getThrown(); for(String reason : ignoreContains)
while(thrown != null){ if(message.contains(reason))
stacktrace.append("\nCaused by ").append(thrown.getMessage()); return;
for(StackTraceElement ste : thrown.getStackTrace()) ByteArrayOutputStream stacktraceOutput = new ByteArrayOutputStream();
stacktrace.append("\n").append(ste.toString()); if(logRecord.getThrown() != null)
logRecord.getThrown().printStackTrace(new PrintStream(stacktraceOutput));
thrown = thrown.getCause(); String stacktrace = stacktraceOutput.toString();
} if(stacktrace.contains("Cannot request protocol")) {
if(++ddosRate % 1000 == 0) {
String stacktraceString = stacktrace.toString();
if(stacktraceString.contains("Cannot request protocol")){
ddosRate++;
if(ddosRate % 1000 == 0){
SWException.log("Bungee", "DDOS", ddosRate + ""); SWException.log("Bungee", "DDOS", ddosRate + "");
} }
return false;
}
return true;
}
@Override
public void publish(LogRecord record) {
if(record.getLevel() != Level.SEVERE && record.getLevel() != Level.WARNING)
return; return;
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(); SWException.log("Bungee", message, stacktrace);
String message = MessageFormat.format(record.getMessage(), record.getParameters());
if(message.contains("ServerConnector")
|| message.contains("InitialHandler")
|| message.contains("UpstreamBridge")
|| message.contains("DownstreamBridge")
|| message.contains(" took ")
|| message.contains("No client connected for pending server!"))
return;
SWException.log("Bungee", message, stacktraceString);
} }
@Override @Override
@ -108,4 +72,17 @@ public class ErrorLogger extends Handler implements Filter {
public void close() { public void close() {
//ignored //ignored
} }
private static final List<String> ignoreContains;
static {
List<String> contains = new ArrayList<>();
contains.add("ServerConnector");
contains.add("InitialHandler");
contains.add("UpstreamBridge");
contains.add("DownstreamBridge");
contains.add(" took ");
contains.add("No client connected for pending server!");
ignoreContains = Collections.unmodifiableList(contains);
}
} }