示例#1
0
 public function dropError($text, $code = 1, $additional = false)
 {
     Output::string($this->getScript() . ": " . Style::red($text) . PHP_EOL . ($additional ? $additional . PHP_EOL : ''));
     die($code);
 }
示例#2
0
文件: Pinch.php 项目: donatj/pinch
 function connect()
 {
     echo "";
     //clear screen
     echo str_repeat(PHP_EOL, self::OUTPUT_ROWS + 2);
     $this->conn = fsockopen($this->server, $this->port, $errno, $errstr);
     if ($this->password) {
         $this->send("PASS " . $this->password);
     }
     $this->send("USER username hostname servername :real name");
     $this->send("NICK " . $this->user);
     while ($input = trim(fgets($this->conn))) {
         stream_set_timeout($this->conn, 3600);
         if (preg_match("|^PING :(.*)\$|i", $input, $matches)) {
             $this->send("PONG :{$matches[1]}");
             $this->send("JOIN " . $this->channel);
             break;
         }
         $this->statusbar($input);
     }
     while ($input = trim(fgets($this->conn))) {
         stream_set_timeout($this->conn, 3600);
         switch (true) {
             //keep alive
             case preg_match("|^PING :(.*)\$|i", $input, $matches):
                 echo Style::light_gray("[ SERVER PING {$matches[1]} ]\n");
                 $this->send("PONG :{$matches[1]}");
                 break;
                 //messages with recipients
             //messages with recipients
             case preg_match("|^:(?P<from>.+?)!.* (?P<cmd>[A-Z]*) (?P<to>.+?) :(?P<msg>.*)\$|i", $input, $matches):
                 $text = sprintf("%-12s%s -> %s: %s\n", $matches["cmd"], $matches["from"], $matches["to"], $matches["msg"]);
                 if ($matches["to"][0] == '#') {
                     $matches['reply'] = $matches["to"];
                     echo Style::cyan($text);
                 } else {
                     $matches['reply'] = $matches["from"];
                     echo Style::light_cyan($text);
                 }
                 foreach ($this->events['msg'] as $event) {
                     if (preg_match($event['match'], $event['justmsg'] ? $matches["msg"] : $input, $lmatches)) {
                         $event['lambda']($this, $lmatches, $matches);
                     }
                 }
                 break;
                 //messages without recipients
             //messages without recipients
             case preg_match("|^:(?P<from>.+?)!.* (?P<cmd>[A-Z]*) :(?P<msg>.*)\$|i", $input, $matches):
                 echo Style::blue(sprintf("%-12s%s <- %s\n", $matches["cmd"], $matches["msg"], $matches["from"]));
                 break;
                 //kick everything else out to our shell
             //kick everything else out to our shell
             default:
                 foreach ($this->events['on'] as $event) {
                     if (preg_match($event['match'], $event['justmsg'] ? $matches["msg"] : $input, $lmatches)) {
                         $event['lambda']($this, $lmatches);
                     }
                 }
                 break;
         }
         $this->statusbar($input);
     }
 }