};
-IrcCommands = function (irc_connection, con_num, client) {
+IrcCommands = function (irc_connection) {
this.irc_connection = irc_connection;
- this.con_num = con_num;
- this.client = client;
};
module.exports = IrcCommands;
if ((command.trailing.charAt(0) === String.fromCharCode(1)) && (command.trailing.charAt(command.trailing.length - 1) === String.fromCharCode(1))) {
//CTCP request
if (command.trailing.substr(1, 6) === 'ACTION') {
- this.client.sendIrcCommand('action', {server: this.con_num, nick: command.nick, ident: command.ident, hostname: command.hostname, channel: command.params[0], msg: command.trailing.substr(7, command.trailing.length - 2)});
+ this.irc_connection.clientEvent('action', {nick: command.nick, ident: command.ident, hostname: command.hostname, channel: command.params[0], msg: command.trailing.substr(7, command.trailing.length - 2)});
} else if (command.trailing.substr(1, 4) === 'KIWI') {
tmp = command.trailing.substr(6, command.trailing.length - 2);
namespace = tmp.split(' ', 1)[0];
- this.client.sendIrcCommand('kiwi', {server: this.con_num, namespace: namespace, data: tmp.substr(namespace.length + 1)});
+ this.irc_connection.clientEvent('kiwi', {namespace: namespace, data: tmp.substr(namespace.length + 1)});
} else if (command.trailing.substr(1, 7) === 'VERSION') {
this.irc_connection.write('NOTICE ' + command.nick + ' :' + String.fromCharCode(1) + 'VERSION KiwiIRC' + String.fromCharCode(1));
} else if (command.trailing.substr(1, 6) === 'SOURCE') {
if (typeof is_error !== 'boolean')
is_error = true;
- this.client.sendIrcCommand('notice', {
- server: this.con_num,
+ this.irc_connection.clientEvent('notice', {
from_server: true,
nick: command.prefix,
ident: '',
_ = require('lodash'),
EventBinder = require('./eventbinder.js'),
IrcServer = require('./server.js'),
+ IrcCommands = require('./commands.js'),
IrcChannel = require('./channel.js'),
IrcUser = require('./user.js'),
EE = require('../ee.js'),
Socks = require('socksjs');
}
-var IrcConnection = function (hostname, port, ssl, nick, user, pass, state) {
+var IrcConnection = function (hostname, port, ssl, nick, user, pass, state, con_num) {
var that = this;
EE.call(this,{
// State object
this.state = state;
+ // Connection ID in the state
+ this.con_num = con_num;
+
+ // IRC protocol handling
+ this.irc_commands = new IrcCommands(this);
+
// IrcServer object
this.server = new IrcServer(this, hostname, port);
var util = require('util'),
events = require('events'),
_ = require('lodash'),
- IrcConnection = require('./connection.js').IrcConnection,
- IrcCommands = require('./commands.js');
+ IrcConnection = require('./connection.js').IrcConnection;
var State = function (client, save_state) {
var that = this;
return callback('Too many connections to host', {host: hostname, limit: global.config.max_server_conns});
}
+ con_num = this.next_connection++;
con = new IrcConnection(
hostname,
port,
nick,
user,
pass,
- this);
+ this,
+ con_num);
- con_num = this.next_connection++;
this.irc_connections[con_num] = con;
- con.con_num = con_num;
-
- con.irc_commands = new IrcCommands(con, con_num, this);
con.on('connected', function () {
global.servers.addConnection(this);