From 3efb4f3373845c84f55f833f38e19965b161285f Mon Sep 17 00:00:00 2001 From: Vinicius Daly Felizardo Date: Sat, 29 Jun 2013 16:44:28 -0400 Subject: [PATCH] No more need to specify a set of available encodings --- client/assets/src/models/application.js | 11 +++++++++-- config.example.js | 5 ++--- server/clientcommands.js | 6 +----- server/irc/connection.js | 18 +++++++++++++----- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/client/assets/src/models/application.js b/client/assets/src/models/application.js index a3b1392..352be2b 100644 --- a/client/assets/src/models/application.js +++ b/client/assets/src/models/application.js @@ -792,9 +792,16 @@ _kiwi.model.Application = function () { function encodingCommand (ev) { if (ev.params[0]) { - _kiwi.gateway.setEncoding(null, ev.params[0], function (msg) { - _kiwi.app.panels().active.addMsg('', msg); + _kiwi.gateway.setEncoding(null, ev.params[0], function (success) { + if (success) { + _kiwi.app.panels().active.addMsg('', "Encoding modified to "+ev.params[0]); + } else { + _kiwi.app.panels().active.addMsg('', ev.params[0]+' is not a valid encoding'); + } }); + } else { + _kiwi.app.panels().active.addMsg('', 'Encoding not specified'); + _kiwi.app.panels().active.addMsg('', 'Usage: /encoding [NEW-ENCODING]'); } } diff --git a/config.example.js b/config.example.js index 626b804..2ca38ee 100644 --- a/config.example.js +++ b/config.example.js @@ -61,11 +61,10 @@ conf.max_client_conns = 5; conf.max_server_conns = 0; /* -* Available encodings supported by the server +* Default encoding to be used by the server * As specified and limited to iconv-lite library support. -* All upper-case. Default is the first element on the list. */ -conf.available_encodings = ['UTF-8', 'WINDOWS-1252']; +conf.default_encoding = 'UTF-8'; /* * Client side plugins diff --git a/server/clientcommands.js b/server/clientcommands.js index 4937672..33edeff 100644 --- a/server/clientcommands.js +++ b/server/clientcommands.js @@ -158,11 +158,7 @@ var listeners = { ENCODING: function (args, irc_connection, callback) { if (args.encoding) { - if (irc_connection.setEncoding(args.encoding)) { - return callback('Encoding modified to '+args.encoding); - } else { - return callback(args.encoding+' is not a valid encoding'); - } + return callback(irc_connection.setEncoding(args.encoding)); } } }; diff --git a/server/irc/connection.js b/server/irc/connection.js index d07ffb4..1a722a4 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -31,7 +31,7 @@ var IrcConnection = function (hostname, port, ssl, nick, user, pass, state) { this.setMaxListeners(0); // Set the first configured encoding as the default encoding - this.encoding = global.config.available_encodings[0]; + this.encoding = global.config.default_encoding; // Socket state this.connected = false; @@ -260,11 +260,19 @@ IrcConnection.prototype.disposeSocket = function () { */ IrcConnection.prototype.setEncoding = function (encoding) { - if (global.config.available_encodings.indexOf(encoding.toUpperCase()) >= 0) { - this.encoding = encoding.toUpperCase(); - return true; + try { + encoded_test = iconv.encode("TEST", encoding); + //This test is done to check if this encoding also supports + //the ASCII charset required by the IRC protocols + //(Avoid the use of base64 or incompatible encodings) + if (encoded_test == "TEST") { + this.encoding = encoding; + return true; + } + return false; + } catch (err) { + return false; } - return false; }; -- 2.25.1