From cc54c0a1cdd40941c0782dd50210cd48251ec9dd Mon Sep 17 00:00:00 2001 From: Darren Date: Fri, 23 Aug 2013 20:07:02 +0100 Subject: [PATCH] Client: Encoding within the URL --- client/assets/src/models/application.js | 3 +++ client/assets/src/models/gateway.js | 4 ++++ client/assets/src/models/newconnection.js | 3 ++- client/assets/src/views/serverselect.js | 9 ++++++++- server/client.js | 10 ++++++++-- server/irc/connection.js | 16 ++++++++++------ server/irc/state.js | 4 ++-- 7 files changed, 37 insertions(+), 12 deletions(-) diff --git a/client/assets/src/models/application.js b/client/assets/src/models/application.js index 7269e46..70e1060 100644 --- a/client/assets/src/models/application.js +++ b/client/assets/src/models/application.js @@ -297,6 +297,9 @@ _kiwi.model.Application = function () { // Set any random numbers if needed defaults.nick = defaults.nick.replace('?', Math.floor(Math.random() * 100000).toString()); + if (getQueryVariable('encoding')) + defaults.encoding = getQueryVariable('encoding'); + // Populate the server select box with defaults new_connection_dialog.view.populateFields(defaults); }; diff --git a/client/assets/src/models/gateway.js b/client/assets/src/models/gateway.js index eddbc60..a2cc8b2 100644 --- a/client/assets/src/models/gateway.js +++ b/client/assets/src/models/gateway.js @@ -290,6 +290,10 @@ _kiwi.model.Gateway = function () { password: connection_info.password }; + // A few optional parameters + if (connection_info.options.encoding) + server_info.encoding = connection_info.options.encoding; + this.socket.emit('kiwi', server_info, function (err, server_num) { if (!err) { callback_fn && callback_fn(err, server_num); diff --git a/client/assets/src/models/newconnection.js b/client/assets/src/models/newconnection.js index 5bf64ca..d829f94 100644 --- a/client/assets/src/models/newconnection.js +++ b/client/assets/src/models/newconnection.js @@ -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); }); diff --git a/client/assets/src/views/serverselect.js b/client/assets/src/views/serverselect.js index 6340e6b..5a2544b 100644 --- a/client/assets/src/views/serverselect.js +++ b/client/assets/src/views/serverselect.js @@ -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 () { diff --git a/server/client.js b/server/client.js index 0ae4f50..c9c1382 100755 --- a/server/client.js +++ b/server/client.js @@ -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'); diff --git a/server/irc/connection.js b/server/irc/connection.js index 1346a2f..d448e83 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -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+$/, '')); diff --git a/server/irc/state.js b/server/irc/state.js index 77ad4cb..f8b7ca9 100755 --- a/server/irc/state.js +++ b/server/irc/state.js @@ -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); -- 2.25.1