this.gateway = _kiwi.global.components.Network();
this.gateway.on('connect', this.networkConnected, this);
this.gateway.on('connecting', this.networkConnecting, this);
+ this.gateway.on('disconnect', this.networkDisconnected, this);
this.gateway.on('irc_error', this.onIrcError, this);
},
this.model.current_connecting_network = null;
},
+ networkDisconnected: function () {
+ this.model.current_connecting_network = null;
+ this.state = 'all';
+ },
+
networkConnecting: function (event) {
this.model.trigger('connecting');
this.setStatus(_kiwi.global.i18n.translate('client_views_serverselect_connection_trying').fetch(), 'ok');
// Socket state
this.connected = false;
+ // If the connection closes and this is false, we reconnect
+ this.requested_disconnect = false;
+
// IRCd write buffers (flood controll)
this.write_buffer = [];
// Make sure we don't already have an open connection
this.disposeSocket();
+ this.requested_disconnect = false;
+
// Get the IP family for the dest_addr (either socks or IRCd destination)
getConnectionFamily(dest_addr, function getConnectionFamilyCb(err, family, host) {
var outgoing;
});
that.socket.on('close', function socketCloseCb(had_error) {
+ // If that.connected is false, we never actually managed to connect
+ var was_connected = that.connected,
+ had_registered = that.server.registered,
+ should_reconnect = false;
+
that.connected = false;
+ that.server.reset();
// Remove this socket form the identd lookup
if (that.identd_port_pair) {
delete global.clients.port_pairs[that.identd_port_pair];
}
- that.emit('close', had_error);
+ should_reconnect = (!that.requested_disconnect && was_connected && had_registered);
+
+ if (should_reconnect) {
+ that.emit('reconnecting');
+ } else {
+ that.emit('close', had_error);
+ }
// Close the whole socket down
that.disposeSocket();
+
+ // If this socket closing was not expected and we did actually connect and
+ // we did previously completely register on the network, then reconnect
+ if (should_reconnect) {
+ setTimeout(function() {
+ that.connect();
+ }, 3000);
+ }
});
});
};
return;
}
+ this.requested_disconnect = true;
+
if (data) {
this.write(data, true);
}
this.list_buffer = [];
this.motd_buffer = '';
+ this.registered = false;
+
this.irc_events = {
connect: onConnect,
options: onOptions,
};
+IrcServer.prototype.reset = function() {
+ this.registered = false;
+ this.list_buffer = [];
+ this.motd_buffer = '';
+};
+
+
function onConnect(event) {
+ this.registered = true;
+
this.irc_connection.clientEvent('connect', {
nick: event.nick
});
return callback(err.message);
});
+ con.on('reconnecting', function IrcConnectionReconnecting() {
+ that.sendIrcCommand('disconnect', {connection_id: con.con_num, reason: 'IRC server reconnecting'});
+ });
+
con.on('close', function IrcConnectionClose() {
// TODO: Can we get a better reason for the disconnection? Was it planned?
that.sendIrcCommand('disconnect', {connection_id: con.con_num, reason: 'disconnected'});