Ejemplo n.º 1
0
 public function run()
 {
     while ($this->running) {
         while ($this->buffer->hasMoreWrite()) {
             $line = IRCLine::parseInternalLine($this->buffer->nextWrite(), $signal, $client);
             if ($signal === IRCLine::SIGNAL_STD_LINE) {
                 if (isset($this->sockets[$client])) {
                     socket_write($this->sockets[$client], $line . "\r\n");
                 }
             } elseif ($signal === IRCLine::SIGNAL_CLOSE_SESSION) {
                 if (isset($this->sockets[$line])) {
                     socket_close($this->sockets[$line]);
                     unset($this->sockets[$line]);
                 }
             }
         }
         while (($newSock = socket_accept($this->serverSocket)) !== false) {
             socket_getpeername($newSock, $address, $port);
             $identifier = "{$address}:{$port}";
             $this->buffer->addRead(chr(IRCLine::SIGNAL_OPEN_SESSION) . $identifier);
             $this->sockets[$identifier] = $newSock;
         }
         while (($line = $this->readLine($identifier)) !== false) {
             $this->buffer->addRead(chr(IRCLine::SIGNAL_STD_LINE) . "{$identifier} {$line}");
         }
     }
     foreach ($this->sockets as $socket) {
         socket_write($socket, "ERROR :Server shutting down\r\n");
         socket_close($socket);
     }
     socket_close($this->serverSocket);
 }