Skip to content

Commit de4a52e

Browse files
committed
Send LINELEN RPL_ISUPPORT and add flag
1 parent f6a773f commit de4a52e

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

bin/irslackd.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const DEFAULT_PORT = 6697;
1010
const DEFAULT_TLS_PKEY = os.homedir() + '/.irslackd/pkey.pem';
1111
const DEFAULT_TLS_CERT = os.homedir() + '/.irslackd/cert.pem';
1212
const DEFAULT_RTM_CLIENT_LOG_LEVEL = 'info';
13+
const DEFAULT_LINE_LEN = 4096;
1314

1415
const opt = require('node-getopt').create([
1516
[ 'h', 'help', 'Show this help' ],
@@ -19,6 +20,7 @@ const opt = require('node-getopt').create([
1920
[ 'c', 'cert=PATH', 'Set TLS cert path (default: ' + DEFAULT_TLS_CERT + ')' ],
2021
[ 'L', 'rtmLogLvl=LEVEL', 'Set RTM Client log level (default: ' + DEFAULT_RTM_CLIENT_LOG_LEVEL + ')' ],
2122
[ 'i', 'insecure', 'Do not use TLS encryption (not recommended)' ],
23+
[ 'l', 'lineLen', 'Set RPL_ISUPPORT LINELEN (default: ' + DEFAULT_LINE_LEN + ')' ],
2224
]).bindHelp().parseSystem();
2325

2426
new irslackd.Irslackd({
@@ -29,4 +31,5 @@ new irslackd.Irslackd({
2931
cert: fs.readFileSync(opt.options.cert || DEFAULT_TLS_CERT),
3032
},
3133
rtmClientLogLevel: opt.options.rtmLogLvl || DEFAULT_RTM_CLIENT_LOG_LEVEL,
34+
lineLen: opt.options.lineLen || DEFAULT_LINE_LEN,
3235
}).listen();

lib/ircd.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ const util = require('util');
66
const EventEmitter = require('events');
77

88
class Ircd extends EventEmitter {
9-
constructor(tlsOpts) {
9+
constructor(config) {
1010
super();
11-
this.tlsOpts = tlsOpts;
11+
this.tlsOpts = config.tlsOpts;
12+
this.lineLen = config.lineLen;
1213
}
1314
listen(port, host) {
1415
const socketFunc = this.onConnect.bind(this);
@@ -62,6 +63,8 @@ class Ircd extends EventEmitter {
6263
console.log('irc_out', line);
6364
line += '\r\n';
6465
if (line.length > 512) {
66+
this.emit('ircError', socket, 'Long line (' + line.length + ' bytes) (clients without LINELEN support may reject): ' + line);
67+
} else if (line.length > this.lineLen) {
6568
this.emit('ircError', socket, 'Long line (' + line.length + ' bytes) (clients may reject): ' + line);
6669
}
6770
return socket.write(line);

lib/irslackd.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Irslackd {
2020
}
2121
listen() {
2222
const self = this;
23-
self.ircd = self.getNewIrcd(self.config.tlsOpts);
23+
self.ircd = self.getNewIrcd(self.config);
2424
const requireInit = true;
2525
const noRequireInit = false;
2626
new Map([
@@ -509,8 +509,13 @@ class Irslackd {
509509
}
510510
}
511511
async onSlackReady(ircUser, event) {
512-
// Send MOTD
512+
// RPL_WELCOME
513513
this.ircd.write(ircUser.socket, 'irslackd', '001', [ ircUser.ircNick, 'irslackd' ]);
514+
515+
// RPL_ISUPPORT
516+
this.ircd.write(ircUser.socket, 'irslackd', '005', [ ircUser.ircNick, 'LINELEN=' + this.config.lineLen, 'are supported by this server' ]);
517+
518+
// RPL_ENDOFMOTD
514519
this.ircd.write(ircUser.socket, 'irslackd', '376', [ ircUser.ircNick, 'End of MOTD' ]);
515520

516521
// set user presence to auto instead of away
@@ -1331,8 +1336,8 @@ class Irslackd {
13311336
await ircUser.slackWeb.apiCallOrThrow('users.setPresence', { presence: status });
13321337
}
13331338
// Dependency injectors
1334-
getNewIrcd(tlsOpts) {
1335-
return new ircd.Ircd(tlsOpts);
1339+
getNewIrcd(config) {
1340+
return new ircd.Ircd(config);
13361341
}
13371342
getNewSlackWebClient(token, cookie = null) {
13381343
const params = cookie ? { headers: { Cookie: cookie }} : {};

tests/mocks.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ async function connectOneIrcClient(t, prefs = []) {
132132
ircSocket.expect(':irslackd 353 test_slack_user = #test_chan_1 :test_slack_user test_slack_user test_slack_fooo test_slack_barr');
133133
ircSocket.expect(':irslackd 366 test_slack_user #test_chan_1 :End of /NAMES list');
134134
ircSocket.expect(':irslackd 001 test_slack_user irslackd');
135+
ircSocket.expect(':irslackd 005 test_slack_user LINELEN=4096 :are supported by this server');
135136
ircSocket.expect(':irslackd 376 test_slack_user :End of MOTD');
136137
};
137138

@@ -143,8 +144,9 @@ async function connectOneIrcClient(t, prefs = []) {
143144
key: 'key',
144145
cert: 'cert',
145146
},
147+
lineLen: 4096,
146148
});
147-
daemon.getNewIrcd = (tlsOpts) => { return new MockIrcd(tlsOpts); };
149+
daemon.getNewIrcd = (config) => { return new MockIrcd(config); };
148150
daemon.getNewSlackRtmClient = (token) => { return new MockSlackRtmClient(t); };
149151
daemon.getNewSlackWebClient = (token) => {
150152
const slackWeb = new MockSlackWebClient(t);
@@ -190,7 +192,7 @@ async function connectOneIrcClient(t, prefs = []) {
190192
end: () => ircSocket.end(),
191193
};
192194
}
193-
connectOneIrcClient.planCount = 21;
195+
connectOneIrcClient.planCount = 22;
194196

195197
exports.MockSlackWebClient = MockSlackWebClient;
196198
exports.MockSlackRtmClient = MockSlackRtmClient;

0 commit comments

Comments
 (0)