2016-03-11 16:34:50 +00:00
|
|
|
var _ = require("lodash");
|
2016-03-08 18:50:48 +00:00
|
|
|
var identd = require("../../identd");
|
|
|
|
var Msg = require("../../models/msg");
|
|
|
|
|
|
|
|
module.exports = function(irc, network) {
|
|
|
|
var client = this;
|
|
|
|
|
2016-04-19 10:20:18 +00:00
|
|
|
network.channels[0].pushMessage(client, new Msg({
|
|
|
|
text: "Network created, connecting to " + network.host + ":" + network.port + "..."
|
|
|
|
}));
|
2016-03-08 18:50:48 +00:00
|
|
|
|
|
|
|
irc.on("raw socket connected", function() {
|
2016-03-20 18:03:18 +00:00
|
|
|
identd.hook(irc.connection.socket, network.username);
|
2016-03-08 18:50:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
irc.on("socket connected", function() {
|
2016-04-19 10:20:18 +00:00
|
|
|
network.channels[0].pushMessage(client, new Msg({
|
|
|
|
text: "Connected to the network."
|
|
|
|
}));
|
2016-03-08 18:50:48 +00:00
|
|
|
});
|
|
|
|
|
2016-04-13 07:10:44 +00:00
|
|
|
irc.on("close", function() {
|
2016-04-19 10:20:18 +00:00
|
|
|
network.channels[0].pushMessage(client, new Msg({
|
2016-04-13 07:10:44 +00:00
|
|
|
text: "Disconnected from the network, and will not reconnect."
|
2016-04-19 10:20:18 +00:00
|
|
|
}));
|
2016-03-08 18:50:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
irc.on("socket error", function(err) {
|
2016-04-16 11:32:38 +00:00
|
|
|
log.debug("IRC socket error", err);
|
2016-04-19 10:20:18 +00:00
|
|
|
network.channels[0].pushMessage(client, new Msg({
|
|
|
|
type: Msg.Type.ERROR,
|
|
|
|
text: "Socket error: " + err
|
|
|
|
}));
|
2016-03-08 18:50:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
irc.on("reconnecting", function() {
|
2016-04-19 10:20:18 +00:00
|
|
|
network.channels[0].pushMessage(client, new Msg({
|
2016-04-13 07:10:44 +00:00
|
|
|
text: "Disconnected from the network. Reconnecting..."
|
2016-04-19 10:20:18 +00:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
irc.on("ping timeout", function() {
|
|
|
|
network.channels[0].pushMessage(client, new Msg({
|
|
|
|
text: "Ping timeout, disconnecting..."
|
|
|
|
}));
|
2016-03-08 18:50:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
irc.on("server options", function(data) {
|
|
|
|
if (network.serverOptions.PREFIX === data.options.PREFIX) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-11 16:34:50 +00:00
|
|
|
network.prefixLookup = {};
|
|
|
|
|
|
|
|
_.each(data.options.PREFIX, function(mode) {
|
|
|
|
network.prefixLookup[mode.mode] = mode.symbol;
|
|
|
|
});
|
|
|
|
|
2016-03-08 18:50:48 +00:00
|
|
|
network.serverOptions.PREFIX = data.options.PREFIX;
|
|
|
|
|
|
|
|
client.emit("network_changed", {
|
|
|
|
network: network.id,
|
|
|
|
serverOptions: network.serverOptions
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|