diff --git a/src/danog/MadelineProto/FastAPI.php b/src/danog/MadelineProto/FastAPI.php index d5072d6a..31eab779 100644 --- a/src/danog/MadelineProto/FastAPI.php +++ b/src/danog/MadelineProto/FastAPI.php @@ -115,7 +115,9 @@ class FastAPI extends API $API = new API($session->getSessionPath(), $settings); yield from $API->initAsynchronously(); unset($API); + Logger::log("Destroying temporary MadelineProto..."); while (\gc_collect_cycles()); + Logger::log("Destroyed temporary MadelineProto!"); return null; // Should start IPC server } return yield from $this->tryConnect($session->getIpcPath()); diff --git a/src/danog/MadelineProto/Logger.php b/src/danog/MadelineProto/Logger.php index 62094413..6713ce24 100644 --- a/src/danog/MadelineProto/Logger.php +++ b/src/danog/MadelineProto/Logger.php @@ -224,7 +224,7 @@ class Logger 10*1000, function () use ($max_size) { \clearstatcache(true, $this->optional); - if (\filesize($this->optional) >= $max_size) { + if (\file_exists($this->optional) && \filesize($this->optional) >= $max_size) { $this->stdout = null; \unlink($this->optional); $this->stdout = new ResourceOutputStream(\fopen($this->optional, 'a')); diff --git a/src/danog/MadelineProto/Wrappers/Start.php b/src/danog/MadelineProto/Wrappers/Start.php index 6fca52e0..c08c4132 100644 --- a/src/danog/MadelineProto/Wrappers/Start.php +++ b/src/danog/MadelineProto/Wrappers/Start.php @@ -53,7 +53,7 @@ trait Start $this->serialize(); return yield from $this->fullGetSelf(); } - if ($this->authorized === MTProto::NOT_LOGGED_IN) { + if ((yield $this->getAuthorization()) === MTProto::NOT_LOGGED_IN) { if (isset($_POST['phone_number'])) { yield from $this->webPhoneLogin(); } elseif (isset($_POST['token'])) { @@ -61,26 +61,26 @@ trait Start } else { yield from $this->webEcho(); } - } elseif ($this->authorized === MTProto::WAITING_CODE) { + } elseif ((yield $this->getAuthorization()) === MTProto::WAITING_CODE) { if (isset($_POST['phone_code'])) { yield from $this->webCompletePhoneLogin(); } else { yield from $this->webEcho("You didn't provide a phone code!"); } - } elseif ($this->authorized === MTProto::WAITING_PASSWORD) { + } elseif ((yield $this->getAuthorization()) === MTProto::WAITING_PASSWORD) { if (isset($_POST['password'])) { yield from $this->webComplete2faLogin(); } else { yield from $this->webEcho("You didn't provide the password!"); } - } elseif ($this->authorized === MTProto::WAITING_SIGNUP) { + } elseif ((yield $this->getAuthorization()) === MTProto::WAITING_SIGNUP) { if (isset($_POST['first_name'])) { yield from $this->webCompleteSignup(); } else { yield from $this->webEcho("You didn't provide the first name!"); } } - if ($this->authorized === MTProto::LOGGED_IN) { + if ((yield $this->getAuthorization()) === MTProto::LOGGED_IN) { $this->serialize(); return yield from $this->fullGetSelf(); } diff --git a/src/danog/MadelineProto/Wrappers/Templates.php b/src/danog/MadelineProto/Wrappers/Templates.php index 4099663a..2ae412a6 100644 --- a/src/danog/MadelineProto/Wrappers/Templates.php +++ b/src/danog/MadelineProto/Wrappers/Templates.php @@ -20,6 +20,7 @@ namespace danog\MadelineProto\Wrappers; use function Amp\ByteStream\getOutputBufferStream; +use \danog\MadelineProto\MTProto; trait Templates { @@ -33,8 +34,8 @@ trait Templates private function webEcho(string $message = ''): \Generator { $stdout = getOutputBufferStream(); - switch ($this->authorized) { - case self::NOT_LOGGED_IN: + switch (yield $this->getAuthorization()) { + case MTProto::NOT_LOGGED_IN: if (isset($_POST['type'])) { if ($_POST['type'] === 'phone') { yield $stdout->write($this->webEchoTemplate('Enter your phone number
'.$message.'', '')); @@ -45,13 +46,13 @@ trait Templates yield $stdout->write($this->webEchoTemplate('Do you want to login as user or bot?
'.$message.'', '')); } break; - case self::WAITING_CODE: + case MTProto::WAITING_CODE: yield $stdout->write($this->webEchoTemplate('Enter your code
'.$message.'', '')); break; - case self::WAITING_PASSWORD: + case MTProto::WAITING_PASSWORD: yield $stdout->write($this->webEchoTemplate('Enter your password
'.$message.'', '')); break; - case self::WAITING_SIGNUP: + case MTProto::WAITING_SIGNUP: yield $stdout->write($this->webEchoTemplate('Sign up please
'.$message.'', '')); break; }