From 1a452a0275d03c207a61e16f7d9078f2326b445e Mon Sep 17 00:00:00 2001 From: Vinicius Daly Felizardo Date: Tue, 18 Jun 2013 03:22:24 -0400 Subject: [PATCH] iconv-lite installed and coverting from a specific encoding --- package.json | 3 ++- server/irc/connection.js | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 25472f9..95c5937 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "daemonize2": "0.4.0-rc.5", "eventemitter2": "0.4.11", "ipaddr.js": "0.1.1", - "socksjs": "0.3.3" + "socksjs": "0.3.3", + "iconv-lite" : "0.2.10" } } diff --git a/server/irc/connection.js b/server/irc/connection.js index 407e6e9..a7202bd 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -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+$/, '')); -- 2.25.1