Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Revert "Reconnection support."
Browse files Browse the repository at this point in the history
This reverts commit 4431bb3.
  • Loading branch information
bews committed May 10, 2016
1 parent 4431bb3 commit 28648cc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 93 deletions.
132 changes: 58 additions & 74 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ var events = [
"quit",
"topic",
"welcome",
"whois",
"ping"
"whois"
];
var inputs = [
"action",
Expand Down Expand Up @@ -139,10 +138,35 @@ Client.prototype.connect = function(args) {
}
}

var stream = args.tls ? tls.connect(server) : net.connect(server);

stream.on("error", function(e) {
console.log("Client#connect():\n" + e);
stream.end();
var msg = new Msg({
type: Msg.Type.ERROR,
text: "Connection error."
});
client.emit("msg", {
msg: msg
});
});

var nick = args.nick || "shout-user";
var username = args.username || nick.replace(/[^a-zA-Z0-9]/g, "");
var realname = args.realname || "Shout User";

var irc = slate(stream);
identd.hook(stream, username);

if (args.password) {
irc.pass(args.password);
}

irc.me = nick;
irc.nick(nick);
irc.user(username, realname);

var network = new Network({
name: server.name,
host: server.host,
Expand All @@ -154,87 +178,47 @@ Client.prototype.connect = function(args) {
commands: args.commands
});

network.irc = irc;

client.networks.push(network);
client.emit("network", {
network: network
});

var reconnect = function(args) {
network = _.find(client.networks, {id: network.id});

var stream = args.tls ? tls.connect(server) : net.connect(server);
events.forEach(function(plugin) {
var path = "./plugins/irc-events/" + plugin;
require(path).apply(client, [
irc,
network
]);
});

stream.on("error", function(e) {
console.log("Client#connect():\n" + e);
if(e.message.indexOf('write after end') != -1) {
return; // fix exponential reconnection attempts
}
stream.end();
var msg = new Msg({
type: Msg.Type.ERROR,
text: "Connection error. Reconnecting in 15 seconds."
irc.once("welcome", function() {
var delay = 1000;
var commands = args.commands;
if (Array.isArray(commands)) {
commands.forEach(function(cmd) {
setTimeout(function() {
client.input({
target: network.channels[0].id,
text: cmd
});
}, delay);
delay += 1000;
});
var lobby = network.channels[0];
lobby.messages.push(msg);
client.emit("msg", {
chan: lobby.id,
msg: msg
});
setTimeout(function() {
reconnect(args);
}, 15000);
});

var irc = slate(stream);
identd.hook(stream, username);

if (args.password) {
irc.pass(args.password);
}
setTimeout(function() {
irc.write("PING " + network.host);
}, delay);
});

irc.me = nick;
irc.nick(nick);
irc.user(username, realname);

network.irc = irc;

events.forEach(function(plugin) {
var path = "./plugins/irc-events/" + plugin;
require(path).apply(client, [
irc,
network
]);
});

irc.once("welcome", function() {
var delay = 1000;
var commands = args.commands;
if (Array.isArray(commands)) {
commands.forEach(function(cmd) {
setTimeout(function() {
client.input({
target: network.channels[0].id,
text: cmd
});
}, delay);
delay += 1000;
});
}
setTimeout(function() {
irc.write("PING " + network.host);
}, delay);
});

irc.once("pong", function() {
var join = (args.join || "");
if (join) {
join = join.replace(/\,/g, " ").split(/\s+/g);
irc.join(join);
}
});
};

reconnect(args);
irc.once("pong", function() {
var join = (args.join || "");
if (join) {
join = join.replace(/\,/g, " ").split(/\s+/g);
irc.join(join);
}
});
};

Client.prototype.input = function(data) {
Expand Down
19 changes: 0 additions & 19 deletions src/plugins/irc-events/ping.js

This file was deleted.

0 comments on commit 28648cc

Please sign in to comment.