mode: onMode
};
EventBinder.bindIrcEvents('channel ' + this.name, this.irc_events, this, irc_connection);
-}
+};
module.exports = IrcChannel;
if (event.nick === this.irc_connection.nick) {
this.irc_connection.write('NAMES ' + this.name);
}
-};
+}
function onPart(event) {
channel: this.name,
message: event.message
});
-};
+}
function onKick(event) {
channel: this.name,
message: event.message
});
-};
+}
function onQuit(event) {
hostname: event.hostname,
message: event.message
});
-};
+}
function onMsg(event) {
channel: this.name,
msg: event.msg
});
-};
+}
function onNotice(event) {
target: event.target,
msg: event.msg
});
-};
+}
function onCtcpRequest(event) {
type: event.type,
msg: event.msg
});
-};
+}
function onCtcpResponse(event) {
type: event.type,
msg: event.msg
});
-};
+}
// TODO: Split event.users into batches of 50
});
// TODO: uncomment when using an IrcUser per nick
//updateUsersList.call(this, event.users);
-};
+}
function onNicklistEnd(event) {
});
// TODO: uncomment when using an IrcUser per nick
//updateUsersList.call(this, event.users);
-};
+}
function updateUsersList(users) {
var that = this;
channel: this.name,
topic: event.topic
});
-};
+}
function onBanList(event) {
this.ban_list_buffer.push(event);
-};
+}
function onBanListEnd(event) {
var that = this;
that.irc_connection.clientEvent('banlist', ban);
});
this.ban_list_buffer = [];
-};
+}
function onTopic(event) {
this.irc_connection.clientEvent('topic', {
channel: event.channel,
topic: event.topic
});
-};
+}
function onTopicSetBy(event) {
this.irc_connection.clientEvent('topicsetby', {
channel: event.channel,
when: event.when
});
-};
+}
function onMode(event) {
this.irc_connection.clientEvent('mode', {
nick: event.nick,
modes: event.modes
});
-};
+}
IrcChannel = require('./channel.js'),
IrcUser = require('./user.js'),
Socks;
-
-
+
+
// Break the Node.js version down into usable parts
var version_values = process.version.substr(1).split('.').map(function (item) {
return parseInt(item, 10);
delimiter: ' '
});
this.setMaxListeners(0);
-
+
// Socket state
this.connected = false;
this.user = user; // Contains users real hostname and address
this.username = this.nick.replace(/[^0-9a-zA-Z\-_.\/]/, '');
this.password = pass;
-
+
// State object
this.state = state;
-
+
// IrcServer object
this.server = new IrcServer(this, hostname, port);
-
+
// IrcUser objects
this.irc_users = Object.create(null);
// IRC connection information
this.irc_host = {hostname: hostname, port: port};
this.ssl = !(!ssl);
-
+
// SOCKS proxy details
// TODO: Wildcard matching of hostnames and/or CIDR ranges of IP addresses
if ((global.config.socks_proxy && global.config.socks_proxy.enabled) && ((global.config.socks_proxy.all) || (_.contains(global.config.socks_proxy.proxy_hosts, this.irc_host.hostname)))) {
// Is SASL supported on the IRCd
this.sasl = false;
-
+
// Buffers for data sent from the IRCd
this.hold_last = false;
this.held_data = '';
// Are we connecting through a SOCKS proxy?
if (this.socks) {
this.socket = Socks.connect({
- host: this.irc_host.hostname,
+ host: this.irc_host.hostname,
port: this.irc_host.port,
ssl: this.ssl,
rejectUnauthorized: global.config.reject_unauthorised_certificates
user: this.socks.user,
pass: this.socks.pass
});
-
+
} else if (this.ssl) {
this.socket = tls.connect({
host: this.irc_host.hostname,
port: this.irc_host.port
});
}
-
+
this.socket.on(socket_connect_event_name, function () {
that.connected = true;
socketConnectHandler.call(that);
});
-
+
this.socket.setEncoding('utf-8');
-
+
this.socket.on('error', function (event) {
that.emit('error', event);
-
});
-
+
this.socket.on('data', function () {
parse.apply(that, arguments);
});
-
+
this.socket.on('close', function (had_error) {
that.connected = false;
that.emit('close');
IrcConnection.prototype.end = function (data, callback) {
if (data)
this.write(data);
-
+
this.socket.end();
};
if (that.password)
that.write('PASS ' + that.password);
-
+
that.write('NICK ' + that.nick);
that.write('USER ' + that.username + ' 0 0 :' + '[www.kiwiirc.com] ' + that.nick);
-
+
that.emit('connected');
});
};
this.list_buffer = [];
this.motd_buffer = '';
-
+
this.irc_events = {
connect: onConnect,
options: onOptions,
nickname_in_use: onNicknameInUse
};
EventBinder.bindIrcEvents('server *', this.irc_events, this, this.irc_connection);
-
};
this.irc_connection.clientEvent('connect', {
nick: event.nick
});
-};
+}
function onOptions(event) {
this.irc_connection.clientEvent('options', {
options: event.options,
cap: event.cap
});
-};
+}
function onListStart(event) {
this.irc_connection.clientEvent('list_start', {});
this.list_buffer = [];
this.busy_listing = true;
-};
+}
function onListChannel(event) {
var buf;
num_users: event.num_users,
topic: event.topic
});
-
+
if (this.list_buffer.length > 200) {
buf = _.sortBy(this.list_buffer, function (channel) {
// sortBy sorts in ascending order, we want to sort by descending, hence using 0 - num_users.
});
this.list_buffer = [];
}
-};
+}
function onListEnd(event) {
var buf;
-
+
buf = _.sortBy(this.list_buffer, function (channel) {
// sortBy sorts in ascending order, we want to sort by descending, hence using 0 - num_users.
return 0 - channel.num_users;
});
this.list_buffer = [];
this.busy_listing = false;
-
+
this.irc_connection.clientEvent('list_end', {});
-};
+}
function onMotdStart(event) {
this.motd_buffer = '';
-};
+}
function onMotd(event) {
this.motd_buffer += event.motd;
-};
+}
function onMotdEnd(event) {
this.irc_connection.clientEvent('motd', {
msg: this.motd_buffer
});
-};
+}
function onError(event) {
this.irc_connection.clientEvent('irc_error', {
error: 'error',
reason: event.reason
});
-};
+}
function onPasswordMismatch(event) {
this.irc_connection.clientEvent('irc_error', {
from: event.from,
to: event.to
});
-};
+}
function onNoSuchNick(event) {
this.irc_connection.clientEvent('irc_error', {
nick: event.nick,
reason: event.reason
});
-};
+}
function onCannotSendToChan(event) {
this.irc_connection.clientEvent('irc_error', {
channel: event.channel,
reason: event.reason
});
-};
+}
function onTooManyChannels(event) {
this.irc_connection.clientEvent('irc_error', {
channel: event.channel,
reason: event.reason
});
-};
+}
function onUserNotInChannel(event) {
this.irc_connection.clientEvent('irc_error', {
channel: event.channel,
reason: event.reason
});
-};
+}
function onNotOnChannel(event) {
this.irc_connection.clientEvent('irc_error', {
channel: event.channel,
reason: event.reason
});
-};
+}
function onChannelIsFull(event) {
this.irc_connection.clientEvent('irc_error', {
channel: event.channel,
reason: event.reason
});
-};
+}
function onInviteOnlyChannel(event) {
this.irc_connection.clientEvent('irc_error', {
channel: event.channel,
reason: event.reason
});
-};
+}
function onBannedFromChannel(event) {
this.irc_connection.clientEvent('irc_error', {
channel: event.channel,
reason: event.reason
});
-};
+}
function onBadChannelKey(event) {
this.irc_connection.clientEvent('irc_error', {
channel: event.channel,
reason: event.reason
});
-};
+}
function onChanopPrivsNeeded(event) {
this.irc_connection.clientEvent('irc_error', {
channel: event.channel,
reason: event.reason
});
-};
+}
function onNicknameInUse(event) {
this.irc_connection.clientEvent('irc_error', {
nick: event.nick,
reason: event.reason
});
-};
+}
var IrcUser = function (irc_connection, nick) {\r
this.irc_connection = irc_connection;\r
this.nick = nick;\r
- \r
+\r
this.irc_events = {\r
nick: onNick,\r
away: onAway,\r
//EventBinder.unbindIrcEvents('user ' + this.nick, this.irc_events, irc_connection);\r
//this.nick = event.newnick;\r
//EventBinder.bindIrcEvents('user ' + this.nick, this.irc_events, this, irc_connection);\r
-};\r
+}\r
\r
function onAway(event) {\r
this.irc_connection.clientEvent('away', {\r
nick: event.nick,\r
msg: event.msg\r
});\r
-};\r
+}\r
\r
function onQuit(event) {\r
this.irc_connection.clientEvent('quit', {\r
hostname: event.hostname,\r
message: event.trailing\r
});\r
-};\r
+}\r
\r
function onWhoisUser(event) {\r
this.irc_connection.clientEvent('whois', {\r
msg: event.msg,\r
end: false\r
});\r
-};\r
+}\r
\r
function onWhoisAway(event) {\r
this.irc_connection.clientEvent('whois', {\r
away_reason: event.reason,\r
end: false\r
});\r
-};\r
+}\r
\r
function onWhoisServer(event) {\r
this.irc_connection.clientEvent('whois', {\r
irc_server: event.irc_server,\r
end: false\r
});\r
-};\r
+}\r
\r
function onWhoisOperator(event) {\r
this.irc_connection.clientEvent('whois', {\r
msg: event.msg,\r
end: false\r
});\r
-};\r
+}\r
\r
function onWhoisChannels(event) {\r
this.irc_connection.clientEvent('whois', {\r
chans: event.chans,\r
end: false\r
});\r
-};\r
+}\r
\r
function onWhoisModes(event) {\r
this.irc_connection.clientEvent('whois', {\r
msg: event.msg,\r
end: false\r
});\r
-};\r
+}\r
\r
function onWhoisIdle(event) {\r
this.irc_connection.clientEvent('whois', {\r
logon: event.logon || undefined,\r
end: false\r
});\r
-};\r
+}\r
\r
function onWhoisRegNick(event) {\r
this.irc_connection.clientEvent('whois', {\r
msg: event.msg,\r
end: false\r
});\r
-};\r
+}\r
\r
function onWhoisEnd(event) {\r
this.irc_connection.clientEvent('whois', {\r
msg: event.msg,\r
end: true\r
});\r
-};\r
+}\r
\r
function onNotice(event) {\r
this.irc_connection.clientEvent('notice', {\r
target: event.target,\r
msg: event.msg\r
});\r
-};\r
+}\r
\r
function onCtcpResponse(event) {\r
this.irc_connection.clientEvent('ctcp_response', {\r
channel: event.channel,\r
msg: event.msg\r
});\r
-};\r
+}\r
\r
function onPrivmsg(event) {\r
this.irc_connection.clientEvent('msg', {\r
channel: event.channel,\r
msg: event.msg\r
});\r
-};\r
+}\r
\r
function onCtcpRequest(event) {\r
this.irc_connection.clientEvent('ctcp_request', {\r
type: event.type,\r
msg: event.msg\r
});\r
-};\r
+}\r
\r
function onMode(event) {\r
this.irc_connection.clientEvent('mode', {\r
nick: event.nick,\r
modes: event.modes\r
});\r
-};\r
+}\r