Skip to content

Fix invite join being blocked for password-protected rooms#142

Open
nadav78 wants to merge 3 commits intoSoWeBegin:toybattles_mvsurgefrom
nadav78:fix/invite-join-password-rooms
Open

Fix invite join being blocked for password-protected rooms#142
nadav78 wants to merge 3 commits intoSoWeBegin:toybattles_mvsurgefrom
nadav78:fix/invite-join-password-rooms

Conversation

@nadav78
Copy link

@nadav78 nadav78 commented Mar 17, 2026

Fixes #113.

Root cause

The fix for #102 added a check that rejects room joins when no password is submitted (getDataSize() != 20). When a client accepts an invite, it sends only the room number (not a 20-byte packet with a password), so hasInputtedPassword was false and the join was rejected with JOIN_INVALID_PASSWORD — even though the server had already authorized the player via the invite.

Fix

Track pending invites on the Room object using an unordered_set<uint32_t>. When an invite is sent, the invitee's account ID is added to the set. The password check in RoomJoinHandler skips players with a pending invite, and the entry is cleared once they successfully join.

The #102 fix remains fully intact for non-invited players.

nadav78 and others added 3 commits March 17, 2026 13:44
The SoWeBegin#102 fix added a check blocking joins when no password was submitted
(getDataSize() != 20). Clients accepting an invite send only the room
number (not 20 bytes), so they were incorrectly rejected with
JOIN_INVALID_PASSWORD even though the server already authorized them
via the invite.

Fix: track pending invites on the Room object. When an invite is sent,
the invitee's account ID is added to a pending set. The password check
skips players in that set, and the entry is cleared once they join.

Closes SoWeBegin#113

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… rooms

When a player's TCP connection dropped mid-game, removeSession only erased
them from the sessions map but left their weak_ptr in the room's m_playersVec.
On reconnect (common after a wrong-password delay within the 10s heartbeat
window), the new session joined alongside the ghost. Position broadcasts went
to both. The ghost's still-open TCP socket caused ASIO completion handler
backlog on the event loop, delaying pong (order 72) responses — high ping
while alive, recovering while dead.

Fixes:
- CastServer SessionsManager::removeSession now calls removePlayerFromRoom so
  players are evicted from rooms immediately on disconnect
- Room::addPlayer lambda also removes expired weak_ptrs (was returning false
  for them, causing stale entries to accumulate forever)
- Session::setSessionId releases the old pool ID before setting the new one,
  preventing CastServer session ID pool exhaustion after 500 connections
- Session destructor no longer calls releaseSessionID explicitly; closeSocket
  already handles this (was a triple-release)
- Removed static from PlayerPositionHandler response packet; std::move on a
  static left it in moved-from state on every subsequent call

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Invites to rooms with password dont work

1 participant