str += command.data.args.target + ' :'
str += String.fromCharCode(1) + command.data.args.type + ' ';
str += command.data.args.params + String.fromCharCode(1);
- this.IRC_connections[command.server].send(str);
+ this.IRC_connections[command.server].write(str);
} else if (command.data.method === 'raw') {
- this.IRC_connections[command.server].send(command.data.args.data);
+ this.IRC_connections[command.server].write(command.data.args.data);
} else if (command.data.method === 'kiwi') {
// do special Kiwi stuff here
} else {
method = command.data.method;
command.data = command.data.args;
- this.IRC_connections[command.server].send(method + ((command.data.params) ? ' ' + command.data.params.join(' ') : '') + ((command.data.trailing) ? ' :' + command.data.trailing : ''), callback);
+ this.IRC_connections[command.server].write(method + ((command.data.params) ? ' ' + command.data.params.join(' ') : '') + ((command.data.trailing) ? ' :' + command.data.trailing : ''), callback);
}
};
var kiwi_command = function (command, callback) {
+ var that = this;
console.log(typeof callback);
if (typeof callback !== 'function') {
callback = function () {};
con.on('error', function (err) {
this.websocket.sendKiwiCommand('error', {server: con_num, error: err});
});
+
+ con.on('close', function () {
+ that.IRC_connections[con_num] = null;
+ });
} else {
return callback('Hostname, port and nickname must be specified');
}
};
var disconnect = function () {
+ _.each(this.IRC_connections, function (irc_connection, i, cons) {
+ if (irc_connection) {
+ irc_connection.end('QUIT :Kiwi IRC');
+ cons[i] = null;
+ }
+ });
this.emit('destroy');
};
} else if (option[0] === 'CHANMODES') {
this.irc_connection.options.CHANMODES = option[1].split(',');
} else if (option[0] === 'NAMESX') {
- this.irc_connection.send('PROTOCTL NAMESX');
+ this.irc_connection.write('PROTOCTL NAMESX');
}
}
}
this.client.sendIRCCommand('topicsetby', {server: this.con_num, nick: command.params[2], channel: command.params[1], when: command.params[3]});
},
'PING': function (command) {
- this.irc_connection.send('PONG ' + command.trailing);
+ this.irc_connection.write('PONG ' + command.trailing);
},
'JOIN': function (command) {
var channel;
this.client.sendIRCCommand('join', {server: this.con_num, nick: command.nick, ident: command.ident, hostname: command.hostname, channel: channel});
if (command.nick === this.nick) {
- this.irc_connection.send('NAMES ' + channel);
+ this.irc_connection.write('NAMES ' + channel);
}
},
'PART': function (command) {
namespace = tmp.split(' ', 1)[0];
this.client.sendIRCCommand('kiwi', {server: this.con_num, namespace: namespace, data: tmp.substr(namespace.length + 1)});
} else if (msg.trailing.substr(1, 7) === 'VERSION') {
- this.irc_connection.send('NOTICE ' + command.nick + ' :' + String.fromCharCode(1) + 'VERSION KiwiIRC' + String.fromCharCode(1));
+ this.irc_connection.write('NOTICE ' + command.nick + ' :' + String.fromCharCode(1) + 'VERSION KiwiIRC' + String.fromCharCode(1));
} else {
this.client.sendIRCCommand('ctcp_request', {server: this.con_num, nick: command.nick, ident: command.ident, hostname: command.hostname, channel: command.params[0], msg: command.trailing.substr(1, command.trailing.length - 2)});
}
parse.apply(that, arguments);
});
+ this.socket.on('close', function () {
+ that.emit('close');
+ });
+
this.connected = false;
this.registered = false;
this.nick = nick;
};
util.inherits(IRCConnection, events.EventEmitter);
-IRCConnection.prototype.send = function (data, callback) {
+IRCConnection.prototype.write = function (data, callback) {
console.log('S<--', data);
write.call(this, data + '\r\n', 'utf-8', callback);
};
+IRCConnection.prototype.end = function (data, callback) {
+ console.log('S<--', data);
+ console.log('Closing docket');
+ end.call(this, data + '\r\n', 'utf-8', callback);
+}
+
var write = function (data, encoding, callback) {
this.socket.write(data, encoding, callback);
};
+var end = function (data, encoding, callback) {
+ this.socket.end(data, encoding, callback);
+};
+
module.exports.IRCConnection = IRCConnection;
var connect_handler = function () {
if (this.webirc) {
- this.send('WEBIRC ' + webirc.pass + ' KiwiIRC ' + this.user.hostname + ' ' + this.user.address);
+ this.write('WEBIRC ' + webirc.pass + ' KiwiIRC ' + this.user.hostname + ' ' + this.user.address);
}
if (this.password) {
- this.send('PASS ' + password);
+ this.write('PASS ' + password);
}
- //this.send('CAP LS');
- this.send('NICK ' + this.nick);
- this.send('USER kiwi_' + this.nick.replace(/[^0-9a-zA-Z\-_.]/, '') + ' 0 0 :' + this.nick);
+ //this.write('CAP LS');
+ this.write('NICK ' + this.nick);
+ this.write('USER kiwi_' + this.nick.replace(/[^0-9a-zA-Z\-_.]/, '') + ' 0 0 :' + this.nick);
this.connected = true;
console.log("IRCConnection.emit('connected')");