Exemplo n.º 1
0
 /**
  * This is the workhorse function, grabs the data from the server and displays on the browser
  *
  * @author Super3 <*****@*****.**>
  * @author Daniel Siepmann <*****@*****.**>
  */
 private function main()
 {
     do {
         $command = '';
         $arguments = array();
         $data = $this->connection->getData();
         // Check for some special situations and react:
         // The nickname is in use, create a now one using a counter and try again.
         if (stripos($data, 'Nickname is already in use.') !== false) {
             $this->nickToUse = $this->nick . ++$this->nickCounter;
             $this->sendDataToServer('NICK ' . $this->nickToUse);
         }
         // We're welcome. Let's join the configured channel/-s.
         if (stripos($data, 'Welcome') !== false) {
             $this->join_channel($this->channel);
         }
         // Something realy went wrong.
         if (stripos($data, 'Registration Timeout') !== false || stripos($data, 'Erroneous Nickname') !== false || stripos($data, 'Closing Link') !== false) {
             // If the error occurs to often, create a log entry and exit.
             if ($this->numberOfReconnects >= (int) $this->maxReconnects) {
                 $this->log('Closing Link after "' . $this->numberOfReconnects . '" reconnects.', 'EXIT');
                 exit;
             }
             // Notice the error.
             $this->log($data, 'CONNECTION LOST');
             // Wait before reconnect ...
             sleep(60 * 1);
             ++$this->numberOfReconnects;
             // ... and reconnect.
             $this->connection->connect();
             return;
         }
         // Get the response from irc:
         $args = explode(' ', $data);
         $this->log($data);
         // Play ping pong with server, to stay connected:
         if ($args[0] == 'PING') {
             $this->sendDataToServer('PONG ' . $args[1]);
         }
         // Nothing new from the server, step over.
         if ($args[0] == 'PING' || !isset($args[1])) {
             continue;
         }
         /* @var $listener \Library\IRC\Listener\Base */
         foreach ($this->listeners as $listener) {
             if (is_array($listener->getKeywords())) {
                 foreach ($listener->getKeywords() as $keyword) {
                     //compare listeners keyword and 1st arguments of server response
                     if ($keyword === $args[1]) {
                         $listener->execute($data);
                     }
                 }
             }
         }
         if (isset($args[3])) {
             // Explode the server response and get the command.
             // $source finds the channel or user that the command originated.
             $source = substr(trim(\Library\FunctionCollection::removeLineBreaks($args[2])), 0);
             $trigger = strtolower(substr(trim(\Library\FunctionCollection::removeLineBreaks($args[3])), 1));
             $arguments = array_slice($args, 4);
             unset($args);
             foreach ($this->commands as $commandKey => $command) {
                 if ($command->prefix) {
                     if (stripos($trigger, $command->prefix) !== 0) {
                         continue;
                     }
                     $trigger = substr($trigger, strlen($command->prefix));
                 }
                 if ($trigger === strtolower($commandKey)) {
                     $this->executeCommand($source, $commandKey, $arguments, $data);
                 }
             }
         }
     } while (true);
 }
Exemplo n.º 2
0
 /**
  * This is the workhorse function, grabs the data from the server and displays on the browser
  *
  * @author Super3 <*****@*****.**>
  * @author Daniel Siepmann <*****@*****.**>
  */
 private function main()
 {
     global $config;
     $this->commandPrefix = $config['prefix'];
     do {
         $command = '';
         $arguments = array();
         $data = $this->connection->getData();
         // Check for some special situations and react:
         // The nickname is in use, create a now one using a counter and try again.
         if (stripos($data, 'Nickname is already in use.') !== false && $this->getUserNickName($data) == 'NickServ') {
             $this->nickToUse = $this->nick . ++$this->nickCounter;
             $this->sendDataToServer('NICK ' . $this->nickToUse);
         }
         // We're welcome. Let's join the configured channel/-s.
         if (stripos($data, 'Welcome') !== false) {
             $this->join_channel($this->channel);
         }
         // Something realy went wrong.
         if (stripos($data, 'Registration Timeout') !== false || stripos($data, 'Erroneous Nickname') !== false || stripos($data, 'Closing Link') !== false) {
             // If the error occurs to often, create a log entry and exit.
             if ($this->numberOfReconnects >= (int) $this->maxReconnects) {
                 $this->log('Closing Link after "' . $this->numberOfReconnects . '" reconnects.', 'EXIT');
                 exit;
             }
             // Notice the error.
             $this->log($data, 'CONNECTION LOST');
             // Wait before reconnect ...
             sleep(60 * 1);
             ++$this->numberOfReconnects;
             // ... and reconnect.
             $this->connection->connect();
             return;
         }
         // Get the response from irc:
         $args = explode(' ', $data);
         $this->log($data);
         // Play ping pong with server, to stay connected:
         if ($args[0] == 'PING') {
             $this->sendDataToServer('PONG ' . $args[1]);
         }
         // Try to flush log buffers, if needed.
         $this->log->intervalFlush();
         // Nothing new from the server, step over.
         if ($args[0] == 'PING' || !isset($args[1])) {
             continue;
         }
         /* @var $listener \Library\IRC\Listener\Base */
         foreach ($this->listeners as $listener) {
             if (is_array($listener->getKeywords())) {
                 foreach ($listener->getKeywords() as $keyword) {
                     //compare listeners keyword and 1st arguments of server response
                     if ($keyword === $args[1]) {
                         $listener->execute($data);
                     }
                 }
             }
         }
         if (isset($args[3])) {
             // Explode the server response and get the command.
             // $source finds the channel or user that the command originated.
             $source = substr(trim(\Library\FunctionCollection::removeLineBreaks($args[2])), 0);
             $command = substr(trim(\Library\FunctionCollection::removeLineBreaks($args[3])), 1);
             // Someone PMed me? Oh noes.
             if ($source == $this->nickToUse && $args[1] == 'PRIVMSG') {
                 $source = $this->getUserNickName($args[0]);
             }
             $arguments = array_slice($args, 4);
             unset($args);
             // Check if the response was a command.
             if (stripos($command, $this->commandPrefix) === 0) {
                 $command = ucfirst(substr($command, strlen($this->commandPrefix)));
                 // Command does not exist:
                 if (!array_key_exists($command, $this->commands)) {
                     $this->log('The following, not existing, command was called: "' . $command . '".', 'MISSING');
                     $this->log('The following commands are known by the bot: "' . implode(',', array_keys($this->commands)) . '".', 'MISSING');
                     continue;
                 }
                 $this->executeCommand($source, $command, $arguments, $data);
             }
         }
     } while (true);
 }
Exemplo n.º 3
0
 /**
  * This is the workhorse function, grabs the data from the server and displays on the browser
  *
  * @author Super3 <*****@*****.**>
  * @author Daniel Siepmann <*****@*****.**>
  */
 private function main()
 {
     do {
         $command = '';
         $arguments = array();
         $data = $this->connection->getData();
         // Check for some special situations and react:
         // The nickname is in use, create a now one using a counter and try again.
         if (stripos($data, 'Nickname is already in use.') !== false) {
             $this->nickToUse = $this->nick . ++$this->nickCounter;
             $this->sendDataToServer('NICK ' . $this->nickToUse);
         }
         // We're welcome. Let's join the configured channel/-s.
         if (stripos($data, 'Welcome') !== false) {
             $this->join_channel($this->channel);
         }
         // Something realy went wrong.
         if (stripos($data, 'Registration Timeout') !== false || stripos($data, 'Erroneous Nickname') !== false || stripos($data, 'Closing Link') !== false) {
             // If the error occurs to often, create a log entry and exit.
             if ($this->numberOfReconnects >= (int) $this->maxReconnects) {
                 $this->log('Closing Link after "' . $this->numberOfReconnects . '" reconnects.', 'EXIT');
                 exit;
             }
             // Notice the error.
             $this->log($data, 'CONNECTION LOST');
             // Wait before reconnect ...
             sleep(60 * 1);
             ++$this->numberOfReconnects;
             // ... and reconnect.
             $this->connection->connect();
             return;
         }
         // trim end /r/n
         $data = rtrim($data);
         // trim double spaces
         $data = preg_replace('/\\s+/', ' ', $data);
         // Get the response from irc:
         $args = explode(' ', $data);
         $this->log($data);
         // Play ping pong with server, to stay connected:
         if ($args[0] == 'PING') {
             $this->sendDataToServer('PONG ' . $args[1]);
             //                $this->executeCommand( "#bojs", "Twitter", $args, $data );
         }
         // Nothing new from the server, step over.
         if ($args[0] == 'PING' || !isset($args[1])) {
             continue;
         }
         $user_message = array_slice($args, 3);
         if (isset($user_message[0])) {
             $user_message[0] = substr($user_message[0], 1);
         }
         // jump over the ':'
         $msg = trim(implode(" ", $user_message));
         if (isset($args[3])) {
             /* @var $listener \Library\IRC\Listener\Base */
             foreach ($this->listeners as $listener) {
                 if (is_array($listener->getKeywords())) {
                     foreach ($listener->getKeywords() as $keyword) {
                         //compare listeners keyword and 1st arguments of server response
                         if (stristr($msg, $keyword)) {
                             $listener->execute($data);
                             break;
                             // only one call per .php... i.e 2 youtube links doesnt mean call the yt listener twice
                         }
                     }
                 }
             }
             // Explode the server response and get the command.
             // $source finds the channel or user that the command originated.
             $source = substr(trim(\Library\FunctionCollection::removeLineBreaks($args[2])), 0);
             $command = substr(trim(\Library\FunctionCollection::removeLineBreaks($args[3])), 1);
             $arguments = array_slice($args, 4);
             unset($args);
             // Check if the response was a command.
             $yes = false;
             if (!empty($this->commandPrefix)) {
                 if (false !== stripos($command, $this->commandPrefix)) {
                     $command = substr($command, 1);
                     $yes = true;
                 }
             } else {
                 $yes = true;
             }
             if ($yes) {
                 $command = ucfirst(strtolower($command));
                 if (!array_key_exists($command, $this->commands)) {
                     /*if( ! empty( $this>commandPrefix ) ) {
                           $this->log( 'The following, not existing, command was called: "' . $command . '".', 'MISSING' );
                           $this->log( 'The following commands are known by the bot: "' . implode( ',', array_keys( $this->commands ) ) . '".', 'MISSING' );
                       }*/
                     continue;
                 }
                 $this->executeCommand($source, $command, $arguments, $data);
             }
         }
     } while (true);
 }
Exemplo n.º 4
0
 /**
  * This is the workhorse function, grabs the data from the server and displays on the browser
  *
  * @author Super3 <*****@*****.**>
  * @author Daniel Siepmann <*****@*****.**>
  */
 private function main()
 {
     // And fire up a connection.
     $this->log('Main loop ignited! GO GO GO!', 'STARTUP');
     do {
         foreach ($this->reminders as $time => $reminder) {
             if (time() >= $time) {
                 $this->sendDataToServer('PRIVMSG #wildphp :' . $this->reminders[$time]);
                 unset($this->reminders[$time]);
             }
         }
         $command = '';
         $arguments = array();
         $data = $this->connection->getData();
         // Check for some special situations and react:
         // The nickname is in use, create a now one using a counter and try again.
         if (stripos($data, 'Nickname is already in use.') !== false && \Library\FunctionCollection::getUserNickName($data) == $this->nickserv) {
             $this->nickToUse = $this->nick . ++$this->nickCounter;
             $this->sendDataToServer('NICK ' . $this->nickToUse);
         }
         // We're welcome without password or identified with password. Lets join.
         if (empty($this->password) && stripos($data, 'Welcome') !== false || !empty($this->password) && stripos($data, 'You are now identified') && \Library\FunctionCollection::getUserNickName($data) == $this->nickserv) {
             $this->join_channel($this->channel);
         }
         // Something realy went wrong.
         if (stripos($data, 'Registration Timeout') !== false || stripos($data, 'Erroneous Nickname') !== false || stripos($data, 'Closing Link') !== false) {
             // If the error occurs to often, create a log entry and exit.
             if ($this->numberOfReconnects >= (int) $this->maxReconnects) {
                 $this->log('Closing Link after "' . $this->numberOfReconnects . '" reconnects.', 'EXIT');
                 exit;
             }
             // Notice the error.
             $this->log($data, 'CONNECTION LOST');
             // Wait before reconnect ...
             sleep(60 * 1);
             ++$this->numberOfReconnects;
             // ... and reconnect.
             $this->connection->connect();
             return;
         }
         // Get the response from irc:
         $args = explode(' ', $data);
         if (!empty($data)) {
             $this->log($data);
         }
         // Play ping pong with server, to stay connected:
         if ($args[0] == 'PING') {
             $this->sendDataToServer('PONG ' . $args[1]);
         }
         // Try to flush log buffers, if needed.
         $this->log->intervalFlush();
         // Nothing new from the server, step over.
         if ($args[0] == 'PING' || !isset($args[1])) {
             unset($data, $args);
             continue;
         }
         if (isset($args[3])) {
             // Explode the server response and get the command.
             // $source finds the channel or user that the command originated.
             $source = substr(trim(\Library\FunctionCollection::removeLineBreaks($args[2])), 0);
             $command = substr(trim(\Library\FunctionCollection::removeLineBreaks($args[3])), 1);
             // Someone PMed me? Oh noes.
             if ($source == $this->nickToUse && $args[1] == 'PRIVMSG') {
                 $source = \Library\FunctionCollection::getUserNickName($args[0]);
             }
             $this->source = $source;
             $arguments = array_slice($args, 4);
             // Check if the response was a command.
             if (stripos($command, $this->commandPrefix) === 0) {
                 $command = ucfirst(substr($command, strlen($this->commandPrefix)));
                 // Command does not exist:
                 if (!$this->commandManager->commandExists($command)) {
                     $this->log('The following, not existing, command was called: "' . $command . '".', 'MISSING');
                     continue;
                 }
                 $this->commandManager->executeCommand($source, $command, $arguments, $data);
             }
         }
         // Call the listeners!
         $this->listenerManager->listenerHook($args, $data);
         unset($data, $args);
     } while (true);
 }