Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize verification by using different data types #109

Merged
merged 4 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,12 @@ public enum Gamemode {
private int maxBrandLength;
private int maxMovementTicks;
private int maxIgnoredTicks;
private int maxVerifyingPlayers;
private int maxLoginPackets;
private int maxPing;
private int readTimeout;
private int reconnectDelay;
private final Collection<Integer> whitelistedProtocols = new Vector<>(0);
private final Collection<Integer> blacklistedProtocols = new Vector<>(0);
private final Collection<Integer> whitelistedProtocols = new HashSet<>(0);
private final Collection<Integer> blacklistedProtocols = new HashSet<>(0);

private Component tooManyPlayers;
private Component tooFastReconnect;
Expand Down Expand Up @@ -480,11 +479,6 @@ public void load() {
"Amount of time that has to pass before a player times out");
verification.readTimeout = clamp(generalConfig.getInt("verification.read-timeout", 3500), 500, 30000);

generalConfig.getYaml().setComment("verification.max-players",
"Maximum number of players verifying at the same time");
verification.maxVerifyingPlayers = clamp(generalConfig.getInt("verification.max-players", 1024), 1,
Short.MAX_VALUE);

generalConfig.getYaml().setComment("verification.rejoin-delay",
"Minimum number of rejoin delay during verification");
verification.reconnectDelay = clamp(generalConfig.getInt("verification.rejoin-delay", 8000), 0, 100000);
Expand All @@ -495,12 +489,12 @@ public void load() {
+ LINE_SEPARATOR + "https://wiki.vg/Protocol_version_numbers"
+ LINE_SEPARATOR + "For example, Minecraft 1.20 has the ID 763.");
verification.whitelistedProtocols.clear();
verification.whitelistedProtocols.addAll(generalConfig.getIntList("verification.whitelisted-protocols", Collections.emptyList()));
verification.whitelistedProtocols.addAll(generalConfig.getIntList("verification.whitelisted-protocols", new ArrayList<>(0)));

generalConfig.getYaml().setComment("verification.blacklisted-protocols",
"List of protocol IDs which are unable to join the server at all");
verification.blacklistedProtocols.clear();
verification.blacklistedProtocols.addAll(generalConfig.getIntList("verification.blacklisted-protocols", Collections.emptyList()));
verification.blacklistedProtocols.addAll(generalConfig.getIntList("verification.blacklisted-protocols", new ArrayList<>(0)));

generalConfig.getYaml().setComment("webhook",
"Bot attack notifications can also be sent to your Discord server using webhooks");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ public final class Fallback {
public static final Fallback INSTANCE = new Fallback();
private static final @NotNull Sonar SONAR = Objects.requireNonNull(Sonar.get());

private final Map<String, InetAddress> connected = new ConcurrentHashMap<>();
private final Map<String, InetAddress> connected = new ConcurrentHashMap<>(64, 0.75f);
// Only block the player for a few minutes to avoid issues
private final ExpiringCache<InetAddress> blacklisted = Cappuccino.buildExpiring(
10L, TimeUnit.MINUTES, 5000L
);
10L, TimeUnit.MINUTES, 5000L);
private final @NotNull FallbackQueue queue = FallbackQueue.INSTANCE;
private final @NotNull FallbackRatelimiter ratelimiter = FallbackRatelimiter.INSTANCE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,6 @@ public void handle(final LoginRequest loginRequest) throws Exception {
return;
}

// We cannot allow too many players on our Fallback server
// There's technically no reason for limiting this, but we'll better stay safe.
if (FALLBACK.getConnected().size() > Sonar.get().getConfig().getVerification().getMaxVerifyingPlayers()) {
closeWith(getKickPacket(Sonar.get().getConfig().getVerification().getTooManyPlayers()));
return;
}

// Check if the IP address is currently being rate-limited
if (!FALLBACK.getRatelimiter().attempt(inetAddress)) {
closeWith(getKickPacket(Sonar.get().getConfig().getVerification().getTooFastReconnect()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,6 @@ public void handle(final @NotNull PreLoginEvent event) throws Throwable {
return;
}

// We cannot allow too many players on our Fallback server
// There's technically no reason for limiting this, but we'll better stay safe.
if (fallback.getConnected().size() > Sonar.get().getConfig().getVerification().getMaxVerifyingPlayers()) {
initialConnection.getConnection().closeWith(Disconnect.create(
Sonar.get().getConfig().getVerification().getTooManyPlayers(),
inboundConnection.getProtocolVersion()
));
return;
}

// Check if the IP address is currently being rate-limited
if (!fallback.getRatelimiter().attempt(inetAddress)) {
initialConnection.getConnection().closeWith(Disconnect.create(
Expand Down