Log spam of logins to determine if that is the attack vector

This commit is contained in:
AlexTheCoder 2017-11-25 00:01:20 -05:00 committed by Alexander Meech
parent d1f81d8154
commit 1380ef8e33

View File

@ -17,6 +17,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -29,6 +30,8 @@ import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
@ -94,6 +97,8 @@ public class CoreClientManager extends MiniPlugin
private static AtomicInteger _clientsProcessing = new AtomicInteger(0);
private final Set<UUID> _reservedSlots = Sets.newConcurrentHashSet();
private final Cache<UUID, Integer> _loginCounter = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.SECONDS).build();
public CoreClientManager(JavaPlugin plugin)
{
@ -227,6 +232,14 @@ public class CoreClientManager extends MiniPlugin
@EventHandler(priority = EventPriority.LOWEST)
public void AsyncLogin(AsyncPlayerPreLoginEvent event)
{
Integer newValueCache = _loginCounter.getIfPresent(event.getUniqueId());
if (newValueCache == null)
{
newValueCache = 0;
}
_loginCounter.put(event.getUniqueId(), newValueCache + 1);
System.out.println("CLIENT LOGIN TOTALS IN PAST 5 SECONDS: " + _loginCounter.asMap().values().stream().reduce(0, Integer::sum));
try
{
_clientsConnecting.incrementAndGet();