Merge pull request #254 from thelounge/xpaw/auto-rc

Enable auto reconnection
This commit is contained in:
Jérémie Astori 2016-05-24 18:43:20 -04:00
commit 7834d12e8f
5 changed files with 29 additions and 5 deletions

View File

@ -36,6 +36,7 @@ var inputs = [
"part", "part",
"action", "action",
"connect", "connect",
"disconnect",
"invite", "invite",
"kick", "kick",
"mode", "mode",
@ -211,7 +212,7 @@ Client.prototype.connect = function(args) {
tls: network.tls, tls: network.tls,
localAddress: config.bind, localAddress: config.bind,
rejectUnauthorized: false, rejectUnauthorized: false,
auto_reconnect: false, // TODO: Enable auto reconnection auto_reconnect: true,
webirc: webirc, webirc: webirc,
}); });

View File

@ -1,8 +1,24 @@
var Msg = require("../../models/msg");
exports.commands = ["connect", "server"]; exports.commands = ["connect", "server"];
exports.allowDisconnected = true; exports.allowDisconnected = true;
exports.input = function(network, chan, cmd, args) { exports.input = function(network, chan, cmd, args) {
if (args.length === 0) { if (args.length === 0) {
if (!network.irc || !network.irc.connection) {
return;
}
if (network.irc.connection.connected) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
text: "You are already connected."
}));
return;
}
network.irc.connection.connect();
return; return;
} }

View File

@ -0,0 +1,7 @@
exports.commands = ["disconnect"];
exports.input = function(network, chan, cmd, args) {
var quitMessage = args[0] ? args.join(" ") : "";
network.irc.quit(quitMessage);
};

View File

@ -1,6 +1,6 @@
var _ = require("lodash"); var _ = require("lodash");
exports.commands = ["quit", "disconnect"]; exports.commands = ["quit"];
exports.allowDisconnected = true; exports.allowDisconnected = true;
exports.input = function(network, chan, cmd, args) { exports.input = function(network, chan, cmd, args) {

View File

@ -19,9 +19,9 @@ module.exports = function(irc, network) {
})); }));
}); });
irc.on("socket close", function() { irc.on("close", function() {
network.channels[0].pushMessage(client, new Msg({ network.channels[0].pushMessage(client, new Msg({
text: "Disconnected from the network." text: "Disconnected from the network, and will not reconnect."
})); }));
}); });
@ -35,7 +35,7 @@ module.exports = function(irc, network) {
irc.on("reconnecting", function() { irc.on("reconnecting", function() {
network.channels[0].pushMessage(client, new Msg({ network.channels[0].pushMessage(client, new Msg({
text: "Reconnecting..." text: "Disconnected from the network. Reconnecting..."
})); }));
}); });