No more need to specify a set of available encodings
authorVinicius Daly Felizardo <felizardow@gmail.com>
Sat, 29 Jun 2013 20:44:28 +0000 (16:44 -0400)
committerVinicius Daly Felizardo <felizardow@gmail.com>
Sat, 29 Jun 2013 20:44:28 +0000 (16:44 -0400)
client/assets/src/models/application.js
config.example.js
server/clientcommands.js
server/irc/connection.js

index a3b1392ab4e79f7bdab9cbe37cc578edc615b04b..352be2bb48c994e3368bfccd81b196b8aefb29c8 100644 (file)
@@ -792,9 +792,16 @@ _kiwi.model.Application = function () {
 \r
         function encodingCommand (ev) {\r
             if (ev.params[0]) {\r
-                _kiwi.gateway.setEncoding(null, ev.params[0], function (msg) {\r
-                    _kiwi.app.panels().active.addMsg('', msg);\r
+                _kiwi.gateway.setEncoding(null, ev.params[0], function (success) {\r
+                    if (success) {\r
+                        _kiwi.app.panels().active.addMsg('', "Encoding modified to "+ev.params[0]);\r
+                    } else {\r
+                        _kiwi.app.panels().active.addMsg('', ev.params[0]+' is not a valid encoding');\r
+                    }\r
                 });\r
+            } else {\r
+                _kiwi.app.panels().active.addMsg('', 'Encoding not specified');\r
+                _kiwi.app.panels().active.addMsg('', 'Usage: /encoding [NEW-ENCODING]');\r
             }\r
         }\r
 \r
index 626b80435980b6ba58cda419da683e8126596e56..2ca38eedda8d52412e84ffb74f13881ef5ed1260 100644 (file)
@@ -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
index 493767218be5b10631dfd24d7534102da03644ce..33edeffb79cabf93054688fd7871bf0e5c5cbfb3 100644 (file)
@@ -158,11 +158,7 @@ var listeners = {
 \r
     ENCODING: function (args, irc_connection, callback) {\r
         if (args.encoding) {\r
-            if (irc_connection.setEncoding(args.encoding)) {\r
-                return callback('Encoding modified to '+args.encoding);\r
-            } else {\r
-                return callback(args.encoding+' is not a valid encoding');\r
-            }\r
+            return callback(irc_connection.setEncoding(args.encoding));\r
         }\r
     }\r
 };\r
index d07ffb4db122916e86d86d1be30097a6055624cd..1a722a4d10b60023338d38c76f3edaf6f2cbce4f 100644 (file)
@@ -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;
 };