geforkt von SteamWar/BungeeCore
Merge branch 'master' into nodeSystem
# Conflicts: # src/de/steamwar/bungeecore/BungeeCore.java
Dieser Commit ist enthalten in:
Commit
563a5f45f6
@ -165,7 +165,6 @@ public class BungeeCore extends Plugin {
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
ErrorLogger.stop();
|
||||
Statement.close();
|
||||
}
|
||||
|
||||
|
@ -20,83 +20,47 @@
|
||||
package de.steamwar.bungeecore;
|
||||
|
||||
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.util.logging.Filter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ErrorLogger extends Handler implements Filter {
|
||||
private static ErrorLogger instance;
|
||||
public class ErrorLogger extends Handler {
|
||||
private int ddosRate = 0;
|
||||
|
||||
ErrorLogger(){
|
||||
ProxyServer.getInstance().getLogger().addHandler(this);
|
||||
ProxyServer.getInstance().getLogger().setFilter(this);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
static void stop(){
|
||||
ProxyServer.getInstance().getLogger().removeHandler(instance);
|
||||
Logger.getLogger("").addHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoggable(LogRecord record) {
|
||||
if(record.getLevel() != Level.SEVERE)
|
||||
return true;
|
||||
public void publish(LogRecord logRecord) {
|
||||
if(logRecord.getLevel().intValue() < Level.WARNING.intValue())
|
||||
return;
|
||||
|
||||
StringBuilder stacktrace = new StringBuilder(record.getSourceClassName() + "\n" + record.getSourceMethodName());
|
||||
Throwable thrown = record.getThrown();
|
||||
while(thrown != null){
|
||||
stacktrace.append("\nCaused by ").append(thrown.getMessage());
|
||||
String message = MessageFormat.format(logRecord.getMessage(), logRecord.getParameters());
|
||||
for(String reason : ignoreContains)
|
||||
if(message.contains(reason))
|
||||
return;
|
||||
|
||||
for(StackTraceElement ste : thrown.getStackTrace())
|
||||
stacktrace.append("\n").append(ste.toString());
|
||||
|
||||
thrown = thrown.getCause();
|
||||
}
|
||||
|
||||
String stacktraceString = stacktrace.toString();
|
||||
if(stacktraceString.contains("Cannot request protocol")){
|
||||
ddosRate++;
|
||||
if(ddosRate % 1000 == 0){
|
||||
ByteArrayOutputStream stacktraceOutput = new ByteArrayOutputStream();
|
||||
if(logRecord.getThrown() != null)
|
||||
logRecord.getThrown().printStackTrace(new PrintStream(stacktraceOutput));
|
||||
String stacktrace = stacktraceOutput.toString();
|
||||
if(stacktrace.contains("Cannot request protocol")) {
|
||||
if(++ddosRate % 1000 == 0) {
|
||||
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;
|
||||
|
||||
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();
|
||||
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);
|
||||
SWException.log("Bungee", message, stacktrace);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -108,4 +72,17 @@ public class ErrorLogger extends Handler implements Filter {
|
||||
public void close() {
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren