Irc icon indicating copy to clipboard operation
Irc copied to clipboard

Extract useful information from connection url

Open shulard opened this issue 9 years ago • 6 comments

Work on the #25 issue about URL details extraction.

This PR must allow the library to extract connection URL details and use it during connection :

  • Entity name to join
  • Credentials
  • Connection options
  • Connection flags (used to define entity more precisely)

Example :

$uri    = 'irc://user:[email protected]:194/#channel?key=abcd';
$client = new Hoa\Irc\Client(new Hoa\Socket\Client($uri));

The given code is valid and can be used to join the channel #channel with the option key=abcd.

shulard avatar Oct 25 '16 16:10 shulard

Hello @shulard!

Is it ready for a review?

Hywan avatar Nov 02 '16 07:11 Hywan

Hello @Hywan,

I haven't worked on Connection implementation for the moment, only on URL information extraction. You can take a look if you want, this first part is ready for a review 😄.

shulard avatar Nov 02 '16 11:11 shulard

Hello @Hywan,

Sorry for the delay but I've worked on that PR this week 😄.

Now, if you use something like that, it works (User is used and Channel is joined) :

$socket = new Hoa\Socket\Client('irc://Gordon:[email protected]/#hoaproject-random');
$client = new Hoa\Irc\Client($socket);
$client->run();

It works with secured account, guest account. I still need to handle some options / flags, I make that changes ASAP.

I've used event handlers (on open) to set specific connection details, do you think it's the right thing to do ?

shulard avatar Nov 30 '16 09:11 shulard

Please, stop being sorry for “delay”. This is open source. We all have a life, with different constraints. I am the first to be concerned…

THANK YOU for your contribution!

Hywan avatar Nov 30 '16 19:11 Hywan

Yes, the open listener is the best one to call the join method I guess.

Hywan avatar Nov 30 '16 19:11 Hywan

Hello,

I've pushed new changes to handle all the described properties.

Now you can use that kind of code :

//Ask to connect as "gordon" then join channel
$socket = new Hoa\Socket\Client('irc://chat.freenode.net/gordon,isuser');
$client = new Hoa\Irc\Client($socket);
$client->on('open', function($bucket) {
    $bucket->getSource()->setChannel('#hoaproject-random');
});
$client->run();

//Directly connect on the "#hoaproject-random" channel as "gordon"
$socket = new Hoa\Socket\Client('irc://gordon:@chat.freenode.net/#hoaproject-random');
$client = new Hoa\Irc\Client($socket);
$client->run();

//Connect using a protected username on "#hoaproject-random" channel
$socket = new Hoa\Socket\Client('irc://gordon:[email protected]/#hoaproject-random');
$client = new Hoa\Irc\Client($socket);
$client->run();

I've also updated unit tests, removed TODOs in the code (because they are done now) and used named groups in regex. Maybe the commit history needs a little cleanup but the code is working for me.

In Socket.php I've added a new regex to parse a nickname with optional part. I saw that there is one in Client.php but the 3 parts are mandatory (nick, user, host). Maybe we can merge the two in a helper function, I don't know if they must be mandatory or not 😄.

shulard avatar Dec 01 '16 11:12 shulard