-var util = require('util'),
- IrcConnection = require('./connection.js');
+var util = require('util'),
+ events = require('events'),
+ _ = require('lodash'),
+ IrcConnection = require('./connection.js').IrcConnection;
var State = function (client, save_state) {
+ var that = this;
+
events.EventEmitter.call(this);
this.client = client;
this.save_state = save_state || false;
this.irc_connections = [];
this.next_connection = 0;
- this.client.on('disconnect', function () {
- if (!this.save_state) {
- _.each(this.irc_connections, function (irc_connection, i, cons) {
+ this.client.on('dispose', function () {
+ if (!that.save_state) {
+ _.each(that.irc_connections, function (irc_connection, i, cons) {
if (irc_connection) {
irc_connection.end('QUIT :' + (global.config.quit_message || ''));
irc_connection.dispose();
}
});
- this.dispose();
+ that.dispose();
}
});
};
global.config.restrict_server,
global.config.restrict_server_port,
global.config.restrict_server_ssl,
- command.nick,
+ nick,
user,
- global.config.restrict_server_password);
+ global.config.restrict_server_password,
+ this);
} else {
con = new IrcConnection(
- command.hostname,
- command.port,
- command.ssl,
- command.nick,
+ hostname,
+ port,
+ ssl,
+ nick,
user,
- command.password);
+ pass,
+ this);
}
con_num = this.next_connection++;
});
con.on('error', function (err) {
- console.log('irc_connection error (' + command.hostname + '):', err);
+ console.log('irc_connection error (' + hostname + '):', err);
return callback(err.code, {server: con_num, error: err});
});
};
State.prototype.dispose = function () {
- this.emit('destroy');
+ this.emit('dispose');
this.removeAllListeners();
};