Skip to content

Commit 99210c8

Browse files
authored
Merge pull request #604 from viztheman/config-max-connections
Add New "maxConnections" Config Option
2 parents d6e40f1 + f0a0e8a commit 99210c8

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

core/config_default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = () => {
1515

1616
menuFile: 'menu.hjson', // 'oputil.js config new' will set this appropriately in config.hjson; may be full path
1717
achievementFile: 'achievements.hjson',
18+
maxConnections: 0 // 0 or less means 'unlimited'
1819
},
1920

2021
term: {

core/login_server_module.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ module.exports = class LoginServerModule extends ServerModule {
1717
super();
1818
}
1919

20-
// :TODO: we need to max connections -- e.g. from config 'maxConnections'
21-
2220
prepareClient(client, cb) {
2321
if (client.user.isAuthenticated()) {
2422
return cb(null);
@@ -41,6 +39,9 @@ module.exports = class LoginServerModule extends ServerModule {
4139
}
4240

4341
handleNewClient(client, clientSock, modInfo) {
42+
const maxConnections = _.get(Config(), 'general.maxConnections');
43+
const numConnections = clientConns.clientConnections.length;
44+
4445
clientSock.on('error', err => {
4546
logger.log.warn({ modInfo, error: err.message }, 'Client socket error');
4647
});
@@ -54,6 +55,13 @@ module.exports = class LoginServerModule extends ServerModule {
5455
}
5556

5657
client.rawSocket = clientSock;
58+
59+
if (maxConnections > 0 && numConnections >= maxConnections) {
60+
client.term.write('\nAll nodes are busy. Try again later...\n');
61+
client.end();
62+
return;
63+
}
64+
5765
client.session.serverName = modInfo.name;
5866
client.session.isSecure = _.isBoolean(client.isSecure)
5967
? client.isSecure

misc/config_template.in.hjson

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565

6666
// Short board description
6767
description : 'Yet another awesome ENiGMA½ BBS'
68+
69+
// Max active nodes (0 = unlimited)
70+
maxConnections : 0
6871
}
6972

7073
term: {

0 commit comments

Comments
 (0)