Skip to content

Commit

Permalink
Make sure the event handler class is in scope before unserializing
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Jul 25, 2023
1 parent 2e1b564 commit 0114106
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Serialization.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Amp\Future;
use Amp\Ipc\Sync\ChannelledSocket;
use Amp\TimeoutException;
use AssertionError;
use danog\MadelineProto\Db\DbPropertiesFactory;
use danog\MadelineProto\Db\DriverArray;
use danog\MadelineProto\Ipc\Server;
Expand Down Expand Up @@ -190,13 +191,25 @@ public static function unserialize(SessionPaths $session, SettingsAbstract $sett
} elseif (!\class_exists($class)) {
// Have lock, can't use it
$unlock();
Logger::log("Session has event handler, but it's not started.", Logger::ERROR);
Logger::log("Session has event handler (class $class), but it's not started.", Logger::ERROR);
Logger::log("We don't have access to the event handler class, so we can't start it.", Logger::ERROR);
Logger::log('Please start the event handler or unset it to use the IPC server.', Logger::ERROR);
return $ipcSocket ?? self::tryConnect($session->getIpcPath(), $cancelIpc->getFuture());
} elseif (\is_subclass_of($class, EventHandler::class)) {
EventHandler::cachePlugins($class);
}
} else {
$class = $lightState->getEventHandler();
if ($class && !\class_exists($class)) {
// Have lock, can't use it
$unlock();
Logger::log("Session has event handler, but it's not started.", Logger::ERROR);
Logger::log("We don't have access to the event handler class, so we can't start it.", Logger::ERROR);
Logger::log('Please start the event handler or unset it to use the IPC server.', Logger::ERROR);
throw new AssertionError("Please make sure the $class class is in scope.");
} elseif ($class && \is_subclass_of($class, EventHandler::class)) {
EventHandler::cachePlugins($class);
}
}

$tempId = Shutdown::addCallback($unlock = static function () use ($unlock): void {
Expand Down

0 comments on commit 0114106

Please sign in to comment.