iconv-lite installed and coverting from a specific encoding
authorVinicius Daly Felizardo <felizardow@gmail.com>
Tue, 18 Jun 2013 07:22:24 +0000 (03:22 -0400)
committerVinicius Daly Felizardo <felizardow@gmail.com>
Tue, 18 Jun 2013 07:22:24 +0000 (03:22 -0400)
package.json
server/irc/connection.js

index 25472f9ff28a82511d88b808ba1f5271ddb4e72d..95c5937393c1428cb42b69a6692a7e8f4940f108 100644 (file)
@@ -21,6 +21,7 @@
     "daemonize2": "0.4.0-rc.5",\r
     "eventemitter2": "0.4.11",\r
     "ipaddr.js": "0.1.1",\r
-    "socksjs": "0.3.3"\r
+    "socksjs": "0.3.3",\r
+    "iconv-lite" : "0.2.10"\r
   }\r
 }\r
index 407e6e9253339385b10272300cf90f9716da68db..a7202bd64f93d83ed215636c13306e64fbf5a3b2 100644 (file)
@@ -7,6 +7,7 @@ var net             = require('net'),
     IrcChannel      = require('./channel.js'),
     IrcUser         = require('./user.js'),
     EE              = require('../ee.js'),
+    iconv           = require('iconv-lite'),
     Socks;
 
 
@@ -167,8 +168,6 @@ IrcConnection.prototype.connect = function () {
         socketConnectHandler.call(that);
     });
 
-    this.socket.setEncoding('utf-8');
-
     this.socket.on('error', function (event) {
         that.emit('error', event);
     });
@@ -198,7 +197,9 @@ IrcConnection.prototype.clientEvent = function (event_name, data, callback) {
  * Write a line of data to the IRCd
  */
 IrcConnection.prototype.write = function (data, callback) {
-    this.socket.write(data + '\r\n', 'utf-8', callback);
+    //ENCODE string to encoding of the server
+    encoded_buffer = iconv.encode(data + '\r\n', "windows-1252");
+    this.socket.write(encoded_buffer);
 };
 
 
@@ -424,6 +425,9 @@ var parse = function (data) {
         tags = [],
         tag;
 
+    //DECODE server encoding 
+    data = iconv.decode(data, 'windows-1252');
+    console.log(data);
     if (this.hold_last && this.held_data !== '') {
         data = this.held_data + data;
         this.hold_last = false;
@@ -445,7 +449,7 @@ var parse = function (data) {
             this.held_data = data[i];
             break;
         }
-
+        
         // Parse the complete line, removing any carriage returns
         msg = parse_regex.exec(data[i].replace(/^\r+|\r+$/, ''));