diff --git a/api/src/main/kotlin/icu/h2l/api/HyperZoneApi.kt b/api/src/main/kotlin/icu/h2l/api/HyperZoneApi.kt index 7bdfbf5f..0cc05c7f 100644 --- a/api/src/main/kotlin/icu/h2l/api/HyperZoneApi.kt +++ b/api/src/main/kotlin/icu/h2l/api/HyperZoneApi.kt @@ -60,7 +60,7 @@ interface HyperZoneApi : /** * 凭证渠道注册表。 * - * 子模块注册时,核心层会将 [HyperSubModule.credentialChannelIds] 中的渠道 ID 自动写入此注册表。 + * 子模块应在 [HyperSubModule.register] 阶段通过此注册表声明自己使用的凭证渠道 ID。 * 外部插件也可以通过此入口主动注册自定义凭证渠道。 */ val credentialChannelRegistry: CredentialChannelRegistry diff --git a/api/src/main/kotlin/icu/h2l/api/module/HyperSubModule.kt b/api/src/main/kotlin/icu/h2l/api/module/HyperSubModule.kt index d90f4c69..137652ce 100644 --- a/api/src/main/kotlin/icu/h2l/api/module/HyperSubModule.kt +++ b/api/src/main/kotlin/icu/h2l/api/module/HyperSubModule.kt @@ -27,17 +27,6 @@ import icu.h2l.api.HyperZoneApi * HyperZoneLogin 子模块的标准接入点。 */ interface HyperSubModule { - /** - * 该子模块将向核心层提交的凭证渠道 ID 集合(对应 [icu.h2l.api.profile.HyperZoneCredential.channelId])。 - * - * 核心层在调用 [register] 之前会自动将这些渠道 ID 写入 - * [icu.h2l.api.profile.CredentialChannelRegistry],以便后续对子模块行为进行定向控制。 - * - * 不提交凭证的子模块(如 data-merge、safe)可使用默认空集合。 - */ - val credentialChannelIds: Set - get() = emptySet() - /** * 将当前子模块注册到指定的 [HyperZoneApi] 运行时中。 */ diff --git a/api/src/main/kotlin/icu/h2l/api/player/HyperZonePlayer.kt b/api/src/main/kotlin/icu/h2l/api/player/HyperZonePlayer.kt index e11e3dba..7f889bff 100644 --- a/api/src/main/kotlin/icu/h2l/api/player/HyperZonePlayer.kt +++ b/api/src/main/kotlin/icu/h2l/api/player/HyperZonePlayer.kt @@ -128,7 +128,7 @@ interface HyperZonePlayer { * 该值在登录管理器提交凭证时由核心层自动记录; * 在凭证提交前(或 [resetVerify] 后)返回 null。 * - * 示例值:`"floodgate"`、`"offline"`、`"yggdrasil"`。 + * 示例值:`"floodgate"`、`"offline"`、`"yggdrasil:mojang"`。 */ val authChannelId: String? get() = null diff --git a/api/src/main/kotlin/icu/h2l/api/profile/CredentialChannelAbility.kt b/api/src/main/kotlin/icu/h2l/api/profile/CredentialChannelAbility.kt deleted file mode 100644 index 7813e4d8..00000000 --- a/api/src/main/kotlin/icu/h2l/api/profile/CredentialChannelAbility.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of HyperZoneLogin, licensed under the GNU Affero General Public License v3.0 or later. - * - * Copyright (C) ksqeib (庆灵) - * Copyright (C) contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -package icu.h2l.api.profile - -/** - * 凭证渠道能力描述。 - * - * 当凭证渠道通过 [CredentialChannelRegistry.registerChannel] 注册时, - * 核心层会根据当前配置计算出该渠道的能力集合并返回。 - * 子模块可据此决定在各自业务流程中应当开放还是禁止特定操作。 - * - * @property channelId 对应的凭证渠道唯一标识 - * @property canRegister 该渠道是否允许通过凭证注册(建档)新玩家档案。 - * 若为 `false`,子模块不应调用 [HyperZoneUserService.create] 等新建档案接口。 - */ -data class CredentialChannelAbility( - val channelId: String, - val canRegister: Boolean, -) - diff --git a/api/src/main/kotlin/icu/h2l/api/profile/CredentialChannelRegistry.kt b/api/src/main/kotlin/icu/h2l/api/profile/CredentialChannelRegistry.kt index c758fcdd..3c4879d2 100644 --- a/api/src/main/kotlin/icu/h2l/api/profile/CredentialChannelRegistry.kt +++ b/api/src/main/kotlin/icu/h2l/api/profile/CredentialChannelRegistry.kt @@ -25,19 +25,18 @@ package icu.h2l.api.profile * 凭证渠道注册表。 * * 子模块在注册时需向此注册表声明自己将使用的凭证渠道 ID(即 [HyperZoneCredential.channelId])。 - * 核心层可通过此注册表了解系统中存在哪些认证渠道,并支持后续的定向行为控制。 + * 核心层可通过此注册表了解系统中存在哪些认证渠道。 */ interface CredentialChannelRegistry { /** - * 注册一个凭证渠道 ID,并返回该渠道当前的能力描述。 + * 注册一个凭证渠道 ID。 * - * 同一渠道 ID 可被重复注册(幂等),不会报错,但每次调用均会返回最新能力。 + * 同一渠道 ID 可被重复注册(幂等),不会报错。 * * @param channelId 凭证渠道唯一标识,与 [HyperZoneCredential.channelId] 对应 - * @return 由核心层根据当前配置计算出的 [CredentialChannelAbility] */ - fun registerChannel(channelId: String): CredentialChannelAbility + fun registerChannel(channelId: String) /** * 判断指定凭证渠道 ID 是否已注册。 @@ -48,13 +47,6 @@ interface CredentialChannelRegistry { * 返回当前已注册的所有凭证渠道 ID 的快照(不可变集合)。 */ fun getRegisteredChannelIds(): Set - - /** - * 获取指定渠道的能力描述。 - * - * @return 若该渠道已注册则返回对应 [CredentialChannelAbility],否则返回 `null`。 - */ - fun getChannelAbility(channelId: String): CredentialChannelAbility? } /** diff --git a/api/src/main/kotlin/icu/h2l/api/profile/HyperZoneCredential.kt b/api/src/main/kotlin/icu/h2l/api/profile/HyperZoneCredential.kt index ab3ca7af..ed39b1fe 100644 --- a/api/src/main/kotlin/icu/h2l/api/profile/HyperZoneCredential.kt +++ b/api/src/main/kotlin/icu/h2l/api/profile/HyperZoneCredential.kt @@ -35,7 +35,7 @@ import java.util.* */ interface HyperZoneCredential : IPropertiesHolder { /** - * 认证渠道唯一标识,由子模块负责稳定定义。 + * 认证渠道唯一标识,可用于区分不同上游。 */ val channelId: String diff --git a/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/FloodgateMessages.kt b/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/FloodgateMessages.kt index 619c5d3e..0667ff29 100644 --- a/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/FloodgateMessages.kt +++ b/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/FloodgateMessages.kt @@ -33,17 +33,6 @@ object FloodgateMessages { return render("init-player-failed") } - - fun registrationDisabled(player: HyperZonePlayer): Component { - return render(player, "registration-disabled") - } - - fun registrationDisabledByName(playerName: String): Component { - return render("registration-disabled", - HyperZoneMessagePlaceholder.text("player", playerName) - ) - } - fun createBlocked(player: HyperZonePlayer): Component { return render(player, "create-blocked") } diff --git a/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/FloodgateSubModule.kt b/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/FloodgateSubModule.kt index 8240681e..f5b2e354 100644 --- a/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/FloodgateSubModule.kt +++ b/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/FloodgateSubModule.kt @@ -44,9 +44,10 @@ import icu.h2l.login.auth.floodgate.service.FloodgateSessionHolder import java.util.* class FloodgateSubModule : HyperSubModule { - override val credentialChannelIds: Set = setOf("floodgate") override fun register(api: HyperZoneApi) { + api.credentialChannelRegistry.registerChannel("floodgate") + HyperZoneModuleMessageResources.copyBundledLocales(api.dataDirectory, "auth-floodgate", javaClass.classLoader) val config = FloodgateAuthConfigLoader.load(api.dataDirectory) FloodgateDebug.configure(config.debug) diff --git a/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/service/FloodgateAuthService.kt b/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/service/FloodgateAuthService.kt index 4724ffde..071f679b 100644 --- a/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/service/FloodgateAuthService.kt +++ b/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/service/FloodgateAuthService.kt @@ -24,7 +24,6 @@ package icu.h2l.login.auth.floodgate.service import icu.h2l.api.HyperZoneApi import icu.h2l.api.db.InGameProfileCandidate import icu.h2l.login.auth.floodgate.config.FloodgateDebug -import icu.h2l.api.profile.CredentialChannelRegistryProvider import icu.h2l.api.profile.HyperZoneUserService import icu.h2l.api.profile.HyperZoneUserServiceProvider import icu.h2l.login.auth.floodgate.FloodgateMessages @@ -113,24 +112,12 @@ class FloodgateAuthService( xuid = xuid, userName = userName, userUUID = userUUID, + ) ?: createAndBindProfileIfAllowed( + xuid = xuid, + userName = userName, + userUUID = userUUID, + suggestedProfileCreateUuid = suggestedProfileCreateUuid, ) - ?: run { - val channelAbility = CredentialChannelRegistryProvider.getOrNull()?.getChannelAbility("floodgate") - if (channelAbility?.canRegister == false) { - return CompleteResult( - handled = true, - passed = false, - disconnectOnFailure = false, - userMessage = FloodgateMessages.registrationDisabledByName(playerName) - ) - } - createAndBindProfileIfAllowed( - xuid = xuid, - userName = userName, - userUUID = userUUID, - suggestedProfileCreateUuid = suggestedProfileCreateUuid, - ) - } if (knownUserUUID == null) { trace("complete blocked channel=$channel player=$playerName: no known profile id") diff --git a/subplugin/auth-floodgate/src/main/resources/messages/auth-floodgate/en_us.conf b/subplugin/auth-floodgate/src/main/resources/messages/auth-floodgate/en_us.conf index 5a9c61c7..04ba0a10 100644 --- a/subplugin/auth-floodgate/src/main/resources/messages/auth-floodgate/en_us.conf +++ b/subplugin/auth-floodgate/src/main/resources/messages/auth-floodgate/en_us.conf @@ -1,7 +1,6 @@ auth-floodgate { init-player-failed = "Floodgate login failed: failed to initialize the login-session player." temporary-profile-failed = "Floodgate login failed: failed to initialize the temporary profile." - registration-disabled = "Floodgate trusted authentication has completed, but the administrator has disabled new player registration for this channel. If you already have a profile, use /bindcode use [binding-code]." create-blocked = "Floodgate trusted authentication has completed, but the current registration name cannot create a Profile. For a name conflict, use /rename [new-registration-name]; for a UUID conflict, this channel account needs to be linked to an existing profile: use /bindcode use [binding-code]." complete-failed = "Floodgate login failed: an error occurred during authentication completion." generic-disconnect = "Floodgate login failed." diff --git a/subplugin/auth-floodgate/src/main/resources/messages/auth-floodgate/zh_cn.conf b/subplugin/auth-floodgate/src/main/resources/messages/auth-floodgate/zh_cn.conf index 7795b82a..33aee845 100644 --- a/subplugin/auth-floodgate/src/main/resources/messages/auth-floodgate/zh_cn.conf +++ b/subplugin/auth-floodgate/src/main/resources/messages/auth-floodgate/zh_cn.conf @@ -1,7 +1,6 @@ auth-floodgate { init-player-failed = "Floodgate 登录失败:登录对象初始化失败。" temporary-profile-failed = "Floodgate 登录失败:临时档案初始化失败。" - registration-disabled = "Floodgate 已完成可信认证,但当前渠道已被管理员禁止新玩家注册。若你已有档案,请使用 /bindcode use [绑定码]。" create-blocked = "Floodgate 已完成可信认证,但当前注册名无法创建 Profile。名称冲突请使用 /rename [新注册名];UUID 冲突说明该渠道账号需要 link 到已有档案,请使用 /bindcode use [绑定码]。" complete-failed = "Floodgate 登录失败:认证完成阶段出错。" generic-disconnect = "Floodgate 登录失败。" diff --git a/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/OfflineAuthMessages.kt b/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/OfflineAuthMessages.kt index 19b9cbbd..ddf435e1 100644 --- a/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/OfflineAuthMessages.kt +++ b/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/OfflineAuthMessages.kt @@ -52,8 +52,6 @@ object OfflineAuthMessages { val PROFILE_ATTACH_FAILED_AFTER_LOGIN: Component get() = render("common.profile-attach-failed-after-login") - val REGISTER_DISABLED: Component - get() = render("register.disabled") val REGISTER_SUCCESS: Component get() = render("register.success") val REGISTER_FAILED: Component diff --git a/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/OfflineSubModule.kt b/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/OfflineSubModule.kt index 9dc7f0dd..58f1e641 100644 --- a/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/OfflineSubModule.kt +++ b/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/OfflineSubModule.kt @@ -49,9 +49,9 @@ class OfflineSubModule : HyperSubModule { lateinit var offlineAuthRepository: OfflineAuthRepository lateinit var offlineAuthService: OfflineAuthService - override val credentialChannelIds: Set = setOf("offline") - override fun register(api: HyperZoneApi) { + api.credentialChannelRegistry.registerChannel("offline") + val proxy = api.proxy val dataDirectory = api.dataDirectory val databaseManager: HyperZoneDatabaseManager = api.databaseManager diff --git a/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineAuthService.kt b/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineAuthService.kt index 666387d1..98f67f65 100644 --- a/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineAuthService.kt +++ b/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineAuthService.kt @@ -25,7 +25,6 @@ import com.velocitypowered.api.proxy.Player import com.velocitypowered.api.proxy.ProxyServer import icu.h2l.api.event.auth.AuthenticationFailureEvent import icu.h2l.api.player.HyperZonePlayerAccessor -import icu.h2l.api.profile.CredentialChannelRegistryProvider import icu.h2l.api.profile.HyperZoneCredentialFlowProvider import icu.h2l.api.profile.HyperZoneUserService import icu.h2l.login.auth.offline.OfflineAuthMessages @@ -63,12 +62,6 @@ class OfflineAuthService( fun register(player: Player, password: String): Result { val hyperZonePlayer = playerAccessor.getByPlayer(player) - // 检查凭证渠道能力:若该渠道已禁用注册,直接返回错误 - val channelAbility = CredentialChannelRegistryProvider.getOrNull()?.getChannelAbility("offline") - if (channelAbility?.canRegister == false) { - return Result(false, OfflineAuthMessages.REGISTER_DISABLED) - } - val username = hyperZonePlayer.getSubmittedCredentials().filterIsInstance() .firstOrNull()?.getRegistrationName() ?: player.username val normalizedName = username.lowercase() diff --git a/subplugin/auth-offline/src/main/resources/messages/auth-offline/en_us.conf b/subplugin/auth-offline/src/main/resources/messages/auth-offline/en_us.conf index a00c891a..2ea0dd0b 100644 --- a/subplugin/auth-offline/src/main/resources/messages/auth-offline/en_us.conf +++ b/subplugin/auth-offline/src/main/resources/messages/auth-offline/en_us.conf @@ -12,7 +12,6 @@ auth-offline { } register { - disabled = "[HyperZoneLogin] New player registration has been disabled by the administrator for this authentication channel." success = "[HyperZoneLogin] Registration successful, and you have been logged in automatically." failed = "[HyperZoneLogin] Registration failed. Please try again later." password-already-set = "[HyperZoneLogin] You have already set an offline password. No need to do it again." diff --git a/subplugin/auth-offline/src/main/resources/messages/auth-offline/zh_cn.conf b/subplugin/auth-offline/src/main/resources/messages/auth-offline/zh_cn.conf index 059cca93..ef0fc2c1 100644 --- a/subplugin/auth-offline/src/main/resources/messages/auth-offline/zh_cn.conf +++ b/subplugin/auth-offline/src/main/resources/messages/auth-offline/zh_cn.conf @@ -12,7 +12,6 @@ auth-offline { } register { - disabled = "[HyperZoneLogin] 当前认证渠道已被管理员禁止新玩家注册" success = "[HyperZoneLogin] 已成功注册,已为你自动登录" failed = "[HyperZoneLogin] 注册失败,请稍后再试" password-already-set = "[HyperZoneLogin] 你已设置过离线密码,无需重复操作" diff --git a/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt index b33a34f1..3783095f 100644 --- a/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt +++ b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt @@ -25,6 +25,7 @@ import icu.h2l.api.profile.HyperZoneCredential import icu.h2l.api.util.IPropertiesHolder import icu.h2l.api.util.PropertiesHolder import icu.h2l.login.auth.online.db.EntryDatabaseHelper +import icu.h2l.login.auth.online.util.ChannelIdUtil import java.util.* class YggdrasilHyperZoneCredential( @@ -35,7 +36,7 @@ class YggdrasilHyperZoneCredential( private val suggestedProfileCreateUuid: UUID?, private val knownUserUUID: UUID? = null, ) : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() { - override val channelId: String = CHANNEL_ID + override val channelId: String = ChannelIdUtil.getChannelId(entryId) override val credentialId: String = "$entryId:$authenticatedUUID" init { @@ -79,8 +80,6 @@ class YggdrasilHyperZoneCredential( } companion object { - private const val CHANNEL_ID = "yggdrasil" - public const val YGGDRASIL_ENTRY_ID_PROPERTY = "yggdrasil-entry-id" } } diff --git a/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/main/YggdrasilSubModule.kt b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/main/YggdrasilSubModule.kt index 676991a7..4cd684a5 100644 --- a/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/main/YggdrasilSubModule.kt +++ b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/main/YggdrasilSubModule.kt @@ -37,6 +37,7 @@ import icu.h2l.login.auth.online.listener.AuthListener import icu.h2l.login.auth.online.listener.YggdrasilProfileLookupListener import icu.h2l.login.auth.online.manager.EntryConfigManager import icu.h2l.login.auth.online.manager.YggdrasilAuthModule +import icu.h2l.login.auth.online.util.ChannelIdUtil import java.util.* class YggdrasilSubModule : HyperSubModule { @@ -44,8 +45,6 @@ class YggdrasilSubModule : HyperSubModule { lateinit var entryTableManager: EntryTableManager lateinit var yggdrasilAuthModule: YggdrasilAuthModule - override val credentialChannelIds: Set = setOf("yggdrasil") - override fun register(api: HyperZoneApi) { val proxy = api.proxy val dataDirectory = api.dataDirectory @@ -66,6 +65,10 @@ class YggdrasilSubModule : HyperSubModule { entryConfigManager.loadAllConfigs() + entryConfigManager.getAllConfigs().forEach { (_, entry) -> + api.credentialChannelRegistry.registerChannel(ChannelIdUtil.getChannelId(entry.id)) + } + val userService = HyperZoneUserServiceProvider.get() val entryDatabaseHelper = EntryDatabaseHelper( databaseManager = databaseManager, diff --git a/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/message/YggdrasilMessages.kt b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/message/YggdrasilMessages.kt index 37da0ee8..d6dc7262 100644 --- a/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/message/YggdrasilMessages.kt +++ b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/message/YggdrasilMessages.kt @@ -29,14 +29,6 @@ import net.kyori.adventure.text.Component object YggdrasilMessages { private const val NAMESPACE = "auth-yggd" - /** - * 返回"注册已被禁用"的原因文本,用于作为 [profileResolveFailed] 的 reason 参数。 - */ - fun registrationDisabledReason(player: HyperZonePlayer): String { - val component = HyperZoneMessageServiceProvider.get().render(player, "$NAMESPACE.registration-disabled-reason") - return net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer.plainText().serialize(component) - } - fun authInProgress(player: HyperZonePlayer): Component { return render(player, "auth-in-progress") } diff --git a/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/service/YggdrasilCredentialService.kt b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/service/YggdrasilCredentialService.kt index 2c9aa8c6..a3911214 100644 --- a/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/service/YggdrasilCredentialService.kt +++ b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/service/YggdrasilCredentialService.kt @@ -25,14 +25,12 @@ import icu.h2l.api.player.HyperZonePlayer import icu.h2l.api.db.InGameProfileCandidate import icu.h2l.api.log.warn import icu.h2l.login.auth.online.config.YggdrasilDebug -import icu.h2l.api.profile.CredentialChannelRegistryProvider import icu.h2l.api.profile.HyperZoneUserService import icu.h2l.login.auth.online.config.EntryConfig import icu.h2l.login.auth.online.config.YggdrasilConfigLoader import icu.h2l.login.auth.online.credential.YggdrasilHyperZoneCredential import icu.h2l.login.auth.online.db.EntryDatabaseHelper import icu.h2l.login.auth.online.manager.EntryConfigManager -import icu.h2l.login.auth.online.message.YggdrasilMessages import icu.h2l.login.auth.online.record.YggdrasilCredentialPreparation import icu.h2l.login.auth.online.record.YggdrasilAuthResult import java.util.* @@ -71,14 +69,6 @@ class YggdrasilCredentialService( suggestedProfileCreateUuid = profileResolveUuid ) - val channelAbility = CredentialChannelRegistryProvider.getOrNull()?.getChannelAbility("yggdrasil") - if (channelAbility?.canRegister == false) { - return YggdrasilCredentialPreparation( - credentialToSubmit = probeCredential, - failureReason = YggdrasilMessages.registrationDisabledReason(handler) - ) - } - if (userService.canCreateUser(probeCredential)) { val createdUser = try { userService.createUser(probeCredential) diff --git a/velocity/src/main/kotlin/icu/h2l/login/config/AuthConfig.kt b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/util/ChannelIdUtil.kt similarity index 68% rename from velocity/src/main/kotlin/icu/h2l/login/config/AuthConfig.kt rename to subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/util/ChannelIdUtil.kt index ce1b107c..5efa3015 100644 --- a/velocity/src/main/kotlin/icu/h2l/login/config/AuthConfig.kt +++ b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/util/ChannelIdUtil.kt @@ -19,16 +19,14 @@ * */ -package icu.h2l.login.config +package icu.h2l.login.auth.online.util -import org.spongepowered.configurate.objectmapping.ConfigSerializable -import org.spongepowered.configurate.objectmapping.meta.Comment - -@Suppress("ANNOTATION_WILL_BE_APPLIED_ALSO_TO_PROPERTY_OR_FIELD") -@ConfigSerializable -data class AuthConfig( - @JvmField - @Comment("config.core.auth.disableRegistration") - val disableRegistration: List = emptyList(), -) +class ChannelIdUtil { + companion object { + private const val CHANNEL_ID_PREFIX = "yggdrasil" + fun getChannelId(entryId: String): String { + return "$CHANNEL_ID_PREFIX:$entryId" + } + } +} diff --git a/subplugin/auth-yggd/src/main/resources/messages/auth-yggd/en_us.conf b/subplugin/auth-yggd/src/main/resources/messages/auth-yggd/en_us.conf index 3025d24b..90140067 100644 --- a/subplugin/auth-yggd/src/main/resources/messages/auth-yggd/en_us.conf +++ b/subplugin/auth-yggd/src/main/resources/messages/auth-yggd/en_us.conf @@ -1,7 +1,6 @@ auth-yggd { auth-in-progress = "Yggdrasil authentication is in progress. Please wait…" auth-succeeded = "Yggdrasil authentication passed. Preparing your profile and skin data…" - registration-disabled-reason = "New player registration has been disabled by the administrator for this channel; if you already have a profile, use /bindcode use [binding-code]" profile-resolve-failed = " If the issue is a profile-creation name conflict, use /rename [new-registration-name]; if a UUID conflict is reported, this channel account needs to be linked to an existing profile: use /bindcode use [binding-code]." verify-complete-failed = " If the issue is a profile-creation name conflict, use /rename [new-registration-name]; if a UUID conflict is reported, this channel account needs to be linked to an existing profile: use /bindcode use [binding-code]." auth-failed = "Yggdrasil authentication failed: " diff --git a/subplugin/auth-yggd/src/main/resources/messages/auth-yggd/zh_cn.conf b/subplugin/auth-yggd/src/main/resources/messages/auth-yggd/zh_cn.conf index 11061bde..cdc48d92 100644 --- a/subplugin/auth-yggd/src/main/resources/messages/auth-yggd/zh_cn.conf +++ b/subplugin/auth-yggd/src/main/resources/messages/auth-yggd/zh_cn.conf @@ -1,7 +1,6 @@ auth-yggd { auth-in-progress = "正在进行 Yggdrasil 验证,请稍候…" auth-succeeded = "Yggdrasil 验证通过,正在准备档案与皮肤信息…" - registration-disabled-reason = "当前渠道已被管理员禁止新玩家注册;若你已有档案,请使用 /bindcode use [绑定码]" profile-resolve-failed = " 若当前是建档名称冲突,请使用 /rename [新注册名];若提示 UUID 冲突,说明该渠道账号需要 link 到已有档案,请使用 /bindcode use [绑定码]。" verify-complete-failed = " 若当前是建档名称冲突,请使用 /rename [新注册名];若提示 UUID 冲突,说明该渠道账号需要 link 到已有档案,请使用 /bindcode use [绑定码]。" auth-failed = "Yggdrasil 验证失败:" diff --git a/velocity/src/main/kotlin/icu/h2l/login/HyperZoneLoginMain.kt b/velocity/src/main/kotlin/icu/h2l/login/HyperZoneLoginMain.kt index e7062eb2..4f0c8af5 100644 --- a/velocity/src/main/kotlin/icu/h2l/login/HyperZoneLoginMain.kt +++ b/velocity/src/main/kotlin/icu/h2l/login/HyperZoneLoginMain.kt @@ -169,7 +169,7 @@ class HyperZoneLoginMain( // ── 第二步:根据 start.conf 中的 language 初始化配置注释 i18n 服务 ────────── ConfigCommentTranslatorProvider.bind(ConfigCommentI18nService(dataDirectory, logger, startConfig.language)) loadCoreConfig() - credentialChannelRegistry = CredentialChannelRegistryImpl(coreConfig.auth) + credentialChannelRegistry = CredentialChannelRegistryImpl() messageService = MessageService(dataDirectory, logger) messageService.load(coreConfig.messages) HyperZoneMessageServiceProvider.bind(messageService) @@ -290,15 +290,6 @@ class HyperZoneLoginMain( fun registerModule(module: HyperSubModule, api: HyperZoneApi) { try { - module.credentialChannelIds.forEach { channelId -> - val ability = credentialChannelRegistry.registerChannel(channelId) - logger.info( - "凭证渠道已注册: {} (模块: {}) [canRegister={}]", - channelId, - module.javaClass.simpleName, - ability.canRegister - ) - } module.register(api) logger.info("模块加载成功: ${module.javaClass.name}") } catch (e: Exception) { diff --git a/velocity/src/main/kotlin/icu/h2l/login/command/RenameCommand.kt b/velocity/src/main/kotlin/icu/h2l/login/command/RenameCommand.kt index a8a217d5..92177b79 100644 --- a/velocity/src/main/kotlin/icu/h2l/login/command/RenameCommand.kt +++ b/velocity/src/main/kotlin/icu/h2l/login/command/RenameCommand.kt @@ -28,7 +28,6 @@ import icu.h2l.api.command.HyperChatBrigadierRegistration import icu.h2l.api.command.HyperChatCommandExecutor import icu.h2l.api.command.HyperChatCommandInvocation import icu.h2l.api.message.HyperZoneMessagePlaceholder -import icu.h2l.api.profile.CredentialChannelRegistryProvider import icu.h2l.login.HyperZoneLoginMain import icu.h2l.login.manager.HyperZonePlayerManager import icu.h2l.login.message.MessageKeys @@ -102,16 +101,6 @@ class RenameCommand : HyperChatCommandExecutor { return } - val channelAbility = CredentialChannelRegistryProvider.getOrNull()?.getChannelAbility(pendingCredential.channelId) - if (channelAbility?.canRegister == false) { - messages.send( - source, - MessageKeys.Rename.EVENT_FAILED, - HyperZoneMessagePlaceholder.text("reason", "当前渠道 [${pendingCredential.channelId}] 已被管理员禁止新玩家注册") - ) - return - } - val renamedCredential = pendingCredential.withRegistrationName(newRegistrationName) ?: run { messages.send(source, MessageKeys.Rename.CONTEXT_CONFLICT) return diff --git a/velocity/src/main/kotlin/icu/h2l/login/config/CoreConfig.kt b/velocity/src/main/kotlin/icu/h2l/login/config/CoreConfig.kt index 79338064..fa2cf565 100644 --- a/velocity/src/main/kotlin/icu/h2l/login/config/CoreConfig.kt +++ b/velocity/src/main/kotlin/icu/h2l/login/config/CoreConfig.kt @@ -50,10 +50,6 @@ data class CoreConfig( @Comment("config.core.vserver") val vServer: VServerConfig = VServerConfig(), @JvmField - // 认证 - @Comment("config.core.auth") - val auth: AuthConfig = AuthConfig(), - @JvmField // 消息 @Comment("config.core.messages") val messages: MessagesConfig = MessagesConfig() diff --git a/velocity/src/main/kotlin/icu/h2l/login/profile/CredentialChannelRegistryImpl.kt b/velocity/src/main/kotlin/icu/h2l/login/profile/CredentialChannelRegistryImpl.kt index d1e1e934..4d7e55a5 100644 --- a/velocity/src/main/kotlin/icu/h2l/login/profile/CredentialChannelRegistryImpl.kt +++ b/velocity/src/main/kotlin/icu/h2l/login/profile/CredentialChannelRegistryImpl.kt @@ -21,48 +21,28 @@ package icu.h2l.login.profile -import icu.h2l.api.profile.CredentialChannelAbility import icu.h2l.api.profile.CredentialChannelRegistry -import icu.h2l.login.config.AuthConfig import java.util.concurrent.ConcurrentHashMap /** * [CredentialChannelRegistry] 的 Velocity 侧实现。 * - * 使用 [ConcurrentHashMap] 存储渠道信息,保证并发安全。 + * 使用 [ConcurrentHashMap] 派生的并发集合存储渠道 ID,保证并发安全。 * 注册操作是幂等的,重复注册同一渠道 ID 不会产生副作用。 - * - * @param authConfig 核心 auth 配置,用于计算各渠道的能力(如是否允许注册)。 */ -class CredentialChannelRegistryImpl( - private val authConfig: AuthConfig, -) : CredentialChannelRegistry { +class CredentialChannelRegistryImpl : CredentialChannelRegistry { - private val abilities: MutableMap = ConcurrentHashMap() + private val channelIds: MutableSet = ConcurrentHashMap.newKeySet() - override fun registerChannel(channelId: String): CredentialChannelAbility { - val ability = buildAbility(channelId) - abilities[channelId] = ability - return ability + override fun registerChannel(channelId: String) { + channelIds.add(channelId) } override fun isRegistered(channelId: String): Boolean { - return channelId in abilities + return channelId in channelIds } override fun getRegisteredChannelIds(): Set { - return abilities.keys.toSet() - } - - override fun getChannelAbility(channelId: String): CredentialChannelAbility? { - return abilities[channelId] - } - - private fun buildAbility(channelId: String): CredentialChannelAbility { - val canRegister = channelId !in authConfig.disableRegistration - return CredentialChannelAbility( - channelId = channelId, - canRegister = canRegister, - ) + return channelIds.toSet() } } diff --git a/velocity/src/main/resources/config-comments/en_us.conf b/velocity/src/main/resources/config-comments/en_us.conf index 548093fc..f46cf75a 100644 --- a/velocity/src/main/resources/config-comments/en_us.conf +++ b/velocity/src/main/resources/config-comments/en_us.conf @@ -11,10 +11,6 @@ "config.core.vserver" = "Waiting Area Server" "config.core.messages" = "Messages" -# AuthConfig -"config.core.auth" = "Authentication behavior configuration" -"config.core.auth.disableRegistration" = "List of credential channel IDs for which new profile registration (creation) is disabled.\nAdd channel IDs (e.g. offline, yggdrasil, floodgate) to prevent those channels from creating new player profiles.\nExisting profile logins are unaffected." - # DatabaseSourceConfig "config.db.type" = "Database type\nSupported values: SQLITE, MYSQL, MARIADB" "config.db.sqlite" = "SQLite database configuration" diff --git a/velocity/src/main/resources/config-comments/zh_cn.conf b/velocity/src/main/resources/config-comments/zh_cn.conf index b623e29b..012bec0a 100644 --- a/velocity/src/main/resources/config-comments/zh_cn.conf +++ b/velocity/src/main/resources/config-comments/zh_cn.conf @@ -11,10 +11,6 @@ "config.core.vserver" = "等待区服务器" "config.core.messages" = "消息" -# AuthConfig -"config.core.auth" = "认证行为配置" -"config.core.auth.disableRegistration" = "禁止通过以下渠道进行新档案注册(建档)的凭证渠道 ID 列表。\n填入渠道 ID(如 offline、yggdrasil、floodgate)后,该渠道的凭证将无法用于创建新玩家档案。\n已有档案的登录不受影响。" - # DatabaseSourceConfig "config.db.type" = "数据库类型\n支持的值: SQLITE, MYSQL, MARIADB" "config.db.sqlite" = "SQLite 数据库配置"