Client: Encoding within the URL
authorDarren <darren@darrenwhitlen.com>
Fri, 23 Aug 2013 19:07:02 +0000 (20:07 +0100)
committerDarren <darren@darrenwhitlen.com>
Fri, 23 Aug 2013 19:07:02 +0000 (20:07 +0100)
client/assets/src/models/application.js
client/assets/src/models/gateway.js
client/assets/src/models/newconnection.js
client/assets/src/views/serverselect.js
server/client.js
server/irc/connection.js
server/irc/state.js

index 7269e461ab471628762a80093175a94870ef98a1..70e1060fc25ab4f921cee746318cdab8be83e874 100644 (file)
@@ -297,6 +297,9 @@ _kiwi.model.Application = function () {
             // Set any random numbers if needed\r
             defaults.nick = defaults.nick.replace('?', Math.floor(Math.random() * 100000).toString());\r
 \r
+            if (getQueryVariable('encoding'))\r
+                defaults.encoding = getQueryVariable('encoding');\r
+\r
             // Populate the server select box with defaults\r
             new_connection_dialog.view.populateFields(defaults);\r
         };\r
index eddbc60568ef3854f4e77f3f8fc5e7fb8a3fbc59..a2cc8b2e5a1f16584e323d14b4444cc0b19b74c3 100644 (file)
@@ -290,6 +290,10 @@ _kiwi.model.Gateway = function () {
             password:   connection_info.password\r
         };\r
 \r
+        // A few optional parameters\r
+        if (connection_info.options.encoding)\r
+            server_info.encoding = connection_info.options.encoding;\r
+\r
         this.socket.emit('kiwi', server_info, function (err, server_num) {\r
             if (!err) {\r
                 callback_fn && callback_fn(err, server_num);\r
index 5bf64cab596182ff4aa812543f3684c286501b54..d829f944d6fb405524dd4cd3a83920746fec70f7 100644 (file)
@@ -55,7 +55,8 @@ _kiwi.model.NewConnection = Backbone.Collection.extend({
             host: new_connection_event.server,
             port: new_connection_event.port,
             ssl: new_connection_event.ssl,
-            password: new_connection_event.password
+            password: new_connection_event.password,
+            options: new_connection_event.options
         }, function(err, network) {
             that.onNewNetwork(err, network);
         });
index 6340e6bfabe60c4ed28a479d6925ac60dc417f5d..5a2544b89186bf56e2190bb0a42324bdec6c4745 100644 (file)
@@ -85,7 +85,8 @@ _kiwi.view.ServerSelect = function () {
                 ssl: $('input.ssl', this.$el).prop('checked'),
                 password: $('input.password', this.$el).val(),
                 channel: $('input.channel', this.$el).val(),
-                channel_key: $('input.channel_key', this.$el).val()
+                channel_key: $('input.channel_key', this.$el).val(),
+                options: this.server_options
             };
 
             this.trigger('server_connect', values);
@@ -164,6 +165,12 @@ _kiwi.view.ServerSelect = function () {
             if (!(!channel_key)) {
                 $('tr.key', this.$el).show();
             }
+
+            // Temporary values
+            this.server_options = {};
+
+            if (defaults.encoding)
+                this.server_options.encoding = defaults.encoding;
         },
 
         hide: function () {
index 0ae4f50dcab978c1a6479d5e4450c468be1b3ff1..c9c13827234c946411f6b13a0136f7d01a0275ae 100755 (executable)
@@ -113,7 +113,13 @@ function kiwiCommand(command, callback) {
     switch (command.command) {
         case 'connect':
             if (command.hostname && command.port && command.nick) {
-                var con;
+                var options = {};
+
+                // Get any optional parameters that may have been passed
+                if (command.encoding)
+                    options.encoding = command.encoding;
+
+                options.password = global.config.restrict_server_password || command.password;
 
                 this.state.connect(
                     (global.config.restrict_server || command.hostname),
@@ -123,7 +129,7 @@ function kiwiCommand(command, callback) {
                         command.ssl),
                     command.nick,
                     {hostname: this.websocket.handshake.revdns, address: this.websocket.handshake.real_address},
-                    (global.config.restrict_server_password || command.password),
+                    options,
                     callback);
             } else {
                 return callback('Hostname, port and nickname must be specified');
index 1346a2fc233cca62cc376185db4d3bb65ba01ded..d448e83c089d794342276cf654e010037146ddd8 100644 (file)
@@ -23,7 +23,7 @@ if (version_values[1] >= 10) {
     Socks = require('socksjs');
 }
 
-var IrcConnection = function (hostname, port, ssl, nick, user, pass, state, con_num) {
+var IrcConnection = function (hostname, port, ssl, nick, user, options, state, con_num) {
     var that = this;
 
     EE.call(this,{
@@ -32,9 +32,8 @@ var IrcConnection = function (hostname, port, ssl, nick, user, pass, state, con_
     });
     this.setMaxListeners(0);
 
-    // Set the first configured encoding as the default encoding
-    this.encoding = global.config.default_encoding;
-    
+    options = options || {};
+
     // Socket state
     this.connected = false;
 
@@ -57,7 +56,12 @@ var IrcConnection = function (hostname, port, ssl, nick, user, pass, state, con_
     this.nick = nick;
     this.user = user;  // Contains users real hostname and address
     this.username = this.nick.replace(/[^0-9a-zA-Z\-_.\/]/, '');
-    this.password = pass;
+    this.password = options.password || '';
+
+    // Set the passed encoding. or the default if none giving or it fails
+    if (!options.encoding || !this.setEncoding(options.encoding)) {
+        this.setEncoding(global.config.default_encoding);
+    }
 
     // State object
     this.state = state;
@@ -670,7 +674,7 @@ var parse = function (data) {
         line = iconv.decode(bufs[i], this.encoding);
         bufs[i] = null;
         if (!line) break;
-        
+
         // Parse the complete line, removing any carriage returns
         msg = parse_regex.exec(line.replace(/^\r+|\r+$/, ''));
 
index 77ad4cb031ee7be5d946357cc8eabcd30da588d8..f8b7ca9bd70943f8eae1ecaa63af61c435a5ba93 100755 (executable)
@@ -32,7 +32,7 @@ util.inherits(State, events.EventEmitter);
 
 module.exports = State;
 
-State.prototype.connect = function (hostname, port, ssl, nick, user, pass, callback) {
+State.prototype.connect = function (hostname, port, ssl, nick, user, options, callback) {
     var that = this;
     var con, con_num;
 
@@ -53,7 +53,7 @@ State.prototype.connect = function (hostname, port, ssl, nick, user, pass, callb
         ssl,
         nick,
         user,
-        pass,
+        options,
         this,
         con_num);