Skip to content

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

@nickuc

Description

@nickuc

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:

DisconnectEvent.LoginStatus status;
if (connectedPlayer.isPresent()) {
if (connectedPlayer.get().getCurrentServer().isEmpty()) {
status = LoginStatus.PRE_SERVER_JOIN;
} else {
status = connectedPlayer.get() == this ? LoginStatus.SUCCESSFUL_LOGIN
: LoginStatus.CONFLICTING_LOGIN;
}
} else {
status = connection.isKnownDisconnect() ? LoginStatus.CANCELLED_BY_PROXY :
LoginStatus.CANCELLED_BY_USER;
}
DisconnectEvent event = new DisconnectEvent(this, status);

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

// Make sure we clear the current connected server as the connection is invalid.
VelocityServerConnection previousConnection = connectedServer;
if (kickedFromCurrent) {
connectedServer = null;
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions