Skip to content

Fix player count being incorrect for login - #544

Open
Dueris wants to merge 1 commit into
PaperMC:ver/26.3.xfrom
Dueris:fix/playercount
Open

Dueris wants to merge 1 commit into
PaperMC:ver/26.3.xfrom
Dueris:fix/playercount

Conversation

@Dueris

@Dueris Dueris commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Folia rewrites login and uses the incorrect comparison for the login count, causing the limit set to be offset by -1. Small fix but whatever

@jpenilla

Copy link
Copy Markdown
Member

The off-by-one is real, but the cause is that canPlayerLogin runs twice for the same connection: once at login and again when configuration finishes. The first call adds the connection to usersCountedAgainstLimit, so on the second call it counts against itself.

Changing to > makes the final slot usable, but it lets the limit be exceeded at login. With N already counted, the next player passes the login check (N > N is false), and then gets kicked when configuration finishes (N+1 > N).

The connection shouldn't count against itself on the second check, which matches vanilla, where only fully joined players are counted. Something like this in countConnection (untested), keeping >=:

final boolean counted = this.usersCountedAgainstLimit.contains(conn);
final int count = this.usersCountedAgainstLimit.size() - (counted ? 1 : 0);
if (count >= limit) {
    return false;
}
this.usersCountedAgainstLimit.add(conn);
return true;

R00tB33rMan added a commit to CraftCanvasMC/Canvas that referenced this pull request Nov 19, 2026
canPlayerLogin runs at login and again when configuration finishes for the same connection, so the second check counted the connection against itself. Checking for more than the limit gave the last slot back but let a login exceed it, only to kick the player when configuration finished; the second check now leaves the connection out of the count, as vanilla only counts fully joined players.

Port of PaperMC/Folia#544 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants