/**
  * Derives a remote for a given connection.
  *
  * @param \Phergie\Irc\ConnectionInterface $connection
  * @return string Remote usable to establish a socket connection
  */
 protected function getRemote(ConnectionInterface $connection)
 {
     $hostname = $connection->getServerHostname();
     $port = $connection->getServerPort();
     $deferred = new Deferred();
     $this->getResolver()->resolve($hostname)->then(function ($ip) use($deferred, $port) {
         $deferred->resolve('tcp://' . $ip . ':' . $port);
     }, function ($error) use($deferred) {
         $deferred->reject($error);
     });
     return $deferred->promise();
 }
Example #2
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());
 }
 /**
  * Adds an event listener to log data emitted by a stream.
  *
  * @param \Evenement\EventEmitter $emitter
  * @param \Phergie\Irc\ConnectionInterface $connection Connection
  *        corresponding to the stream
  */
 protected function addLogging(EventEmitter $emitter, ConnectionInterface $connection)
 {
     $logger = $this->getLogger();
     $callback = function ($msg) use($logger, $connection) {
         $mask = sprintf('%s!%s@%s', $connection->getNickname(), $connection->getUsername(), $connection->getServerHostname());
         $logger->debug($mask . ' ' . trim($msg));
     };
     $emitter->on('data', $callback);
     $emitter->on('error', $callback);
 }