diff options
| author | Adam Soltys <[email protected]> | 2020-07-12 07:23:25 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-07-12 07:23:25 -0700 |
| commit | 29063c8982442fddc015c7a9fd79feb4ba7c0c47 (patch) | |
| tree | f5f7f9c207a223c2c01409c4c3e1caf7d49b0100 | |
| parent | 9cbe98b5c16262f14c06c2b2aaeabed8c42c7231 (diff) | |
| download | coinos-server-29063c8982442fddc015c7a9fd79feb4ba7c0c47.tar.gz coinos-server-29063c8982442fddc015c7a9fd79feb4ba7c0c47.zip | |
limit socket connections
| -rw-r--r-- | lib/sockets.js | 5 |
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; |
