Skip to content

Feature/pix 58 validate user join#49

Merged
matteosusca merged 6 commits into
developfrom
feature/PIX-58_validate-user-join
Jan 29, 2026
Merged

Feature/pix 58 validate user join#49
matteosusca merged 6 commits into
developfrom
feature/PIX-58_validate-user-join

Conversation

@matteosusca
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds centralized Socket.IO lobby utilities and introduces server-side validation when a user joins a lobby (banned/capacity), while simplifying draw/batch-draw socket handlers.

Changes:

  • Added reusable Socket.IO helpers for lobby user count, user listing, and broadcasting.
  • Validated lobby join attempts against banned users and lobby capacity before completing the join flow.
  • Refactored draw/batch-draw handling to use CanvasService.drawBatch and shared broadcast helpers.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
server/src/utils/socketUtils.ts Introduces shared Socket.IO room helpers (counts, user listing, broadcast wrappers).
server/src/sockets/index.ts Uses new helpers; adds join validation and refactors draw/draw_batch event logic.
server/src/services/lobby.service.ts Adds reusable validation methods for join access and lobby capacity.
server/src/services/canvas.service.ts Adds drawBatch to process and persist multiple pixel updates efficiently.
server/src/middlewares/permissionMiddleware.ts Reuses lobby access validation from LobbyService (but leaves an unused import).
client/src/views/PlayView.vue Moves onUnmounted import to the top-level import section.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/src/middlewares/permissionMiddleware.ts Outdated
Comment thread server/src/sockets/index.ts Outdated
Comment on lines +38 to +46
socket.join(lobbyName); // Optimistic Join

// 3. Send list of connected users to the new user
// We fetch sockets AFTER joining so the user is included in the list
const sockets = await io.in(lobbyName).fetchSockets();
const users = sockets.map(s => s.data.user).filter(u => u);
socket.emit(CONFIG.EVENTS.SERVER.LOBBY_USERS, users);
const currentCount = getLobbyUserCount(io, lobbyName);
try {
LobbyService.validateCapacity(lobby, currentCount - 1);
} catch (e: any) {
socket.leave(lobbyName);
return socket.emit(CONFIG.EVENTS.SERVER.ERROR, { message: "Lobby is full" });
}
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capacity validation uses currentCount - 1 after an optimistic socket.join(), which makes the intent (checking count before vs after the join) hard to follow and easy to get wrong later. Consider computing a clearly named countBeforeJoin (or validating using the post-join count and checking > maxCollaborators) to make the off-by-one behavior explicit.

Copilot uses AI. Check for mistakes.
Comment thread server/src/services/canvas.service.ts Outdated
Comment thread server/src/services/lobby.service.ts Outdated
matteosusca and others added 4 commits January 29, 2026 15:27
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@matteosusca matteosusca merged commit 0faaa7f into develop Jan 29, 2026
@matteosusca matteosusca deleted the feature/PIX-58_validate-user-join branch February 1, 2026 11:58
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