Add a setting for enabling a hard player cap

This commit is contained in:
rtm516 2023-04-28 13:29:18 +01:00
parent b0698284b3
commit 56b9fe7619
No known key found for this signature in database
GPG key ID: 331715B8B007C67A
3 changed files with 15 additions and 2 deletions

View file

@ -75,8 +75,16 @@ public class PacketHandler extends UpstreamPacketHandler {
public PacketSignal handle(SetLocalPlayerAsInitializedPacket packet) { public PacketSignal handle(SetLocalPlayerAsInitializedPacket packet) {
geyserConnect.logger().debug("Player initialized: " + Utils.displayName(session)); geyserConnect.logger().debug("Player initialized: " + Utils.displayName(session));
// Check to see if the server is full and we have a hard player cap
if (geyserConnect.config().hardPlayerLimit()) {
if (session.getGeyser().getSessionManager().size() > session.getGeyser().getConfig().getMaxPlayers()) {
session.disconnect("disconnectionScreen.serverFull");
return PacketSignal.HANDLED;
}
}
// Handle the virtual host if specified // Handle the virtual host if specified
VirtualHostSection vhost = GeyserConnect.instance().config().vhost(); VirtualHostSection vhost = geyserConnect.config().vhost();
if (vhost.enabled()) { if (vhost.enabled()) {
String domain = session.getClientData().getServerAddress().split(":")[0]; String domain = session.getClientData().getServerAddress().split(":")[0];
if (!domain.equals(vhost.baseDomain()) && domain.endsWith("." + vhost.baseDomain())) { if (!domain.equals(vhost.baseDomain()) && domain.endsWith("." + vhost.baseDomain())) {
@ -104,7 +112,7 @@ public class PacketHandler extends UpstreamPacketHandler {
} }
// Log the virtual host usage // Log the virtual host usage
GeyserConnect.instance().logger().info(Utils.displayName(session) + " is using virtualhost: " + address + ":" + port + (!online ? " (offline)" : "")); geyserConnect.logger().info(Utils.displayName(session) + " is using virtualhost: " + address + ":" + port + (!online ? " (offline)" : ""));
// Send the player to the wanted server // Send the player to the wanted server
Utils.sendToServer(session, originalPacketHandler, new Server(address, port, online, false, null, null, null)); Utils.sendToServer(session, originalPacketHandler, new Server(address, port, online, false, null, null, null));

View file

@ -32,6 +32,7 @@ import java.util.List;
public record Config( public record Config(
@JsonProperty("welcome-file") String welcomeFile, @JsonProperty("welcome-file") String welcomeFile,
@JsonProperty("hard-player-limit") boolean hardPlayerLimit,
List<Server> servers, List<Server> servers,
@JsonProperty("custom-servers") CustomServersSection customServers, @JsonProperty("custom-servers") CustomServersSection customServers,
VirtualHostSection vhost) { VirtualHostSection vhost) {

View file

@ -6,6 +6,10 @@
# This is loaded live so will update without a server restart # This is loaded live so will update without a server restart
welcome-file: welcome.txt welcome-file: welcome.txt
# Enabled hard max player limit
# This will kick players if the server is full
hard-player-limit: false
# A global list of servers sent to all clients # A global list of servers sent to all clients
servers: servers:
- name: The Hive - name: The Hive