From a626acfad17edb77a22c24ff825c42d950f5893a Mon Sep 17 00:00:00 2001 From: NanoSector Date: Mon, 22 Apr 2019 21:20:05 +0200 Subject: [PATCH] Add UserModeParser from irc-project to fix NamReply bug with userhost-in-names Signed-off-by: NanoSector --- src/RPL/NamReply.php | 5 +++- src/Utility/UserModeParser.php | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/Utility/UserModeParser.php diff --git a/src/RPL/NamReply.php b/src/RPL/NamReply.php index 1e01dc1..48c708b 100644 --- a/src/RPL/NamReply.php +++ b/src/RPL/NamReply.php @@ -18,6 +18,7 @@ use WildPHP\Messages\Traits\ChannelTrait; use WildPHP\Messages\Traits\NicknameTrait; use WildPHP\Messages\Traits\ServerTrait; +use WildPHP\Messages\Utility\UserModeParser; /** * Class RPL_NAMREPLY @@ -72,7 +73,9 @@ public static function fromIncomingMessage(IrcMessageInterface $incomingMessage) $prefixes = []; foreach ($nicknames as $key => $prefixString) { - $prefix = Prefix::fromString($prefixString); + $prefixStringNoModes = ''; + UserModeParser::extractFromNickname($prefixString, $prefixStringNoModes); + $prefix = Prefix::fromString($prefixStringNoModes); // no nickname means this isn't a full prefix. do not try any further. if (empty($prefix->getNickname())) { diff --git a/src/Utility/UserModeParser.php b/src/Utility/UserModeParser.php new file mode 100644 index 0000000..476fefc --- /dev/null +++ b/src/Utility/UserModeParser.php @@ -0,0 +1,47 @@ + 'o', + '%' => 'h', + '+' => 'v' + ]; + + /** + * @param string $nickname + * @param string $remainders + * + * @return array + */ + public static function extractFromNickname(string $nickname, string &$remainders): array + { + $parts = str_split($nickname); + $modes = []; + + foreach ($parts as $key => $part) { + if (!array_key_exists($part, self::$prefixMap)) { + $remainders = implode('', $parts); + break; + } + + unset($parts[$key]); + $modes[] = self::$prefixMap[$part]; + } + + return $modes; + } +}