From 7c863e935331b3c6b50bc6c8dfb30ce27a163b82 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Thu, 18 Feb 2021 01:13:06 +0800 Subject: [PATCH] Limit MiraiConsoleImplementation.backendAccess --- .../mirai-console/src/MiraiConsoleImplementation.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/mirai-console/src/MiraiConsoleImplementation.kt b/backend/mirai-console/src/MiraiConsoleImplementation.kt index 428ca1b97..da85d7ddd 100644 --- a/backend/mirai-console/src/MiraiConsoleImplementation.kt +++ b/backend/mirai-console/src/MiraiConsoleImplementation.kt @@ -31,6 +31,7 @@ import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.LoginSolver import net.mamoe.mirai.utils.MiraiLogger +import java.lang.IllegalStateException import java.nio.file.Path import java.util.* import java.util.concurrent.locks.ReentrantLock @@ -217,7 +218,13 @@ public interface MiraiConsoleImplementation : CoroutineScope { public val resolvedPlugins: MutableList } - public val backendAccess: BackendAccess get() = backendAccessInstance + public val backendAccess: BackendAccess get() { + if (instanceInitialized) { + if (this === instance) + return backendAccessInstance + } + throw IllegalStateException("Permission denied") + } public companion object { private val backendAccessInstance = object : BackendAccess { @@ -226,6 +233,7 @@ public interface MiraiConsoleImplementation : CoroutineScope { } internal lateinit var instance: MiraiConsoleImplementation + internal val instanceInitialized: Boolean get() = ::instance.isInitialized private val initLock = ReentrantLock() /**