From: Darren Date: Sun, 30 Sep 2012 15:45:44 +0000 (+0100) Subject: Regex reverted back kiwi original X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4e85992dc811caaa2c7ac3029edf9b737f2f1f6b;p=KiwiIRC.git Regex reverted back kiwi original --- diff --git a/client_backbone/dev/model_gateway.js b/client_backbone/dev/model_gateway.js index 45cb41b..5b4de4d 100755 --- a/client_backbone/dev/model_gateway.js +++ b/client_backbone/dev/model_gateway.js @@ -153,7 +153,7 @@ kiwi.model.Gateway = function () { * Parses the response from the server */ this.parse = function (command, data) { - //console.log('gateway event', command, data); + console.log('gateway event', command, data); if (command !== undefined) { that.trigger('on' + command, data); diff --git a/server/client.js b/server/client.js index 5191fb9..e71d6c9 100755 --- a/server/client.js +++ b/server/client.js @@ -47,7 +47,7 @@ module.exports.Client = Client; Client.prototype.sendIRCCommand = function (command, data, callback) { var c = {command: command, data: data}; - console.log('C<--', c); + //console.log('C<--', c); this.websocket.emit('irc', c, callback); }; diff --git a/server/irc-commands.js b/server/irc-commands.js index c882009..fb72fe7 100755 --- a/server/irc-commands.js +++ b/server/irc-commands.js @@ -385,7 +385,12 @@ var listeners = { } } - this.client.sendIRCCommand('mode', {server: this.con_num, target: command.params[0], nick: command.nick, modes: modes}); + this.client.sendIRCCommand('mode', { + server: this.con_num, + target: command.params[0], + nick: command.nick || command.prefix || '', + modes: modes + }); }, 'PRIVMSG': function (command) { /*command.server = this.con_num; diff --git a/server/irc-connection.js b/server/irc-connection.js index d6a0a0e..eade6a4 100755 --- a/server/irc-connection.js +++ b/server/irc-connection.js @@ -83,8 +83,8 @@ var connect_handler = function () { this.emit('connected'); }; -//parse_regex = /^(?::(?:([a-z0-9\x5B-\x60\x7B-\x7D\.\-]+)|([a-z0-9\x5B-\x60\x7B-\x7D\.\-]+)!([a-z0-9~\.\-_|]+)@?([a-z0-9\.\-:\/]+)?) )?(\S+)(?: (?!:)(.+?))?(?: :(.+))?$/i; -alt_regex = /(?::(([0-9a-z][\x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){7}|0:0:0:0:0:(?:0|ffff):\d{1,3}\x2e\d{1,3}\x2e\d{1,3}\x2e\d{1,3}))?)\x20)?([a-z]+|\d{3})((?:\x20[\x01-\t\v\f\x0e-\x1f!-9;-@\x5b-\xff][\x01-\t\v\f\x0e-\x1f!-@\x5b-\xff]*){0,14}(?:\x20:[\x01-\t\v\f\x0e-@\x5b-\xff]*)?|(?:\x20[\x01-\t\v\f\x0e-\x1f!-9;-@\x5b-\xff][\x01-\t\v\f\x0e-\x1f!-@\x5b-\xff]*){14}(?:\x20:?[\x01-\t\v\f\x0e-@\x5b-\xff]*)?)?/i; var parse = function (data) { var i, @@ -109,26 +109,24 @@ var parse = function (data) { } // We have a complete line of data, parse it! - //msg = parse_regex.exec(data[i].replace(/^\r+|\r+$/, '')); - msg2 = alt_regex.exec(data[i].replace(/^\r+|\r+$/, '')); - //console.log(msg2); - if (msg2) { + msg = parse_regex.exec(data[i].replace(/^\r+|\r+$/, '')); + //msg2 = alt_regex.exec(data[i].replace(/^\r+|\r+$/, '')); + console.log('S-->', data[i]); + console.log('Matches', msg); + if (msg) { msg = { - prefix: msg2[1], - nick: msg2[2], - ident: msg2[3], - hostname: msg2[4], - command: msg2[5] + prefix: msg[1], + nick: msg[2], + ident: msg[3], + hostname: msg[4] || '', + command: msg[5], + params: msg[6] || '', + trailing: (msg[7]) ? msg[7].trim() : '' }; - trm = msg2[6].indexOf(':'); - if (trm !== -1){ - msg.params = msg2[6].substr(0, trm - 1).trim().split(" "); - msg.trailing = msg2[6].substr(trm + 1).trim(); - } else { - msg.params = msg2[6].trim().split(" "); - } - console.log('S-->', data[i]); - //console.log(msg); + msg.params = msg.params.split(' '); + + console.log('Parsed', msg); + this.emit('irc_' + msg.command.toUpperCase(), msg); } else { console.log("Malformed IRC line: " + data[i].replace(/^\r+|\r+$/, ''));