PaperMC / PaperMC/Velocity

Unexpected DisconnectEvent#getLoginStatus() result when disconnected by the backend

Open
#1,696 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
Java
Stars
2.3k
Forks
959
Avg merge
5d 10h
Merged PRs (30d)
2

Description

Expected Behavior

The result of DisconnectEvent#getLoginStatus() should be: SUCCESSFUL_LOGIN

Actual Behavior

When disconnecting using the Minecraft client, the result of DisconnectEvent#getLoginStatus() is:
SUCCESSFUL_LOGIN

When disconnecting using the backend console /kick <player>, the result of DisconnectEvent#getLoginStatus() is:
PRE_SERVER_JOIN

Steps to Reproduce
  1. Listen to the DisconnectEvent event
@Subscribe
public void onDisconnected(DisconnectEvent event) {
    this.logger.info("Current Server: " + event.getPlayer().getCurrentServer());
    this.logger.info("Login Status: " + event.getLoginStatus());
}
  1. Log in to the server and disconnect using the Minecraft client (in-game).
  2. Log in to the server and disconnect the client via the backend with Paper. kick <player>
  3. Compare the console outputs from steps 2 and 3:
Disconnection by the Minecraft Client (step 2)
[11:55:14 INFO]: [server connection] NickUC -> lobby has disconnected
[11:55:14 INFO] [com.nickuc.test.velocity.VelocityPlugin]: Current Server: Optional[[server connection] NickUC -> lobby]
[11:55:14 INFO] [com.nickuc.test.velocity.VelocityPlugin]: Login Status: SUCCESSFUL_LOGIN
Disconnection by the Backend (step 3)
[11:55:32 INFO]: [server connection] NickUC -> lobby has disconnected
[11:55:32 INFO]: [connected player] NickUC (/[XXXX:XXXX:XXXX:XXXX]:60006) has disconnected: Você foi expulso de lobby: 
[11:55:32 INFO] [com.nickuc.test.velocity.VelocityPlugin]: Current Server: Optional.empty
[11:55:32 INFO] [com.nickuc.test.velocity.VelocityPlugin]: Login Status: PRE_SERVER_JOIN
Plugin List

Plugins: velocity, test_plugin

Velocity Version

Velocity 3.4.0-SNAPSHOT (git-8f65a814-b558)

Additional Information

From what I've discovered, this behavior occurs because Player#getCurrentServer() is empty when calling DisconnectEvent in:

https://github.com/PaperMC/Velocity/blob/8f65a8142029717d3af09ecf82792f7345dc873a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java#L969-L982

The Player#getCurrentServer() is set to null in:

https://github.com/PaperMC/Velocity/blob/8f65a8142029717d3af09ecf82792f7345dc873a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java#L803-L807

I confirmed that the cause of the problem is in the code above. I commented out the line connectedServer = null and the problem was solved.

I don't know anything about Velocity's internal API, so I have no idea how to solve it.

I am using the default Velocity configuration.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java, around lines 803-807 and 969-982, and trace the disconnect ordering for client versus backend kicks. Reproduce both cases with DisconnectEvent and compare getCurrentServer() and getLoginStatus(); done means backend kicks report the expected successful-login status without breaking disconnect handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.