Added configuration file

This commit is contained in:
Mattias Erming 2014-03-13 13:44:54 +01:00
parent bc5e5ee5fc
commit e587a46242
3 changed files with 66 additions and 93 deletions

3
config.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
host: "irc.freenode.org"
};

View File

@ -49,34 +49,20 @@ models.Channel = Backbone.Model.extend({
});
this.set("users", new models.UserCollection());
this.get("users").on(
"add change remove",
function() {
// Bubble event
this.trigger(
"users", {
target: this.get("id"),
data: this.get("users")
}
);
},
this
);
this.get("users").on("all", function() {
this.trigger("users", {
target: this.get("id"),
data: this.get("users")
});
}, this);
this.set("messages", new models.MessageCollection());
this.get("messages").on(
"add",
function() {
// Bubble event
this.trigger(
"messages", {
target: this.get("id"),
data: this.get("messages").last()
}
);
},
this
);
this.get("messages").on("all", function() {
this.trigger("messages", {
target: this.get("id"),
data: this.get("messages").last()
});
}, this);
}
});
@ -96,26 +82,13 @@ models.Network = Backbone.Model.extend({
});
this.set("channels", new models.ChannelCollection());
this.get("channels").on(
"all",
function(type, model, collection) {
if ([
"users",
"messages"
].indexOf(type) != -1) {
this.trigger(type, model);
} else {
// Bubble event
this.trigger(
"channels", {
target: this.get("id"),
data: collection
}
);
}
},
this
);
this.get("channels").on("all", function(type, data) {
if (type == "users" || type == "messages") {
this.trigger(type, data);
} else {
this.trigger("channels");
}
}, this);
this.get("channels").add(new models.Channel({
type: "network",
name: this.get("host")

View File

@ -1,7 +1,8 @@
var connect = require("connect");
var io = require("socket.io");
// Local library
// Local libraries
var config = require("./../config.js");
var models = require("./models.js");
module.exports = Server;
@ -17,25 +18,24 @@ Server.prototype.listen = function(port) {
.use(connect.static("client"))
.listen(port);
this.networks.on(
"all",
function(type, data) {
if (type != "users" && type != "messages") {
type = "networks";
data = self.networks;
}
self.sockets
.emit(type, data);
this.networks.on("all", function(type, data) {
if (type == "users" || type == "messages") {
self.sockets.emit(type, data);
} else {
// Network and channel events will force
// a full refresh.
self.sockets.emit(
"networks", self.networks
);
}
);
});
this.sockets = io
.listen(http, {log: false})
.sockets;
this.sockets.on("connection", function(socket) {
socket.emit(
"networks",
self.networks
"networks", self.networks
);
socket.on(
"input",
@ -59,6 +59,25 @@ function handleInput(input) {
: "";
switch (cmd) {
case "SERVER":
case "CONNECT":
var network = this.networks.add(
new models.Network({
host: argv[1] || config.host
})
);
network.irc.addListener("raw", function() {
handleEvent.apply(network, arguments);
}
);
break;
case "QUIT":
case "DISCONNECT":
this.networks.remove(target.network);
break;
case "":
var irc = target.network.irc;
if (typeof irc !== "undefined") {
@ -149,26 +168,6 @@ function handleInput(input) {
}
break;
case "SERVER":
case "CONNECT":
if (argv[1]) {
var network = this.networks.add(
new models.Network({host: argv[1]})
);
network.irc.addListener(
"raw",
function() {
handleEvent.apply(network, arguments);
}
);
}
break;
case "QUIT":
case "DISCONNECT":
this.networks.remove(target.network);
break;
default:
target.channel.get("messages").add(
new models.Message({text: "Command `/" + cmd + "` does not exist."})
@ -181,7 +180,9 @@ function handleEvent(argv) {
var network = this;
var channels = network.get("channels");
var event = argv.command;
var event = argv.commandType != "error" ? argv.command
: "ERROR";
switch (event) {
case "PRIVMSG":
@ -334,12 +335,7 @@ function handleEvent(argv) {
);
break;
case "err_nicknameinuse":
case "err_chanoprivsneeded":
case "err_notonchannel":
case "err_nosuchchannel":
case "err_cannotsendtochan":
case "err_nosuchnick":
case "ERROR":
channels.first().get("messages").add(
new models.Message({
text: argv.args.slice(2).join(" ")
@ -347,13 +343,14 @@ function handleEvent(argv) {
);
break;
default:
channels.first().get("messages").add(
new models.Message({
user: "-!-",
text: argv.args.slice(1).join(" ")
})
);
//default:
// channels.first().get("messages").add(
// new models.Message({
// user: "-!-",
// text: argv.args.slice(1).join(" ")
// })
// );
}
// Debug