Skip to content

Commit 5498def

Browse files
feat: enhance security
1 parent a719b8b commit 5498def

File tree

3 files changed

+164
-166
lines changed

3 files changed

+164
-166
lines changed

.env.example

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Server Configuration
21
PORT=3000
3-
4-
# Admin password for display/control page
5-
ADMIN_PASSWORD=admin123
2+
ADMIN_PASSWORD=change_me_before_deploy
3+
ALLOWED_ORIGIN=*

public/display.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,10 @@
204204
};
205205

206206
const calculateBallParams = () => {
207-
const totalBalls = Math.floor((window.innerWidth * window.innerHeight) / ballSize / ballSize);
208-
return { radius: ballSize, count: totalBalls };
207+
// Hexagonal packing efficiency ~0.9065, use 0.85 for comfort margin
208+
const r = ballSize;
209+
const maxBalls = Math.floor(((window.innerWidth * window.innerHeight) / (Math.PI * r * r)) * 0.85);
210+
return { radius: r, count: maxBalls };
209211
};
210212

211213
// Socket events
@@ -214,6 +216,10 @@
214216
});
215217

216218
socket.on("ball:add", data => {
219+
// Enforce ball cap — ignore if screen is full
220+
const { count: maxBalls } = calculateBallParams();
221+
if (balls.length >= maxBalls) return;
222+
217223
const x = Math.random() * (window.innerWidth - 200) + 100;
218224
const y = -50;
219225
const radius = ballSize;

0 commit comments

Comments
 (0)