/**
  * There are certain incoming events that the client processes internally.
  * These functions are essential to the client-server relationship: for example,
  * updating the connection's stored nickname, responding to PING events, etc.
  *
  * Any user-level IRC functionality handled internally by the client
  * should be implemented here.
  *
  * @param array $message Parser output
  * @param \Phergie\Irc\Client\React\WriteStream $write Write stream
  *        corresponding to the read stream on which the event occurred
  * @param \Phergie\Irc\ConnectionInterface $connection Connection on
  *        which the event occurred
  */
 protected function processInput(array $message, WriteStream $write, ConnectionInterface $connection)
 {
     switch ($message['command']) {
         // Update connection's internal nickname when changed
         case 'NICK':
             if ($connection->getNickname() === $message['nick']) {
                 $connection->setNickname($message['params']['nickname']);
             }
             break;
             // Play client-server ping-pong
         // Play client-server ping-pong
         case 'PING':
             $write->ircPong($message['params']['server1']);
             break;
     }
 }
 /**
  * Add connections to pool
  *
  * @param ConnectionInterface $connection
  */
 public function addConnection(ConnectionInterface $connection)
 {
     $this->connections[$connection->getMask()] = $connection;
 }
Example #3
0
 /**
  * @param ConnectionInterface $connection
  */
 public function create(ConnectionInterface $connection)
 {
     if ($this->stream) {
         $this->disconnect();
     }
     $hostname = $connection->getServerHostname();
     $port = $connection->getServerPort();
     $this->getConnector()->create($hostname, $port)->then(function (Stream $stream) use($connection) {
         $this->setStream($stream);
         $this->setConnectionDetails($connection);
         $this->api->getEmitter()->emit('irc.connect', [$stream, $connection]);
         $this->write($this->api->getGenerator()->ircNick($connection->getNickname()));
         $this->write($this->api->getGenerator()->ircUser($connection->getNickname(), gethostname(), $connection->getNickname(), $connection->getUsername()));
         $stream->on('data', [$this, 'processData']);
     });
 }
 /**
  * Returns the connection mask for a given connection.
  *
  * @param \Phergie\Irc\ConnectionInterface $connection
  * @return string
  */
 protected function getConnectionMask(ConnectionInterface $connection)
 {
     return sprintf('%s!%s@%s', $connection->getNickname(), $connection->getUsername(), $connection->getServerHostname());
 }
 /**
  * Configures an established stream for a given connection.
  *
  * This method is only public to allow it to be called from
  * addSecureConnection() under PHP 5.3.x. It should not be called outside
  * this class.
  *
  * @param \React\Stream\StreamInterface $stream
  * @param \Phergie\Irc\ConnectionInterface $connection
  */
 public function initializeStream(StreamInterface $stream, ConnectionInterface $connection)
 {
     try {
         $connection->setOption('stream', $stream);
         $write = $this->getWriteStream($connection);
         $connection->setOption('write', $write);
         $this->configureStreams($connection, $stream, $write);
         $this->identifyUser($connection, $write);
     } catch (\Exception $e) {
         $this->emitConnectionError($e, $connection);
     }
 }