Move connection events to a separate file, sync PREFIX with frontend
This commit is contained in:
parent
470b0a2c4f
commit
28ae544b2a
@ -146,6 +146,7 @@ $(function() {
|
||||
})
|
||||
);
|
||||
var channels = $.map(data.networks, function(n) {
|
||||
sidebar.find("#network-" + n.id).data("options", n.serverOptions);
|
||||
return n.channels;
|
||||
});
|
||||
chat.html(
|
||||
@ -294,6 +295,7 @@ $(function() {
|
||||
networks: [data.network]
|
||||
})
|
||||
);
|
||||
sidebar.find("#network-" + data.network.id).data("options", data.network.serverOptions);
|
||||
chat.append(
|
||||
render("chat", {
|
||||
channels: data.network.channels
|
||||
@ -310,6 +312,10 @@ $(function() {
|
||||
sortable();
|
||||
});
|
||||
|
||||
socket.on("network_changed", function(data) {
|
||||
sidebar.find("#network-" + data.network).data("options", data.serverOptions);
|
||||
});
|
||||
|
||||
socket.on("nick", function(data) {
|
||||
var id = data.network;
|
||||
var nick = data.nick;
|
||||
|
@ -1,7 +1,6 @@
|
||||
var _ = require("lodash");
|
||||
var Chan = require("./models/chan");
|
||||
var crypto = require("crypto");
|
||||
var identd = require("./identd");
|
||||
var log = require("./log");
|
||||
var Msg = require("./models/msg");
|
||||
var Network = require("./models/network");
|
||||
@ -12,6 +11,7 @@ module.exports = Client;
|
||||
|
||||
var id = 0;
|
||||
var events = [
|
||||
"connection",
|
||||
"ctcp",
|
||||
"error",
|
||||
"invite",
|
||||
@ -172,8 +172,8 @@ Client.prototype.connect = function(args) {
|
||||
return;
|
||||
}
|
||||
|
||||
var irc = new ircFramework.Client();
|
||||
irc.connect({
|
||||
network.irc = new ircFramework.Client();
|
||||
network.irc.connect({
|
||||
host: network.host,
|
||||
port: network.port,
|
||||
nick: nick,
|
||||
@ -186,49 +186,7 @@ Client.prototype.connect = function(args) {
|
||||
auto_reconnect: false, // TODO: Enable auto reconnection
|
||||
});
|
||||
|
||||
network.irc = irc;
|
||||
|
||||
events.forEach(function(plugin) {
|
||||
var path = "./plugins/irc-events/" + plugin;
|
||||
require(path).apply(client, [
|
||||
irc,
|
||||
network
|
||||
]);
|
||||
});
|
||||
|
||||
irc.on("raw socket connected", function() {
|
||||
identd.hook(irc.socket, network.username);
|
||||
});
|
||||
|
||||
irc.on("socket connected", function() {
|
||||
client.emit("msg", {
|
||||
chan: network.channels[0].id,
|
||||
msg: new Msg({
|
||||
text: "Connected to the network."
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
irc.on("socket close", function() {
|
||||
client.emit("msg", {
|
||||
chan: network.channels[0].id,
|
||||
msg: new Msg({
|
||||
type: Msg.Type.ERROR,
|
||||
text: "Disconnected from the network."
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
irc.on("reconnecting", function() {
|
||||
client.emit("msg", {
|
||||
chan: network.channels[0].id,
|
||||
msg: new Msg({
|
||||
text: "Reconnecting..."
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
irc.on("registered", function() {
|
||||
network.irc.on("registered", function() {
|
||||
var delay = 1000;
|
||||
var commands = args.commands;
|
||||
if (Array.isArray(commands)) {
|
||||
@ -247,10 +205,18 @@ Client.prototype.connect = function(args) {
|
||||
if (join) {
|
||||
setTimeout(function() {
|
||||
join = join.replace(/\,/g, " ").split(/\s+/g);
|
||||
irc.join(join);
|
||||
network.irc.join(join);
|
||||
}, delay);
|
||||
}
|
||||
});
|
||||
|
||||
events.forEach(function(plugin) {
|
||||
var path = "./plugins/irc-events/" + plugin;
|
||||
require(path).apply(client, [
|
||||
network.irc,
|
||||
network
|
||||
]);
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.setPassword = function(hash) {
|
||||
@ -373,10 +339,8 @@ Client.prototype.quit = function() {
|
||||
}
|
||||
this.networks.forEach(function(network) {
|
||||
var irc = network.irc;
|
||||
if (network.connected) {
|
||||
irc.quit();
|
||||
} else {
|
||||
irc.stream.end();
|
||||
if (irc.connection) {
|
||||
irc.connection.end();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -16,9 +16,11 @@ function Network(attr) {
|
||||
username: "",
|
||||
realname: "",
|
||||
channels: [],
|
||||
connected: false,
|
||||
id: id++,
|
||||
irc: null,
|
||||
serverOptions: {
|
||||
PREFIX: [],
|
||||
},
|
||||
}, attr));
|
||||
this.name = attr.name || prettify(attr.host);
|
||||
this.channels.unshift(
|
||||
|
68
src/plugins/irc-events/connection.js
Normal file
68
src/plugins/irc-events/connection.js
Normal file
@ -0,0 +1,68 @@
|
||||
var identd = require("../../identd");
|
||||
var Msg = require("../../models/msg");
|
||||
|
||||
module.exports = function(irc, network) {
|
||||
var client = this;
|
||||
|
||||
client.emit("msg", {
|
||||
chan: network.channels[0].id,
|
||||
msg: new Msg({
|
||||
text: "Network created, connecting to " + network.host + ":" + network.port + "..."
|
||||
})
|
||||
});
|
||||
|
||||
irc.on("raw socket connected", function() {
|
||||
identd.hook(irc.socket, network.username);
|
||||
});
|
||||
|
||||
irc.on("socket connected", function() {
|
||||
client.emit("msg", {
|
||||
chan: network.channels[0].id,
|
||||
msg: new Msg({
|
||||
text: "Connected to the network."
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
irc.on("socket close", function() {
|
||||
client.emit("msg", {
|
||||
chan: network.channels[0].id,
|
||||
msg: new Msg({
|
||||
text: "Disconnected from the network."
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
irc.on("socket error", function(err) {
|
||||
console.log(err);
|
||||
client.emit("msg", {
|
||||
chan: network.channels[0].id,
|
||||
msg: new Msg({
|
||||
type: Msg.Type.ERROR,
|
||||
text: "Socket error: " + err
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
irc.on("reconnecting", function() {
|
||||
client.emit("msg", {
|
||||
chan: network.channels[0].id,
|
||||
msg: new Msg({
|
||||
text: "Reconnecting..."
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
irc.on("server options", function(data) {
|
||||
if (network.serverOptions.PREFIX === data.options.PREFIX) {
|
||||
return;
|
||||
}
|
||||
|
||||
network.serverOptions.PREFIX = data.options.PREFIX;
|
||||
|
||||
client.emit("network_changed", {
|
||||
network: network.id,
|
||||
serverOptions: network.serverOptions
|
||||
});
|
||||
});
|
||||
};
|
@ -42,6 +42,11 @@ module.exports = function(irc, network) {
|
||||
}
|
||||
}
|
||||
|
||||
// Server messages go to server window
|
||||
if (data.from_server) {
|
||||
chan = network.channels[0];
|
||||
}
|
||||
|
||||
var self = data.nick === irc.user.nick;
|
||||
|
||||
// Self messages are never highlighted
|
||||
|
@ -3,7 +3,6 @@ var Msg = require("../../models/msg");
|
||||
module.exports = function(irc, network) {
|
||||
var client = this;
|
||||
irc.on("registered", function(data) {
|
||||
network.connected = true;
|
||||
network.nick = data.nick;
|
||||
var lobby = network.channels[0];
|
||||
var msg = new Msg({
|
||||
|
Loading…
Reference in New Issue
Block a user