@@ -21,6 +21,7 @@ import * as logging from "../logging";
2121import Bluebird from "bluebird" ;
2222import { Defer } from "../promiseutil" ;
2323import { IrcServer } from "./IrcServer" ;
24+ import { getBridgeVersion } from "matrix-appservice-bridge" ;
2425
2526const log = logging . get ( "client-connection" ) ;
2627
@@ -42,7 +43,8 @@ const FLOOD_PROTECTION_DELAY_MS = 700;
4243const THROTTLE_WAIT_MS = 20 * 1000 ;
4344
4445// String reply of any CTCP Version requests
45- const CTCP_VERSION = 'matrix-appservice-irc, part of the Matrix.org Network' ;
46+ const CTCP_VERSION =
47+ ( homeserverName : string ) => `matrix-appservice-irc ${ getBridgeVersion ( ) } bridged via ${ homeserverName } ` ;
4648
4749const CONN_LIMIT_MESSAGES = [
4850 "too many host connections" , // ircd-seven
@@ -83,18 +85,20 @@ export class ConnectionInstance {
8385 private connectDefer : Defer < ConnectionInstance > ;
8486 public onDisconnect ?: ( reason : string ) => void ;
8587 /**
86- * Create an IRC connection instance. Wraps the node -irc library to handle
88+ * Create an IRC connection instance. Wraps the matrix-org -irc library to handle
8789 * connections correctly.
8890 * @constructor
89- * @param {IrcClient } ircClient The new IRC client.
90- * @param {string } domain The domain (for logging purposes)
91- * @param {string } nick The nick (for logging purposes)
91+ * @param client The new IRC client.
92+ * @param domain The domain (for logging purposes)
93+ * @param nick The nick (for logging purposes)
94+ * @param pingOpts Options for automatic pings to the IRCd.
95+ * @param homeserverDomain The homeserver's domain, for the CTCP version string.
9296 */
9397 constructor ( public readonly client : Client , private readonly domain : string , private nick : string ,
9498 private pingOpts : {
9599 pingRateMs : number ;
96100 pingTimeoutMs : number ;
97- } ) {
101+ } , private readonly homeserverDomain : string ) {
98102 this . listenForErrors ( ) ;
99103 this . listenForPings ( ) ;
100104 this . listenForCTCPVersions ( ) ;
@@ -329,7 +333,7 @@ export class ConnectionInstance {
329333 private listenForCTCPVersions ( ) {
330334 this . client . addListener ( "ctcp-version" , ( from : string ) => {
331335 if ( from ) { // Ensure the sender is valid before we try to respond
332- this . client . ctcp ( from , 'reply' , `VERSION ${ CTCP_VERSION } ` ) ;
336+ this . client . ctcp ( from , 'reply' , `VERSION ${ CTCP_VERSION ( this . homeserverDomain ) } ` ) ;
333337 }
334338 } ) ;
335339 }
@@ -359,10 +363,13 @@ export class ConnectionInstance {
359363 * @param {string } opts.realname The real name of the user.
360364 * @param {string } opts.password The password to give NickServ.
361365 * @param {string } opts.localAddress The local address to bind to when connecting.
366+ * @param {string } homeserverDomain Domain of the homeserver bridging requests.
362367 * @param {Function } onCreatedCallback Called with the client when created.
363368 * @return {Promise } Resolves to an ConnectionInstance or rejects.
364369 */
365- public static async create ( server : IrcServer , opts : ConnectionOpts ,
370+ public static async create ( server : IrcServer ,
371+ opts : ConnectionOpts ,
372+ homeserverDomain : string ,
366373 onCreatedCallback ?: ( inst : ConnectionInstance ) => void ) : Promise < ConnectionInstance > {
367374 if ( ! opts . nick || ! server ) {
368375 throw new Error ( "Bad inputs. Nick: " + opts . nick ) ;
@@ -396,7 +403,8 @@ export class ConnectionInstance {
396403 nodeClient , server . domain , opts . nick , {
397404 pingRateMs : server . pingRateMs ,
398405 pingTimeoutMs : server . pingTimeout ,
399- }
406+ } ,
407+ homeserverDomain ,
400408 ) ;
401409 if ( onCreatedCallback ) {
402410 onCreatedCallback ( inst ) ;
0 commit comments