2014-04-23 18:44:44 +00:00
|
|
|
var _ = require("lodash");
|
|
|
|
var Chan = require("./chan");
|
|
|
|
|
|
|
|
module.exports = Network;
|
|
|
|
|
|
|
|
function Network(attr) {
|
|
|
|
_.merge(this, _.extend({
|
|
|
|
id: global.id = ++global.id || 1,
|
|
|
|
client: null,
|
2014-06-14 15:57:26 +00:00
|
|
|
connected: false,
|
2014-04-23 18:44:44 +00:00
|
|
|
host: "",
|
|
|
|
nick: "",
|
|
|
|
channels: [],
|
|
|
|
}, attr));
|
|
|
|
|
2014-06-18 22:16:44 +00:00
|
|
|
this.name = this.host.split(".")[1] || clone.host;
|
|
|
|
|
2014-04-23 18:44:44 +00:00
|
|
|
// Add lobby
|
|
|
|
this.channels.unshift(
|
2014-05-02 21:54:31 +00:00
|
|
|
new Chan({name: this.host, type: "lobby"})
|
2014-04-23 18:44:44 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2014-06-15 15:01:38 +00:00
|
|
|
Network.prototype.addChan = function(chan) {
|
2014-06-20 13:57:11 +00:00
|
|
|
chan.network = this;
|
2014-06-15 15:01:38 +00:00
|
|
|
this.channels.push(chan);
|
|
|
|
};
|
|
|
|
|
2014-04-30 15:14:22 +00:00
|
|
|
Network.prototype.toJSON = function() {
|
2014-06-14 15:57:26 +00:00
|
|
|
var clone = _.omit(this, [
|
|
|
|
"client",
|
|
|
|
"connected",
|
|
|
|
]);
|
2014-05-02 17:46:18 +00:00
|
|
|
return clone;
|
2014-04-23 18:44:44 +00:00
|
|
|
};
|