Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #19 from Renegade334/devel-mode-params
Browse files Browse the repository at this point in the history
Change MODE parameter processing
  • Loading branch information
elazar committed Mar 30, 2015
2 parents 7d524d7 + 959f692 commit d233d03
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function __construct()
'SQUIT' => "/^(?:(?P<server>$middle)(?P<comment>$trailing))$/",
'JOIN' => "/^(?:(?P<channels>$middle|$trailing)(?P<keys>$trailing)?)$/",
'PART' => "/^(?:(?P<channels>$middle|$trailing)(?P<message>$trailing)?)$/",
'MODE' => "/^(?:(?P<target>$middle)(?P<mode>$middle|$trailing)(?P<param>$trailing)?)$/",
'MODE' => "/^(?:(?P<target>$middle)(?P<mode>$middle|$trailing)(?P<params>$trailing)?)$/",
'TOPIC' => "/^(?:(?P<channel>$middle|$trailing)(?P<topic>$trailing)?)$/",
'NAMES' => "/^(?:(?P<channels>$trailing))$/",
'LIST' => "/^(?:(?:(?P<channels>$trailing)|$middle)?(?P<server>$trailing)?)$/",
Expand Down Expand Up @@ -349,20 +349,31 @@ public function parse($message)
case 'MODE':
if (preg_match('/^' . $this->channel . '$/', $params['target'])) {
$params['channel'] = $params['target'];
if (strpos($params['mode'], 'l') !== false) {
$params['limit'] = $params['param'];
} elseif (strpos($params['mode'], 'b') !== false
&& !empty($params['param'])) {
$params['banmask'] = $params['param'];
} elseif (strpos($params['mode'], 'k') !== false) {
$params['key'] = $params['param'];
} elseif (isset($params['param'])) {
$params['user'] = $params['param'];

/* Assign the value of $params['params'] to a named parameter if
* only one channel mode is being set.
* This functionality is DEPRECATED, and will not occur if more than one
* channel mode is being set. Use $params['params'] instead. */
if (strlen($params['mode']) == 2 && isset($params['params'])) {
switch ($params['mode']{1}) {
case 'l':
$params['limit'] = $params['params'];
break;
case 'b':
$params['banmask'] = $params['params'];
break;
case 'k':
$params['key'] = $params['params'];
break;
default:
$params['user'] = $params['params'];
break;
}
}
} else {
$params['user'] = $params['target'];
}
unset($params['target'], $params['param']);
unset($params['target']);
break;
// Handle CTCP messages
case 'PRIVMSG':
Expand Down
104 changes: 104 additions & 0 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ public function dataProviderTestParse()
'params' => array(
'channel' => '#Finnish',
'mode' => '+o',
'params' => 'Kilroy',
'user' => 'Kilroy',
'all' => '#Finnish +o :Kilroy',
),
Expand All @@ -470,13 +471,42 @@ public function dataProviderTestParse()
'params' => array(
'channel' => '#Finnish',
'mode' => '+v',
'params' => 'Wiz',
'user' => 'Wiz',
'all' => '#Finnish +v :Wiz',
),
'targets' => array('#Finnish'),
),
),

array(
"MODE #Finnish +ov :Kilroy Wiz\r\n",
array(
'command' => 'MODE',
'params' => array(
'channel' => '#Finnish',
'mode' => '+ov',
'params' => 'Kilroy Wiz',
'all' => '#Finnish +ov :Kilroy Wiz',
),
'targets' => array('#Finnish'),
),
),

array(
"MODE #Finnish +mvv-v :Kilroy Wiz Angel\r\n",
array(
'command' => 'MODE',
'params' => array(
'channel' => '#Finnish',
'mode' => '+mvv-v',
'params' => 'Kilroy Wiz Angel',
'all' => '#Finnish +mvv-v :Kilroy Wiz Angel',
),
'targets' => array('#Finnish'),
),
),

array(
"MODE #Fins :-s\r\n",
array(
Expand All @@ -497,27 +527,57 @@ public function dataProviderTestParse()
'params' => array(
'channel' => '#42',
'mode' => '+k',
'params' => 'oulu',
'key' => 'oulu',
'all' => '#42 +k :oulu',
),
'targets' => array('#42'),
),
),

array(
"MODE #42 +ks :oulu\r\n",
array(
'command' => 'MODE',
'params' => array(
'channel' => '#42',
'mode' => '+ks',
'params' => 'oulu',
'all' => '#42 +ks :oulu',
),
'targets' => array('#42'),
),
),

array(
"MODE #eu-opers +l :10\r\n",
array(
'command' => 'MODE',
'params' => array(
'channel' => '#eu-opers',
'mode' => '+l',
'params' => '10',
'limit' => '10',
'all' => '#eu-opers +l :10',
),
'targets' => array('#eu-opers'),
),
),

array(
"MODE #eu-opers +lL :10 #eu-opers-overflow\r\n",
array(
'command' => 'MODE',
'params' => array(
'channel' => '#eu-opers',
'mode' => '+lL',
'params' => '10 #eu-opers-overflow',
'all' => '#eu-opers +lL :10 #eu-opers-overflow',
),
'targets' => array('#eu-opers'),
),
),

array(
"MODE &oulu :+b\r\n",
array(
Expand All @@ -538,6 +598,7 @@ public function dataProviderTestParse()
'params' => array(
'channel' => '&oulu',
'mode' => '+b',
'params' => '*!*@*',
'banmask' => '*!*@*',
'all' => '&oulu +b :*!*@*',
),
Expand All @@ -552,13 +613,28 @@ public function dataProviderTestParse()
'params' => array(
'channel' => '&oulu',
'mode' => '+b',
'params' => '*!*@*.edu',
'banmask' => '*!*@*.edu',
'all' => '&oulu +b :*!*@*.edu',
),
'targets' => array('&oulu'),
),
),

array(
"MODE &oulu +b-b :*!*@*.edu *!*@*.ac.uk\r\n",
array(
'command' => 'MODE',
'params' => array(
'channel' => '&oulu',
'mode' => '+b-b',
'params' => '*!*@*.edu *!*@*.ac.uk',
'all' => '&oulu +b-b :*!*@*.edu *!*@*.ac.uk',
),
'targets' => array('&oulu'),
),
),

array(
"MODE Wiz :-w\r\n",
array(
Expand Down Expand Up @@ -600,6 +676,34 @@ public function dataProviderTestParse()
),
),

array(
"MODE Kilroy +s :+CcQq\r\n",
array(
'command' => 'MODE',
'params' => array(
'user' => 'Kilroy',
'mode' => '+s',
'params' => '+CcQq',
'all' => 'Kilroy +s :+CcQq',
),
'targets' => array('Kilroy'),
),
),

array(
"MODE Angel +ws :+CcQq\r\n",
array(
'command' => 'MODE',
'params' => array(
'user' => 'Angel',
'mode' => '+ws',
'params' => '+CcQq',
'all' => 'Angel +ws :+CcQq',
),
'targets' => array('Angel'),
),
),

// TOPIC (RFC 1459 Section 4.2.4)
array(
":Wiz TOPIC #test :New topic\r\n",
Expand Down

0 comments on commit d233d03

Please sign in to comment.