\r
controlbox.on('command:whowas', whowasCommand);\r
\r
+ controlbox.on('command:encoding', encodingCommand);\r
\r
controlbox.on('command:css', function (ev) {\r
var queryString = '?reload=' + new Date().getTime();\r
_kiwi.app.connections.active_connection.gateway.raw('WHOWAS ' + nick);\r
}\r
\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
+ });\r
+ }\r
+ }\r
\r
function serverCommand (ev) {\r
var server, port, ssl, password, nick,\r
});\r
};\r
\r
-\r
-\r
this.isConnected = function () {\r
return this.socket.socket.connected;\r
};\r
this.sendData(connection_id, data, callback);\r
};\r
\r
+ /**\r
+ * Sends ENCODING change request to server.\r
+ * @param {String} new_encoding The new proposed encode\r
+ * @param {Fucntion} callback A callback function\r
+ */\r
+ this.setEncoding = function (connection_id, new_encoding, callback) {\r
+ var data = {\r
+ method: 'encoding',\r
+ args: {\r
+ encoding: new_encoding\r
+ }\r
+ };\r
+\r
+ this.sendData(connection_id, data, callback);\r
+ };\r
+\r
/**\r
* Sends data to a fellow Kiwi IRC user\r
* @param {String} target The nick of the Kiwi IRC user to send to\r
this.sendData(data, callback);\r
};\r
\r
-\r
// Check a nick alongside our ignore list\r
this.isNickIgnored = function (nick) {\r
var idx, list = this.get('ignore_list');\r
\r
\r
return new (Backbone.Model.extend(this))(arguments);\r
-};
\ No newline at end of file
+};\r
// - Kiwi is running in restricted server mode.
conf.max_server_conns = 0;
+/*
+* Available encodings supported 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'];
/*
* Client side plugins
if ((args.target) && (args.data)) {\r
irc_connection.write('PRIVMSG ' + args.target + ': ' + String.fromCharCode(1) + 'KIWI ' + args.data + String.fromCharCode(1), callback);\r
}\r
+ },\r
+\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
+ }\r
}\r
};\r
});
this.setMaxListeners(0);
+ // Set the first configured encoding as the default encoding
+ this.encoding = global.config.available_encodings[0];
+
// Socket state
this.connected = false;
*/
IrcConnection.prototype.write = function (data, callback) {
//ENCODE string to encoding of the server
- encoded_buffer = iconv.encode(data + '\r\n', "windows-1252");
+ encoded_buffer = iconv.encode(data + '\r\n', this.encoding);
this.socket.write(encoded_buffer);
};
}
};
+/**
+ * Set a new encoding for this connection
+ * Return true in case of success
+ */
+
+IrcConnection.prototype.setEncoding = function (encoding) {
+ if (global.config.available_encodings.indexOf(encoding.toUpperCase()) >= 0) {
+ this.encoding = encoding.toUpperCase();
+ return true;
+ }
+ return false;
+};
function onChannelJoin(event) {
tag;
//DECODE server encoding
- data = iconv.decode(data, 'windows-1252');
+ data = iconv.decode(data, this.encoding);
console.log(data);
+
if (this.hold_last && this.held_data !== '') {
data = this.held_data + data;
this.hold_last = false;