Option to restrict connections to 1 server
authorDarren <darren@darrenwhitlen.com>
Thu, 8 Nov 2012 02:23:30 +0000 (02:23 +0000)
committerDarren <darren@darrenwhitlen.com>
Thu, 8 Nov 2012 02:23:30 +0000 (02:23 +0000)
client/assets/css/style.css
client/assets/dev/build.js
client/assets/dev/index.html.tmpl
client/assets/dev/model_application.js
client/assets/dev/view.js
config.js
server/client.js

index 0a1719499bf126a80cacd78508091934d771b6e9..ec5f62d2007a7422ca302bc857bfa455b28d81d0 100644 (file)
@@ -223,6 +223,7 @@ a img { border:none; }
 .server_select .basic label { font-size:1.3em; margin-top:4px; }
 .server_select .basic { border-bottom: 1px dashed gray; margin-bottom:1em; }
 .server_select .basic .show_more { display: block; width:40px; margin:10px 0 0 0; font-size:0.8em; background: url(../img/more.png) no-repeat right 7px; }
+.server_select.single_server .basic { border:none; }
 .server_select .status { text-align: center; font-weight: bold; padding:1em; }
 .server_select .status .ok {
     border:1px solid #A33F3F; background-color:#D28A8A;
index be386f4ef71264ba610236065f159074983dec81..8e75dcabbb564c24aa15f4e7b753d703f2ce9f80 100644 (file)
@@ -84,9 +84,23 @@ console.log('kiwi.js and kiwi.min.js built');
 var index_src = fs.readFileSync(__dirname + '/index.html.tmpl', FILE_ENCODING);\r
 var vars = {\r
     base_path: config.get().http_base_path,\r
-    cache_buster: Math.ceil(Math.random() * 9000).toString()\r
+    cache_buster: Math.ceil(Math.random() * 9000).toString(),\r
+    server_settings: '{}'\r
 };\r
 \r
+if (config.get().restrict_server) {\r
+    vars.server_settings = JSON.stringify({\r
+        connection: {\r
+            server: config.get().restrict_server,\r
+            port: config.get().restrict_server_port || 6667,\r
+            ssl: config.get().restrict_server_ssl,\r
+            channel: config.get().restrict_server_channel,\r
+            nick: config.get().restrict_server_nick,\r
+            allow_change: false\r
+        }\r
+    });\r
+}\r
+\r
 _.each(vars, function(value, key) {\r
     index_src = index_src.replace(new RegExp('<%' + key + '%>', 'g'), value);\r
 });\r
index 054aa574b334ccc844cd023b4970eec6cba64bd5..7b6f311e5a18a774354af1de680faf99367fa1c9 100644 (file)
         function startApp () {\r
             var opts = {\r
                 container: $('#kiwi'),\r
-                base_path: base_path\r
+                base_path: base_path,\r
 \r
                 // Override the kiwi_server to use. (Think: running on standalone client..)\r
-                //kiwi_server: 'http://kiwiirc.com:80'\r
+                //kiwi_server: 'http://kiwiirc.com:80',\r
+\r
+                server_settings: <%server_settings%>\r
             };\r
 \r
             // Start the app\r
index b08ea49837dbc58540eda8eadcb79026be01394b..9eeedcc3413a0be9c9790a027d97f273fe6a31fb 100644 (file)
@@ -29,6 +29,9 @@ _kiwi.model.Application = function () {
             // The base url to the kiwi server\r
             this.set('base_path', options[0].base_path ? options[0].base_path : '/kiwi');\r
 \r
+            // Any options sent down from the server\r
+            this.server_settings = options[0].server_settings || {};\r
+\r
             // Best guess at where the kiwi server is\r
             this.detectKiwiServer();\r
         };\r
@@ -217,6 +220,30 @@ _kiwi.model.Application = function () {
                 }\r
             }\r
 \r
+            // If any settings have been given by the server.. override any auto detected settings\r
+            if (this.server_settings && this.server_settings.connection) {\r
+                if (this.server_settings.connection.server) {\r
+                    defaults.server = this.server_settings.connection.server;\r
+                }\r
+\r
+                if (this.server_settings.connection.port) {\r
+                    defaults.port = this.server_settings.connection.port;\r
+                }\r
+\r
+                if (this.server_settings.connection.ssl) {\r
+                    defaults.ssl = this.server_settings.connection.ssl;\r
+                }\r
+\r
+                if (this.server_settings.connection.channel) {\r
+                    defaults.channel = this.server_settings.connection.channel;\r
+                }\r
+\r
+                if (this.server_settings.connection.nick) {\r
+                    defaults.nick = this.server_settings.connection.nick;\r
+                }\r
+            }\r
+console.log('defaults', defaults, this.server_settings);\r
+\r
             // Set any random numbers if needed\r
             defaults.nick = defaults.nick.replace('?', Math.floor(Math.random() * 100000).toString());\r
 \r
index 3c8db34146f0fc47f1bc2780177a156e01b3739f..68b4c4152a24aead2e28e2c7845a94224c3e8018 100644 (file)
@@ -107,6 +107,15 @@ _kiwi.view.ServerSelect = function () {
         initialize: function () {\r
             this.$el = $($('#tmpl_server_select').html());\r
 \r
+            // Remove the 'more' link if the server has disabled server changing\r
+            if (_kiwi.app.server_settings && _kiwi.app.server_settings.connection) {\r
+                if (!_kiwi.app.server_settings.connection.allow_change) {\r
+                    this.$el.find('.show_more').remove();\r
+                    this.$el.addClass('single_server');\r
+                }\r
+            }\r
+\r
+\r
             _kiwi.gateway.bind('onconnect', this.networkConnected, this);\r
             _kiwi.gateway.bind('connecting', this.networkConnecting, this);\r
 \r
index 68376411ae289f6aa4c627b4b89697f6f181a483..5becf375ba03144888b7fd3930194d790263d112 100644 (file)
--- a/config.js
+++ b/config.js
@@ -95,7 +95,13 @@ conf.http_base_path = "/kiwi";
 conf.quit_message = "http://www.kiwiirc.com/ - A hand-crafted IRC client";
 
 
-
+// If not empty, the client may only connect to this 1 IRC server
+//conf.restrict_server = "irc.kiwiirc.com";
+//conf.restrict_server_port = 6667;
+//conf.restrict_server_ssl = false;
+//conf.restrict_server_channel = "#kiwiirc";
+//conf.restrict_server_password = "";
+//conf.restrict_server_nick = "kiwi_";
 
 
 /*
index 0a530bca77ca354c70ccd9fbc333674cbb533b96..27aa0565b70ba361340979e8e0edd7a890c2cb2f 100755 (executable)
@@ -110,38 +110,55 @@ function kiwiCommand(command, callback) {
         callback = function () {};
     }
     switch (command.command) {
-               case 'connect':
-                       if (command.hostname && command.port && command.nick) {
-                               var con = new IrcConnection(command.hostname, command.port, command.ssl,
-                                       command.nick, {hostname: this.websocket.handshake.revdns, address: this.websocket.handshake.real_address},
-                                       command.password);
-
-                               var con_num = this.next_connection++;
-                               this.irc_connections[con_num] = con;
-
-                               var irc_commands = new IrcCommands(con, con_num, this);
-                               irc_commands.bindEvents();
-                               
-                               con.on('connected', function () {
-                                       return callback(null, con_num);
-                               });
-                               
-                               con.on('error', function (err) {
+        case 'connect':
+            if (command.hostname && command.port && command.nick) {
+                var con;
+
+                if (global.config.restrict_server) {
+                    con = new IrcConnection(
+                        global.config.restrict_server,
+                        global.config.restrict_server_port,
+                        global.config.restrict_server_ssl,
+                        command.nick,
+                        {hostname: this.websocket.handshake.revdns, address: this.websocket.handshake.real_address},
+                        global.config.restrict_server_password);
+
+                } else {
+                    con = new IrcConnection(
+                        command.hostname,
+                        command.port,
+                        command.ssl,
+                        command.nick,
+                        {hostname: this.websocket.handshake.revdns, address: this.websocket.handshake.real_address},
+                        command.password);
+                }
+
+                var con_num = this.next_connection++;
+                this.irc_connections[con_num] = con;
+
+                var irc_commands = new IrcCommands(con, con_num, this);
+                irc_commands.bindEvents();
+                
+                con.on('connected', function () {
+                    return callback(null, con_num);
+                });
+                
+                con.on('error', function (err) {
                     console.log('irc_connection error (' + command.hostname + '):', err);
                     // TODO: Once multiple servers implemented, specify which server failed
                     //that.sendKiwiCommand('error', {server: con_num, error: err});
                     return callback(err.code, null);
-                               });
+                });
                 
                 con.on('close', function () {
                     that.irc_connections[con_num] = null;
                 });
-                       } else {
-                               return callback('Hostname, port and nickname must be specified');
-                       }
-               break;
-               default:
-                       callback();
+            } else {
+                return callback('Hostname, port and nickname must be specified');
+            }
+        break;
+        default:
+            callback();
     }
 }