Skip to content

fix: unattached player should access waiting area only. - #54

Open
qyl27 wants to merge 2 commits into
HyperZoneLogin:masterfrom
qyl27:fix/unattached-player-restriction
Open

qyl27 wants to merge 2 commits into
HyperZoneLogin:masterfrom
qyl27:fix/unattached-player-restriction

Conversation

@qyl27

@qyl27 qyl27 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

This is a behaviour change, enforce the unauthorized players' restriction. They may join the waiting area only.

Summary by Sourcery

Enforce waiting-area-only access for players who have not yet attached to a HyperZone user.

New Features:

  • Restrict unattached players to the configured waiting-area server and redirect or deny other connection attempts.
  • Expose the waiting-area server through the virtual-server adapter API.

Bug Fixes:

  • Prevent unauthorized, untracked, or misconfigured connections from reaching non-waiting-area servers.
  • Treat invalid authentication-server configuration as an authorization failure instead of silently continuing.

Enhancements:

  • Clarify attachment state and post-verification lifecycle guarantees in the public API.
  • Centralize test setup and cleanup for static application configuration.

Tests:

  • Add coverage for unattached-player connection gating, waiting-area fallback, denial paths, adapter failures, and backend server resolution.

@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Define the unattached-player restriction and expose the waiting-area server through the vServer adapter/provider contract.

  • api/src/main/kotlin/icu/h2l/api/player/HyperZonePlayer.kt L162-164
  • api/src/main/kotlin/icu/h2l/api/vServer/HyperZoneVServer.kt L76-83, L153-157 (+2 small edits)

Uses of the API

Enforce the restriction on pre-connect attempts, allowing unattached players only into the waiting area and denying or redirecting other connections.

  • velocity/src/main/kotlin/icu/h2l/login/listener/UnAttachedPlayerListener.kt L1-98

Implementation

Provide the configured backend auth server as the waiting-area server, and wire the connection gate into plugin startup while treating invalid auth-server configuration as an error.

  • velocity/src/main/kotlin/icu/h2l/login/HyperZoneLoginMain.kt L224-228 (+3 small edits)
  • velocity/src/main/kotlin/icu/h2l/login/vServer/backend/BackendAuthHoldListener.kt L44 (removed lines), L141-154

Tests

Add coverage for connection authorization and waiting-area lookup, and update existing tests to initialize and reset shared static state consistently.

  • velocity/src/test/kotlin/icu/h2l/login/database/InGameProfileDatabaseTest.kt L45-54 (+3 small edits)
  • velocity/src/test/kotlin/icu/h2l/login/listener/AttachedUserInitialGameProfileListenerTest.kt L37, L130
  • velocity/src/test/kotlin/icu/h2l/login/listener/UnAttachedPlayerListenerTest.kt L1-311
  • velocity/src/test/kotlin/icu/h2l/login/manager/LoginManagerTest.kt L43-52, L58-75 (+9 small edits)
  • velocity/src/test/kotlin/icu/h2l/login/profile/UserBindingCodeServiceTest.kt L34-55, L63-70, L81-85 (+1 small edits)
  • velocity/src/test/kotlin/icu/h2l/login/vServer/backend/BackendAuthHoldListenerTest.kt L1-83
  • velocity/src/test/kotlin/icu/h2l/login/vServer/outpre/OutPreVServerAuthTest.kt L135-143 (+6 small edits)
  • velocity/src/test/kotlin/util/MockStaticUtil.kt L1-43

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="velocity/src/main/kotlin/icu/h2l/login/HyperZoneLoginMain.kt" line_range="139" />
<code_context>
-        // 访问配置不再抛 UninitializedPropertyAccessException,而是返回安全默认配置。
-        private var coreConfig: CoreConfig = CoreConfig()
-        private var startConfig: StartConfig = StartConfig()
+        private lateinit var coreConfig: CoreConfig

         @JvmStatic
</code_context>
<issue_to_address>
**Configuration callers crash before loading**

When a plugin or API caller accesses core configuration before `loadCoreConfig()` completes or after startup exits early, `getCoreConfig()` reads the uninitialized `lateinit` property and throws `UninitializedPropertyAccessException`, so callers no longer receive the safe default configuration.

Keep `coreConfig` initialized with a safe default or otherwise ensure the getter returns a safe configuration before loading completes.
</issue_to_address>

### Comment 2
<location path="api/src/main/kotlin/icu/h2l/api/vServer/HyperZoneVServer.kt" line_range="82" />
<code_context>
+     * 如果等待区不经过 Velocity 后端连接,或者没有配置可用的等待区时,返回 `null`。
+     * 一个 Velocity 服务器最多只能配置一个等待区。
+     */
+    fun getRegisteredVServer(): RegisteredServer? = null
+
     /**
</code_context>
<issue_to_address>
**Players are disconnected instead of routed**

When a third-party adapter uses the existing waiting-area methods but does not override the new getter, the default `getRegisteredVServer()` returns `null`, so the connection gate treats the adapter's waiting area as unavailable and disconnects the player instead of routing them into that waiting area.

Preserve existing waiting-area behavior for adapters that do not override the new getter instead of treating its default `null` as proof that no waiting area is available.

Also at `velocity/src/main/kotlin/icu/h2l/login/listener/UnAttachedPlayerListener.kt:56-78`.
</issue_to_address>

### Comment 3
<location path="velocity/src/test/kotlin/icu/h2l/login/listener/UnAttachedPlayerListenerTest.kt" line_range="256-257" />
<code_context>
+        event: ServerPreConnectEvent,
+        otherListeners: (ServerPreConnectEvent) -> Unit = {},
+    ) {
+        otherListeners(event)
+        gate.onServerPreConnect(event)
+    }
+
</code_context>
<issue_to_address>
**Later listener can re-allow access**

When the gate’s event priority is removed or changed so another listener runs after it, when the event bus runs another listener after the gate, that listener can re-allow the connection, but `dispatch` always runs `otherListeners` before `gate.onServerPreConnect`; the named test’s `assertFalse` therefore passes even if the gate’s priority is broken.

Dispatch the event through Velocity’s event manager in this test and verify that a listener registered at a later priority cannot re-allow the connection.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and if this gate is wrong or can be bypassed, a player without an attached user could connect to a game backend and access resources before authorization; that access may have consequences a revert cannot undo. Reverting restores the previous connection behavior but cannot retract anything accessed while the gate was ineffective.

Blocking findings: velocity/src/main/kotlin/icu/h2l/login/HyperZoneLoginMain.kt:139, api/src/main/kotlin/icu/h2l/api/vServer/HyperZoneVServer.kt:82, velocity/src/test/kotlin/icu/h2l/login/listener/UnAttachedPlayerListenerTest.kt:257


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant