Exemple #1
0
 public function setIncommingData($dataString)
 {
     if (!preg_match(self::MESSAGE_REGEX, $dataString, $data)) {
         return false;
     }
     $this->mask = !empty($data[1]) ? $data[1] : false;
     if (!empty($this->mask)) {
         preg_match(self::MASK_REGEX, $this->mask, $mask);
         $this->userNick = !empty($mask[1]) ? $mask[1] : false;
         $this->userName = !empty($mask[2]) ? $mask[2] : false;
         $this->userHost = !empty($mask[3]) ? $mask[3] : false;
     } else {
         $this->userNick = $this->userName = $this->userHost = false;
     }
     $this->type = !empty($data[2]) ? strtoupper($data[2]) : false;
     $this->message = !empty($data[4]) ? $data[4] : false;
     if (empty($data[3])) {
         $this->offset = $this->source = false;
     } elseif ($data[3] == Config::getNick()) {
         $this->source = $this->userNick;
         $this->offset = false;
     } elseif ($data[3]) {
         preg_match(self::SOURCE_REGEX, $data[3], $channel);
         $this->source = !empty($channel[1]) ? strtolower($channel[1]) : '';
         $this->offset = trim(str_ireplace($this->source, '', $data[3]));
     }
     return true;
 }
Exemple #2
0
 public function fillBuffer($text, $type, $target = null, $prio = false)
 {
     $text = str_replace([chr(9), chr(10), chr(11), chr(13), chr(0)], '', $text);
     $text = trim($text);
     $filters = (new Filter())->filterList();
     if ($type == IRC::PRIVMSG && $filters) {
         foreach ($filters as $filter) {
             if (isset($filter['serverBlock']) && in_array(Config::getServerName(), $filter['serverBlock'])) {
                 continue;
             }
             if (isset($filter['serverAllow']) && !in_array(Config::getServerName(), $filter['serverAllow'])) {
                 continue;
             }
             if (isset($filter['channelBlock']) && in_array($target, $filter['channelBlock'])) {
                 continue;
             }
             if (isset($filter['channelAllow']) && !in_array($target, $filter['channelAllow'])) {
                 continue;
             }
             if (is_callable($filter['callback'])) {
                 $text = call_user_func($filter['callback'], $text);
             }
         }
     }
     if (!$text) {
         echo 'You sent nothing' . PHP_EOL;
         return false;
     }
     while (true) {
         switch ($type) {
             case IRC::PRIVMSG:
                 $message = IRC::PRIVMSG . ' ' . $target . ' :' . $text;
                 break;
             case IRC::MODE:
                 $message = IRC::MODE . ' ' . $target . ' ' . $text;
                 break;
             case IRC::NICK:
                 $message = IRC::NICK . ' ' . $text;
                 break;
             case IRC::TOPIC:
                 break;
             case IRC::PART:
                 $message = IRC::PART . ' ' . $target . ' :' . $text;
                 break;
             case IRC::QUIT:
                 $message = IRC::QUIT . ' :' . $text;
                 break;
             case IRC::JOIN:
                 $message = IRC::JOIN . ' ' . $text;
                 break;
             case IRC::KICK:
                 $message = IRC::KICK . ' ' . $target . ' ' . $text;
                 break;
             case IRC::NOTICE:
                 $message = IRC::NOTICE . ' ' . $target . ' :' . $text;
                 break;
             case IRC::INVITE:
                 break;
             case IRC::IDENTIFY:
                 $message = IRC::IDENTIFY . ' ' . $text;
                 break;
             case IRC::PING:
                 $message = IRC::PONG . ' ' . $text;
                 break;
             default:
                 return;
         }
         if (strlen($message) > 508) {
             $lastWhiteSpace = strrpos(substr($message, 0, 508), ' ');
             $position = $lastWhiteSpace !== false ? $lastWhiteSpace : strlen(substr($message, 0, 508));
             $text = substr($message, $position + 1);
             $this->buffer[] = substr($message, 0, $position);
         } else {
             $this->buffer[] = $message;
             break;
         }
     }
     while ($prio && $this->buffer) {
         $this->flushBuffer();
     }
 }
Exemple #3
0
<?php

require __DIR__ . '/../autoload.php';
use Library\Configuration as Config;
Config::set('db.engine', 'mysql');
Config::set('db.user', 'root');
Config::set('db.password', 'root');
Config::set('db.host', '127.0.0.1');
Config::set('db.name', 'contacts-book');
$request = new Plus33FPS\Request($_SERVER, $_GET, $_POST);
$router = new Plus33FPS\Routing\Router($request);
$routeStore = new Plus33FPS\Routing\RouteStore();
$routeStore->add(new Plus33FPS\Routing\Route(['name' => 'index', 'pattern' => '/^\\/$/']));
$route = $router->route($request, $routeStore->getAll());
var_dump($route);
die;
//$response
//new Request($_SERVER, $_GET, $_POST);
$uri = $_SERVER['REQUEST_URI'];
$method = $_SERVER['REQUEST_METHOD'];
$isGETMethod = $method === 'GET';
$isPOSTMethod = $method === 'POST';
$pos = strrpos($uri, '?');
if ($pos !== false) {
    $uri = substr($uri, 0, $pos);
}
# TODO Trim trailing slash from URI
$viewParams = ['isPOSTMethod' => $isPOSTMethod, 'isGETMethod' => $isGETMethod];
global $viewParams;
$name = isset($_POST['Name']) ? $_POST['Name'] : null;
$email = isset($_POST['Email']) ? $_POST['Email'] : null;
Exemple #4
0
 protected function nickNameInUse()
 {
     Config::setNick(Config::getNick() . ++$this->nickCounter);
     $this->message(Config::getNick(), null, IRC::NICK);
     $this->ghost = true;
 }
Exemple #5
0
 public function saveData($out = false)
 {
     $timestamp = '[' . date('H:i') . ']';
     $source = $this->bot->getSource();
     $message = $this->bot->getMessage();
     $userNick = $this->bot->getUserNick();
     $folder = implode(DIRECTORY_SEPARATOR, [Config::$logFolder, Config::getServerName()]);
     /* $userName = $this->getUserName(); */
     /* $userHost = $this->getUserHost(); */
     if (!$out) {
         switch ($this->bot->getType()) {
             case IRC::PRIVMSG:
                 $text = "{$timestamp} <{$userNick}> {$message}" . IRC_EOL;
                 if (strpos($source, '#') === 0) {
                     $filename = $source . '_' . date('Y-m-d');
                     $filepatch = implode(DIRECTORY_SEPARATOR, [$folder, substr($source, 1)]);
                 } else {
                     $filename = $source;
                     $filepatch = $folder;
                 }
                 static::push($text, $filepatch, $filename . '.log');
                 return $text;
             case IRC::JOIN:
                 break;
                 /*   $text = "{$timestamp} {$userNick} (~{$userName}@{$userHost}) has joined.\r\n";
                      $filename = $message;
                      return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */
             /*   $text = "{$timestamp} {$userNick} (~{$userName}@{$userHost}) has joined.\r\n";
                  $filename = $message;
                  return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */
             case IRC::PART:
                 break;
                 /*   $info = ($this->message) ? ' (' . $this->message . ')' : '';
                      $text = $timestamp . ' ' . $this->userNick . ' (~' . $this->userName . '@' . $this->userHost . ') has parted.' . $info . "\r\n";
                      $filename = $this->source;
                      return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */
             /*   $info = ($this->message) ? ' (' . $this->message . ')' : '';
                  $text = $timestamp . ' ' . $this->userNick . ' (~' . $this->userName . '@' . $this->userHost . ') has parted.' . $info . "\r\n";
                  $filename = $this->source;
                  return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */
             case IRC::QUIT:
                 break;
                 /*  $info = ($this->message) ? ' (' . $this->message . ')' : '';
                     $text = $timestamp . ' ' . $this->userNick . ' (~' . $this->userName . '@' . $this->userHost . ') has quit.' . $info . "\r\n";
                     $filename = 'QUIT'; //$this->msgChan;
                     return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */
             /*  $info = ($this->message) ? ' (' . $this->message . ')' : '';
                 $text = $timestamp . ' ' . $this->userNick . ' (~' . $this->userName . '@' . $this->userHost . ') has quit.' . $info . "\r\n";
                 $filename = 'QUIT'; //$this->msgChan;
                 return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */
             case IRC::KICK:
                 break;
                 /*  $info = ($this->message) ? ' (' . $this->message . ')' : '';
                     $special = explode(' ', $this->source);
                     $text = $timestamp . ' * ' . $special [1] . ' was kicked by ' . $special[0] . ' ' . $info . "\r\n";
                     return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */
             /*  $info = ($this->message) ? ' (' . $this->message . ')' : '';
                 $special = explode(' ', $this->source);
                 $text = $timestamp . ' * ' . $special [1] . ' was kicked by ' . $special[0] . ' ' . $info . "\r\n";
                 return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */
             case IRC::NOTICE:
                 break;
                 /* return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */
         }
     } else {
     }
 }
Exemple #6
0
 private function settingFile($mode, $content = null, $object = null)
 {
     $object = $object ? $object : $this;
     $filename = (new ReflectionClass($object))->getShortName() . '.json';
     switch ($mode) {
         case self::FILE_LOAD:
             $pathname = implode(DIRECTORY_SEPARATOR, [ROOT_DIR, self::SETTING_PATHNAME, Config::getServerName(), $filename]);
             if (!file_exists($pathname)) {
                 return false;
             }
             return file_get_contents($pathname);
         case self::FILE_SAVE:
             $pathname = implode(DIRECTORY_SEPARATOR, [ROOT_DIR, self::SETTING_PATHNAME, Config::getServerName()]);
             if (!is_dir($pathname)) {
                 mkdir($pathname, 0755, true);
             }
             $pathname = implode(DIRECTORY_SEPARATOR, [$pathname, $filename]);
             return file_put_contents($pathname, $content);
     }
     return false;
 }