Skip to content

Limit multiplayer WebSocket connections per IP address#456

Merged
geoffrey-wu merged 2 commits intomainfrom
copilot/add-ip-connection-limit
Mar 8, 2026
Merged

Limit multiplayer WebSocket connections per IP address#456
geoffrey-wu merged 2 commits intomainfrom
copilot/add-ip-connection-limit

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

A single IP could open unlimited concurrent multiplayer WebSocket connections, enabling resource exhaustion or abuse.

Changes

  • server/multiplayer/constants.js: Added MAX_CONNECTIONS_PER_IP = 50
  • server/multiplayer/handle-wss-connection.js: Added a module-level connectionsByIp Map; rejects new connections from IPs at or above the limit with an error message; decrements the counter on close
const ipConnections = connectionsByIp.get(ip) ?? 0;
if (ipConnections >= MAX_CONNECTIONS_PER_IP) {
  ws.send(JSON.stringify({
    type: 'error',
    message: `Too many connections from your IP address. The limit is ${MAX_CONNECTIONS_PER_IP}.`
  }));
  return false;
}

connectionsByIp.set(ip, ipConnections + 1);
ws.on('close', () => {
  const current = connectionsByIp.get(ip) ?? 0;
  if (current <= 1) { connectionsByIp.delete(ip); }
  else { connectionsByIp.set(ip, current - 1); }
});
Original prompt

This section details on the original issue you should resolve

<issue_title>Add a limit to the number of multiplayer connections that can come from a single IP address</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: geoffrey-wu <42471355+geoffrey-wu@users.noreply.github.com>
Copilot AI changed the title [WIP] Add limit to multiplayer connections from single IP address Limit multiplayer WebSocket connections per IP address Mar 1, 2026
@geoffrey-wu geoffrey-wu marked this pull request as ready for review March 8, 2026 21:04
@geoffrey-wu geoffrey-wu merged commit 4a595db into main Mar 8, 2026
@geoffrey-wu geoffrey-wu deleted the copilot/add-ip-connection-limit branch March 8, 2026 21:04
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.

Add a limit to the number of multiplayer connections that can come from a single IP address

2 participants