mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-12-21 15:59:32 +00:00
Introduce limit for the maximum number of connected clients per address
This commit is contained in:
@@ -89,6 +89,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class UpstreamPacketHandler extends LoggingPacketHandler {
|
public class UpstreamPacketHandler extends LoggingPacketHandler {
|
||||||
|
|
||||||
private boolean networkSettingsRequested = false;
|
private boolean networkSettingsRequested = false;
|
||||||
|
private boolean receivedLoginPacket = false;
|
||||||
private final Deque<String> packsToSend = new ArrayDeque<>();
|
private final Deque<String> packsToSend = new ArrayDeque<>();
|
||||||
private final CompressionStrategy compressionStrategy;
|
private final CompressionStrategy compressionStrategy;
|
||||||
|
|
||||||
@@ -188,11 +189,23 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
|
|||||||
return PacketSignal.HANDLED;
|
return PacketSignal.HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (receivedLoginPacket) {
|
||||||
|
GeyserImpl.getInstance().getLogger().warning("Received duplicate login packet from " + session.name());
|
||||||
|
session.disconnect("Received duplicate login packet!");
|
||||||
|
return PacketSignal.HANDLED;
|
||||||
|
}
|
||||||
|
receivedLoginPacket = true;
|
||||||
|
|
||||||
if (!networkSettingsRequested) {
|
if (!networkSettingsRequested) {
|
||||||
session.disconnect(GeyserLocale.getLocaleStringLog("geyser.network.outdated.client", GameProtocol.getAllSupportedBedrockVersions()));
|
session.disconnect(GeyserLocale.getLocaleStringLog("geyser.network.outdated.client", GameProtocol.getAllSupportedBedrockVersions()));
|
||||||
return PacketSignal.HANDLED;
|
return PacketSignal.HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!geyser.getSessionManager().addPendingSession(session)) {
|
||||||
|
session.disconnect("Too many connections are originating from this location!");
|
||||||
|
return PacketSignal.HANDLED;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the block translation based off of version
|
// Set the block translation based off of version
|
||||||
session.setBlockMappings(BlockRegistries.BLOCKS.forVersion(loginPacket.getProtocolVersion()));
|
session.setBlockMappings(BlockRegistries.BLOCKS.forVersion(loginPacket.getProtocolVersion()));
|
||||||
session.setItemMappings(Registries.ITEMS.forVersion(loginPacket.getProtocolVersion()));
|
session.setItemMappings(Registries.ITEMS.forVersion(loginPacket.getProtocolVersion()));
|
||||||
@@ -204,6 +217,11 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
|
|||||||
return PacketSignal.HANDLED;
|
return PacketSignal.HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GeyserImpl.getInstance().connectionByXuid(session.xuid()) != null) {
|
||||||
|
session.disconnect(GeyserLocale.getLocaleStringLog("geyser.auth.already_loggedin", session.name()));
|
||||||
|
return PacketSignal.HANDLED;
|
||||||
|
}
|
||||||
|
|
||||||
// Fire SessionInitializeEvent here as we now know the client data
|
// Fire SessionInitializeEvent here as we now know the client data
|
||||||
geyser.eventBus().fire(new SessionInitializeEvent(session));
|
geyser.eventBus().fire(new SessionInitializeEvent(session));
|
||||||
|
|
||||||
@@ -211,8 +229,6 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
|
|||||||
playStatus.setStatus(PlayStatusPacket.Status.LOGIN_SUCCESS);
|
playStatus.setStatus(PlayStatusPacket.Status.LOGIN_SUCCESS);
|
||||||
session.sendUpstreamPacket(playStatus);
|
session.sendUpstreamPacket(playStatus);
|
||||||
|
|
||||||
geyser.getSessionManager().addPendingSession(session);
|
|
||||||
|
|
||||||
this.resourcePackLoadEvent = new SessionLoadResourcePacksEventImpl(session);
|
this.resourcePackLoadEvent = new SessionLoadResourcePacksEventImpl(session);
|
||||||
this.geyser.eventBus().fire(this.resourcePackLoadEvent);
|
this.geyser.eventBus().fire(this.resourcePackLoadEvent);
|
||||||
|
|
||||||
|
|||||||
@@ -61,10 +61,19 @@ public final class SessionManager {
|
|||||||
@Getter(AccessLevel.PACKAGE)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private final Map<InetAddress, AtomicInteger> connectedClients = new ConcurrentHashMap<>();
|
private final Map<InetAddress, AtomicInteger> connectedClients = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the maximum amount of connections per address
|
||||||
|
*/
|
||||||
|
private final static int MAX_CONNECTIONS_PER_ADDRESS = Integer.getInteger("Geyser.MaxConnectionsPerAddress", 10);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called once the player has successfully authenticated to the Geyser server.
|
* Called once the player has successfully authenticated to the Geyser server.
|
||||||
*/
|
*/
|
||||||
public void addPendingSession(GeyserSession session) {
|
public boolean addPendingSession(GeyserSession session) {
|
||||||
|
if (getAddressMultiplier(session.getSocketAddress().getAddress()) > MAX_CONNECTIONS_PER_ADDRESS) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
pendingSessions.add(session);
|
pendingSessions.add(session);
|
||||||
connectedClients.compute(session.getSocketAddress().getAddress(), (key, count) -> {
|
connectedClients.compute(session.getSocketAddress().getAddress(), (key, count) -> {
|
||||||
if (count == null) {
|
if (count == null) {
|
||||||
@@ -74,6 +83,8 @@ public final class SessionManager {
|
|||||||
count.incrementAndGet();
|
count.incrementAndGet();
|
||||||
return count;
|
return count;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user