/** * @TODO DESCR * @param array|string $mask * @param mixed $msg */ public function onPart($mask, $msg = null) { if (is_string($mask)) { $mask = IRC::parseUsermask($mask); } if ($mask['nick'] === $this->irc->nick && $mask['user'] === $this->irc->user) { $this->destroy(); } else { unset($this->nicknames[$mask['nick']]); } }
/** * Called when new data received * @return void */ public function onRead() { while (($line = $this->readline()) !== null) { if ($line === '') { continue; } if (strlen($line) > 512) { Daemon::$process->log('IRCClientConnection error: buffer overflow.'); $this->finish(); return; } $line = binarySubstr($line, 0, -strlen($this->EOL)); $p = strpos($line, ' :', 1); $max = $p !== false ? substr_count($line, " ", 0, $p + 1) + 1 : 18; $e = explode(" ", $line, $max); $i = 0; $from = IRC::parseUsermask($e[$i][0] === ':' ? binarySubstr($e[$i++], 1) : null); $cmd = $e[$i++]; $args = []; for ($s = min(sizeof($e), 14); $i < $s; ++$i) { if ($e[$i][0] === ':') { $args[] = binarySubstr($e[$i], 1); break; } $args[] = $e[$i]; } if (ctype_digit($cmd)) { $code = (int) $cmd; $cmd = isset(IRC::$codes[$code]) ? IRC::$codes[$code] : $code; } $this->lastLine = $line; $this->onCommand($from, $cmd, $args); } if (strlen($this->buf) > 512) { Daemon::$process->log('IRCClientConnection error: buffer overflow.'); $this->finish(); } }
/** * @TODO * @param string $from From * @param string $cmd Command * @param array $args Arguments */ public function commandArr($from, $cmd, $args) { if ($from === null) { $from = $this->pool->config->servername->value; } if (is_string($args)) { Daemon::log(get_class($this) . '->commandArr: args is string'); return; } $cmd = IRC::getCodeByCommand($cmd); $line = ':' . $from . ' ' . $cmd; for ($i = 0, $s = sizeof($args); $i < $s; ++$i) { if ($i + 1 === $s && strpos($args[$i], " ") !== false) { $line .= ' :'; } else { $line .= ' '; } $line .= $args[$i]; } $this->writeln($line); if ($this->pool->protologging && $cmd !== 'PONG') { Daemon::log('=>=>=>=> ' . json_encode($line)); } }
/** * @TODO DESCR * @param array|string $mask * @return $this */ public function setUsermask($mask) { if (is_string($mask)) { $mask = IRC::parseUsermask($mask); } $this->setUnverified($mask['unverified'])->setUser($mask['user'])->setNick($mask['nick'])->setHost($mask['host']); return $this; }