175: $unlock(); 176: $monitor = Server::startMe($session); 177: EventLoop::queue(static function () use ($cancelIpc, $monitor): void { 178: try { 179: $cancelIpc->complete($monitor->await()); 180: } catch (\Throwable $e) { 181: $cancelIpc->error($e); 182: } 183: }); 184: return $ipcSocket ?? self::tryConnect($session->getIpcPath(), $cancelIpc->getFuture()); 185: } elseif (!class_exists($class)) { 186: // Have lock, can't use it 187: $unlock(); 188: Logger::log("Session has event handler (class $class), but it's not started.", Logger::ERROR); 189: Logger::log("We don't have access to the event handler class, so we can't start it.", Logger::ERROR); 190: Logger::log('Please start the event handler or unset it to use the IPC server.', Logger::ERROR); 191: return $ipcSocket ?? self::tryConnect($session->getIpcPath(), $cancelIpc->getFuture(), customE: new AssertionError("Please make sure the $class class is in scope, or that the event handler is running (in a separate process or in the current process).")); 192: } elseif (is_subclass_of($class, EventHandler::class)) { 193: EventHandler::cachePlugins($class); 194: } 195: } elseif ($lightState) { 196: $class = $lightState->getEventHandler(); 197: if ($class && !class_exists($class)) { 198: // Have lock, can't use it 199: $unlock(); 200: Logger::log("Session has event handler, but it's not started.", Logger::ERROR); 201: Logger::log("We don't have access to the event handler class, so we can't start it.", Logger::ERROR); 202: Logger::log('Please start the event handler or unset it to use the IPC server.', Logger::ERROR); 203: throw new AssertionError("Please make sure the $class class is in scope, or that the event handler is running (in a separate process or in the current process)."); 204: } elseif ($class && is_subclass_of($class, EventHandler::class)) { 205: EventHandler::cachePlugins($class); 206: } 207: } elseif ($exists) { 208: throw new AssertionError("Could not read the lightstate file, check logs!"); 209: } 210: 211: $tempId = Shutdown::addCallback($unlock = static function () use ($unlock): void { 212: Logger::log('Unlocking exclusive session lock!'); 213: $unlock(); 214: Logger::log('Unlocked exclusive session lock!'); 215: });