• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ General Support (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

Removing spaces from nicknames and channels names ?

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
13 posts • Page 1 of 1

Postby phpfreechat » Fri Nov 24, 2006 1:14 pm

Hi phpfreechat users,

I whould like to have your say about how to handle commands with multiple parameters.
I can give you an example, beni is implementing private conferences so he is working on a new /invite command and on setting up password to channels.
The invite command will have the same syntax as on IRC :
/invite channelname nickname
Now imagine someone with the "Mr Cool" nickname is invited to "My room" channel.
The command to type whould be :
/invite My room Mr Cool
You can see the problem : the space separator between "My room" and "Mr Cool" can't be located... From the computer point of view, the channel name can be "My room Mr" and the nickname "Cool".

One solution is to forbid spaces in channels name and in nicknames.
What do you think about that ? and do you have better ideas to allow user firendly multi parameters in commands ?

regards,
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby feric » Fri Nov 24, 2006 1:25 pm

Either use Quotes: /invite "My Channel" "Mr Kraps"
or use parametertags /invite -r My Channel -u Mr Kraps

I'd prefer Quotes ;)
feric
Member
 
Posts: 14
Joined: Wed Nov 22, 2006 10:20 am
Location: Duisburg, Germany
  • Website
Top

Postby phpfreechat » Fri Nov 24, 2006 2:48 pm

Another idea I had is to disallow spaces but add a parameter : "space_character"
For exemple, caht admin could setup this parameter :
$params['space_charactere'] = '_';
Then the chat interface will automaticaly display nicknames and channels name with space substitute to underscore.

The problem with this solution is that it's not very user friendly because users will see "Mr Cool" and "My room" but should type : /invite My_room Mr_Cool
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby Beni » Fri Nov 24, 2006 5:21 pm

Quotes is a good idea. Flags aren't so good, again because of userfriendlyness.
btw the /invite cmd on IRC has Syntax "/invite <nick> <channel>", that is because <channel> is optional and defaults to the current channel, as is in the implementation of /invite i send to you ;)

Handling of quotes should be easy implementable using preg_match(), but since they are not always required (like in /join, wehre only one parameter is expected) it could easily lead to confusion.
Therefor every command expecting parameters must support both quoted and unquoted parameters.
Beni
Member
 
Posts: 65
Joined: Thu Sep 21, 2006 10:50 am
Top

Postby phpfreechat » Fri Dec 01, 2006 9:56 am

I just wrote some code to parse the commands with or without quotes.
Could you give me your advice on it ?

Code: Select all
<?php

function parsecmd($cmd_str)
{
  $pattern_quote   = '/([^\]|^)"([^"]+[^\])"/';
  $pattern_quote   = '/"([^"]+)"/';
  $pattern_noquote = '/([^"s]+)/';
  $pattern_command = '/^/([a-z0-9]+)s*(.*)/';
  $result = array();
 
  // parse the command name (ex: '/invite')
  if (preg_match($pattern_command, $cmd_str, $res))
  {
    $cmd = $res[1];
    $params_str = $res[2];
    // parse the quotted parameters (ex: '/invite "nickname with spaces"')
    preg_match_all($pattern_quote,$params_str,$res1,PREG_OFFSET_CAPTURE);
    $params_res = $res1[1];
    // split the parameters string
    $nospaces = preg_split($pattern_quote,$params_str,-1,PREG_SPLIT_OFFSET_CAPTURE|PREG_SPLIT_NO_EMPTY);
    foreach($nospaces as $p)
    {
      // parse the splited blocks with unquotted parameter pattern (ex: '/invite nicknamewithoutspace')
      preg_match_all($pattern_noquote,$p[0],$res2,PREG_OFFSET_CAPTURE);
      foreach( $res2[1] as $p2 )
      {
        $p2[1] += $p[1];
        $params_res[] = $p2;
      }
    }

    // order the array by offset
    $params = array();
    foreach($params_res as $p) $params[$p[1]] = $p[0];
    ksort($params);
    $params = array_values($params);
    $params = array_map("trim",$params);
   
    $result['command'] = $cmd;
    $result['params']  = $params;
  }
  return $result;
}

$commands = array();
$results = array();
$commands[] = '/cmdname';
$results[] = array('command' => 'cmdname', 'params' => array());
$commands[] = '/cmdname "param1" "param2"';
$results[] = array('command' => 'cmdname', 'params' => array('param1','param2'));
$commands[] = '/cmdname "param1" "param2" "param3"';
$results[] = array('command' => 'cmdname', 'params' => array('param1','param2','param3'));
$commands[] = '/cmdname "param1 with spaces" "param2 with spaces"';
$results[] = array('command' => 'cmdname', 'params' => array('param1 with spaces','param2 with spaces'));
$commands[] = '/cmdname000 "param1" "param2"';
$results[] = array('command' => 'cmdname000', 'params' => array('param1','param2'));
$commands[] = '/cmdname param1 param2';
$results[] = array('command' => 'cmdname', 'params' => array('param1','param2'));
$commands[] = '/cmdname "param1 with spaces" param2  param3';
$results[] = array('command' => 'cmdname', 'params' => array('param1 with spaces','param2','param3'));
$commands[] = '/cmdname "param1" param2 "param3 with spaces" param4';
$results[] = array('command' => 'cmdname', 'params' => array('param1', 'param2', 'param3 with spaces', 'param4'));
$commands[] = '/cmdname "param1""param2"';
$results[] = array('command' => 'cmdname', 'params' => array('param1', 'param2'));

echo '<pre>';
for($i = 0; $i< count($commands); $i++)
{
  $command = $commands[$i];
  $result = parsecmd($command);
  if ($result == $results[$i])
    echo "OK => $commandn";
  else
    echo "KO => $commandn";
}
echo '</pre>';

?>

It should output :
Code: Select all
OK => /cmdname
OK => /cmdname "param1" "param2"
OK => /cmdname "param1" "param2" "param3"
OK => /cmdname "param1 with spaces" "param2 with spaces"
OK => /cmdname000 "param1" "param2"
OK => /cmdname param1 param2
OK => /cmdname "param1 with spaces" param2  param3
OK => /cmdname "param1" param2 "param3 with spaces" param4
OK => /cmdname "param1""param2"
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby phpfreechat » Sat Dec 09, 2006 10:08 pm

I just integrated this code in the official pfc source code.
So it makes possible to write commands using multi parameters.
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby Beni » Tue Feb 27, 2007 12:50 pm

Hi Kerphi, sorry, i wasn't in the forums for a while and found the post just now...

I see it is already implemented. A open question for me is, as of Beta8, are the parameters automatically processed by the chat or does the function need to parse it on its own?
Beni
Member
 
Posts: 65
Joined: Thu Sep 21, 2006 10:50 am
Top

Postby phpfreechat » Tue Feb 27, 2007 2:08 pm

Hi Beni,
Sorry but I don't understand your question, could you reformulate it ?
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby Beni » Sun Mar 11, 2007 12:17 pm

Of course :)
The quetsion is, wether parsecmd() is called auotatically prior any proxys are executed or not.
So, do i need to call parsecmd() manually in my proxys or is this done somewehre inside the chat routines for me and i dont need to recode my proxys?
Beni
Member
 
Posts: 65
Joined: Thu Sep 21, 2006 10:50 am
Top

Postby phpfreechat » Sun Mar 11, 2007 12:28 pm

pfcCommand::ParseCommand(...) is called automatically in phpFreeChat::handleRequest(..) so you don't have to recode your proxies at all.
You can just use the new parameters called "params" that contains an array with the result of ParseCommand().
I have leaved the "param" parameter to keep compatibility with old proxies code.
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby Beni » Sun Mar 11, 2007 1:00 pm

okay, thank you for your FAST answer!
Currently i am on testing my app with beta9 :D

I am produ to see my invite command there, but why do you remove the copyright and authors notices? I think contributioners should also be mentioned in the source code... I think something like "based on code from foobar" would be appropriate since you usually modify the contributions.

GPL doens't mean "i take some code and sell it as my own", you know ;)
Beni
Member
 
Posts: 65
Joined: Thu Sep 21, 2006 10:50 am
Top

Postby phpfreechat » Sun Mar 11, 2007 1:10 pm

I didn't removed your name from the authors, look at these lines :
Code: Select all
/**
 * /invite command
 *
 * Invites other users into a channel
 * Currently this is implemented as a "autojoin", so the invited user joins automatically.
 * The parameter "target channel" is optional, if not set it defaults to the current channel
 *
 * @author Benedikt Hallinger <beni@php.net>
 * @author Stephane Gully <stephane.gully@gmail.com>
 */
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby Beni » Sun Mar 11, 2007 1:16 pm

wohow, SORRY for that - i only looked at the file comment block!
sorry again!

Btw: have you seen my question regarding channel metadata at client side?
http://www.phpfreechat.net/forum/viewtopic.php?id=1262
Beni
Member
 
Posts: 65
Joined: Thu Sep 21, 2006 10:50 am
Top


Post a reply
13 posts • Page 1 of 1

Return to General Support (v1.x)

Who is online

Users browsing this forum: No registered users and 29 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub