aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sockets.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-07-12 07:23:25 -0700
committerAdam Soltys <[email protected]>2020-07-12 07:23:25 -0700
commit29063c8982442fddc015c7a9fd79feb4ba7c0c47 (patch)
treef5f7f9c207a223c2c01409c4c3e1caf7d49b0100 /lib/sockets.js
parent9cbe98b5c16262f14c06c2b2aaeabed8c42c7231 (diff)
downloadcoinos-server-29063c8982442fddc015c7a9fd79feb4ba7c0c47.tar.gz
coinos-server-29063c8982442fddc015c7a9fd79feb4ba7c0c47.zip
limit socket connections
Diffstat (limited to 'lib/sockets.js')
-rw-r--r--lib/sockets.js5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/sockets.js b/lib/sockets.js
index d4ca336d..d0f00771 100644
--- a/lib/sockets.js
+++ b/lib/sockets.js
@@ -54,6 +54,11 @@ wss.on("connection", function(ws, req) {
try {
const username = jwt.decode(token).username;
if (!sockets[username]) sockets[username] = {};
+ const existing = Object.keys(sockets[username]);
+ if (existing.length > 5) {
+ l.warn("too many sockets, logging out", existing[0]);
+ sockets[username][existing[0]].send(JSON.stringify({ type: "login", data: false }));
+ }
sockets[username][id] = ws;
names[id] = username;