Run private server by default

Use `shout start --public` or edit your `config.json` to override.
This commit is contained in:
Mattias Erming 2014-08-14 09:35:37 -07:00
parent 43b6310481
commit eb7c40276e
5 changed files with 185 additions and 173 deletions

View file

@ -1,5 +1,5 @@
{ {
"port": 9000, "port": 9000,
"theme": "themes/example.css", "theme": "themes/example.css",
"public": true "public": false
} }

View file

@ -8,14 +8,14 @@ var program = require("commander");
var shout = require("./src/server.js"); var shout = require("./src/server.js");
program program
.option("-p, --port <port>"); .option("-p, --port <port>")
.option("-P, --public");
program program
.command("start") .command("start")
.description("Start the server") .description("Start the server")
.action(function() { .action(function() {
var port = program.port || config.port; shout(program.port, program.public);
shout(port);
}); });
program program

View file

@ -1,7 +1,7 @@
{ {
"name": "shout", "name": "shout",
"description": "A web IRC client", "description": "A web IRC client",
"version": "0.9.2", "version": "0.9.3",
"homepage": "http://github.com/erming/shout", "homepage": "http://github.com/erming/shout",
"author": "Mattias Erming", "author": "Mattias Erming",
"preferGlobal": true, "preferGlobal": true,

View file

@ -4,9 +4,19 @@ var Client = require("./client");
module.exports = ClientManager; module.exports = ClientManager;
function ClientManager() { function ClientManager() {
this.clients = {}; this.clients = [];
} }
ClientManager.prototype.findClient = function(name) {
for (var i in this.clients) {
var client = this.clients[i];
if (client.name == name) {
return client;
}
}
return false;
};
ClientManager.prototype.loadUsers = function(sockets) { ClientManager.prototype.loadUsers = function(sockets) {
var users = this.getUsers(); var users = this.getUsers();
for (var i in users) { for (var i in users) {
@ -18,11 +28,11 @@ ClientManager.prototype.loadUsers = function(sockets) {
if (!json) { if (!json) {
continue; continue;
} }
if (!this.clients[name]) { if (!this.findClient(name)) {
this.clients[name] = new Client( this.clients.push(new Client(
sockets, sockets,
json json
); ));
} }
} }
}; };

View file

@ -26,12 +26,14 @@ var inputs = [
"whois" "whois"
]; ];
module.exports = function(port) { module.exports = function(port, public) {
var port = port || config.port || 9000; config.port = port || config.port,
config.public = public || config.public
var app = http() var app = http()
.use(index) .use(index)
.use(http.static("client")) .use(http.static("client"))
.listen(port); .listen(config.port);
sockets = io(app); sockets = io(app);
sockets.on("connect", function(socket) { sockets.on("connect", function(socket) {
@ -43,7 +45,7 @@ module.exports = function(port) {
}); });
console.log(""); console.log("");
console.log("Shout is now running on port " + port); console.log("Shout is now running on port " + config.port);
console.log("Press ctrl-c to stop"); console.log("Press ctrl-c to stop");
console.log(""); console.log("");
@ -100,9 +102,9 @@ function auth(data) {
var socket = this; var socket = this;
if (config.public) { if (config.public) {
var client = new Client(sockets); var client = new Client(sockets);
clients.push(client); manager.clients.push(client);
socket.on("disconnect", function() { socket.on("disconnect", function() {
clients = _.without(clients, client); manager.clients = _.without(manager.clients, client);
client.quit(); client.quit();
}); });
init(socket, client); init(socket, client);