Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -r 63a96ee6f193 chat/protocols/irc/irc.js
- --- a/chat/protocols/irc/irc.js Mon Jun 29 22:00:54 2015 +0100
- +++ b/chat/protocols/irc/irc.js Tue Jun 30 23:28:32 2015 +0200
- @@ -46,9 +46,10 @@
- let message = {rawMessage: aData};
- let temp;
- - // Splits the raw string into four parts (the second is required), the command
- + // Splits the raw string into five parts (the third is required), the command
- // is required. A raw string looks like:
- - // [":" <prefix> " "] <command> [" " <parameter>]* [":" <last parameter>]
- + // [ "@" <tags> " " ] [":" <prefix> " "] <command> [" " <parameter>]* [":" <last parameter>]
- + // <tags>: /[^ ]+/
- // <prefix>: :(<server name> | <nickname> [["!" <user>] "@" <host>])
- // <command>: /[^ ]+/
- // <parameter>: /[^ ]+/
- @@ -60,26 +61,49 @@
- // (This is for compatibility with Unreal's 432 response, which returns an
- // empty first parameter.) It also allows a trailing space after the
- // <parameter>s when no <last parameter> is present (also occurs with Unreal).
- - if (!(temp = aData.match(/^(?::([^ ]+) )?([^ ]+)((?: +[^: ][^ ]*)*)? *(?::([\s\S]*))?$/)))
- + if (!(temp = aData.match(/^(?:@([^ ]+) )?(?::([^ ]+) )?([^ ]+)((?: +[^: ][^ ]*)*)? *(?::([\s\S]*))?$/)))
- throw "Couldn't parse message: \"" + aData + "\"";
- - message.command = temp[2];
- + message.command = temp[3];
- // Space separated parameters. Since we expect a space as the first thing
- // here, we want to ignore the first value (which is empty).
- - message.params = temp[3] ? temp[3].split(" ").slice(1) : [];
- + message.params = temp[4] ? temp[4].split(" ").slice(1) : [];
- // Last parameter can contain spaces or be an empty string.
- - if (temp[4] != undefined)
- - message.params.push(temp[4]);
- + if (temp[5] != undefined)
- + message.params.push(temp[5]);
- // Handle the prefix part of the message per RFC 2812 Section 2.3.
- // If no prefix is given, assume the current server is the origin.
- - if (!temp[1])
- - temp[1] = aOrigin;
- + if (!temp[2])
- + temp[2] = aOrigin;
- // Split the prefix into separate nickname, username and hostname fields as:
- // :(servername|(nickname[[!user]@host]))
- - [message.origin, message.user, message.host] = temp[1].split(/[!@]/);
- + [message.origin, message.user, message.host] = temp[2].split(/[!@]/);
- +
- + // Store the tags in a Map, if there are tags
- + // For the tags spec, see IRCv3.2 Message Tags
- + message.tags = new Map();
- + if(temp[1]) {
- + let tags = temp[1].split(";");
- + tags.forEach((tag) => {
- + tag = tag.split("=");
- + if(tag.length > 1) {
- + message.tags.set(
- + tag[0],
- + tag[1].replace(/(?:[^\\]|^)\\:/g, ";")
- + .replace(/(?:[^\\]|^)\\s/g, " ")
- + .replace(/(?:[^\\]|^)\\r/g, "\r")
- + .replace(/(?:[^\\]|^)\\n/g, "\n")
- + .replace(/\\/g, "\")
- + );
- + }
- + else {
- + message.tags.set(tag[0], null);
- + }
- + });
- + }
- // It is occasionally useful to have a "source" which is a combination of
- // user@host.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement