Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/main/kotlin/icu/h2l/api/HyperZoneApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface HyperZoneApi :
/**
* 凭证渠道注册表。
*
* 子模块注册时,核心层会将 [HyperSubModule.credentialChannelIds] 中的渠道 ID 自动写入此注册表。
* 子模块应在 [HyperSubModule.register] 阶段通过此注册表声明自己使用的凭证渠道 ID。
* 外部插件也可以通过此入口主动注册自定义凭证渠道。
*/
val credentialChannelRegistry: CredentialChannelRegistry
Expand Down
11 changes: 0 additions & 11 deletions api/src/main/kotlin/icu/h2l/api/module/HyperSubModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
get() = emptySet()

/**
* 将当前子模块注册到指定的 [HyperZoneApi] 运行时中。
*/
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/kotlin/icu/h2l/api/player/HyperZonePlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ interface HyperZonePlayer {
* 该值在登录管理器提交凭证时由核心层自动记录;
* 在凭证提交前(或 [resetVerify] 后)返回 null。
*
* 示例值:`"floodgate"`、`"offline"`、`"yggdrasil"`。
* 示例值:`"floodgate"`、`"offline"`、`"yggdrasil:mojang"`。
*/
val authChannelId: String?
get() = null
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 是否已注册。
Expand All @@ -48,13 +47,6 @@ interface CredentialChannelRegistry {
* 返回当前已注册的所有凭证渠道 ID 的快照(不可变集合)。
*/
fun getRegisteredChannelIds(): Set<String>

/**
* 获取指定渠道的能力描述。
*
* @return 若该渠道已注册则返回对应 [CredentialChannelAbility],否则返回 `null`。
*/
fun getChannelAbility(channelId: String): CredentialChannelAbility?
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import java.util.*
*/
interface HyperZoneCredential : IPropertiesHolder {
/**
* 认证渠道唯一标识,由子模块负责稳定定义。
* 认证渠道唯一标识,可用于区分不同上游。
*/
val channelId: String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ import icu.h2l.login.auth.floodgate.service.FloodgateSessionHolder
import java.util.*

class FloodgateSubModule : HyperSubModule {
override val credentialChannelIds: Set<String> = 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
auth-floodgate {
init-player-failed = "<red>Floodgate login failed: failed to initialize the login-session player.</red>"
temporary-profile-failed = "<red>Floodgate login failed: failed to initialize the temporary profile.</red>"
registration-disabled = "<yellow>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].</yellow>"
create-blocked = "<yellow>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].</yellow>"
complete-failed = "<red>Floodgate login failed: an error occurred during authentication completion.</red>"
generic-disconnect = "<red>Floodgate login failed.</red>"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
auth-floodgate {
init-player-failed = "<red>Floodgate 登录失败:登录对象初始化失败。</red>"
temporary-profile-failed = "<red>Floodgate 登录失败:临时档案初始化失败。</red>"
registration-disabled = "<yellow>Floodgate 已完成可信认证,但当前渠道已被管理员禁止新玩家注册。若你已有档案,请使用 /bindcode use [绑定码]。</yellow>"
create-blocked = "<yellow>Floodgate 已完成可信认证,但当前注册名无法创建 Profile。名称冲突请使用 /rename [新注册名];UUID 冲突说明该渠道账号需要 link 到已有档案,请使用 /bindcode use [绑定码]。</yellow>"
complete-failed = "<red>Floodgate 登录失败:认证完成阶段出错。</red>"
generic-disconnect = "<red>Floodgate 登录失败。</red>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class OfflineSubModule : HyperSubModule {
lateinit var offlineAuthRepository: OfflineAuthRepository
lateinit var offlineAuthService: OfflineAuthService

override val credentialChannelIds: Set<String> = setOf("offline")

override fun register(api: HyperZoneApi) {
api.credentialChannelRegistry.registerChannel("offline")

val proxy = api.proxy
val dataDirectory = api.dataDirectory
val databaseManager: HyperZoneDatabaseManager = api.databaseManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<OfflineHyperZoneCredential>()
.firstOrNull()?.getRegistrationName() ?: player.username
val normalizedName = username.lowercase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ auth-offline {
}

register {
disabled = "<dark_gray>[<gold>HyperZoneLogin</gold>] <red>New player registration has been disabled by the administrator for this authentication channel.</red>"
success = "<dark_gray>[<gold>HyperZoneLogin</gold>] <green>Registration successful, and you have been logged in automatically.</green>"
failed = "<dark_gray>[<gold>HyperZoneLogin</gold>] <red>Registration failed. Please try again later.</red>"
password-already-set = "<dark_gray>[<gold>HyperZoneLogin</gold>] <yellow>You have already set an offline password. No need to do it again.</yellow>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ auth-offline {
}

register {
disabled = "<dark_gray>[<gold>HyperZoneLogin</gold>] <red>当前认证渠道已被管理员禁止新玩家注册</red>"
success = "<dark_gray>[<gold>HyperZoneLogin</gold>] <green>已成功注册,已为你自动登录</green>"
failed = "<dark_gray>[<gold>HyperZoneLogin</gold>] <red>注册失败,请稍后再试</red>"
password-already-set = "<dark_gray>[<gold>HyperZoneLogin</gold>] <yellow>你已设置过离线密码,无需重复操作</yellow>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 {
Expand Down Expand Up @@ -79,8 +80,6 @@ class YggdrasilHyperZoneCredential(
}

companion object {
private const val CHANNEL_ID = "yggdrasil"

public const val YGGDRASIL_ENTRY_ID_PROPERTY = "yggdrasil-entry-id"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ 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 {
lateinit var entryConfigManager: EntryConfigManager
lateinit var entryTableManager: EntryTableManager
lateinit var yggdrasilAuthModule: YggdrasilAuthModule

override val credentialChannelIds: Set<String> = setOf("yggdrasil")

override fun register(api: HyperZoneApi) {
val proxy = api.proxy
val dataDirectory = api.dataDirectory
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = emptyList(),
)
class ChannelIdUtil {
companion object {
private const val CHANNEL_ID_PREFIX = "yggdrasil"

fun getChannelId(entryId: String): String {
return "$CHANNEL_ID_PREFIX:$entryId"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
auth-yggd {
auth-in-progress = "<yellow>Yggdrasil authentication is in progress. Please wait…</yellow>"
auth-succeeded = "<green>Yggdrasil authentication passed. Preparing your profile and skin data…</green>"
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 = "<red><reason></red><yellow> 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].</yellow>"
verify-complete-failed = "<red><reason></red><yellow> 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].</yellow>"
auth-failed = "<red>Yggdrasil authentication failed: <reason></red>"
Expand Down
Loading
Loading