Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.ChatEvent;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PlayerHandshakeEvent;
import net.md_5.bungee.api.event.PreLoginEvent;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.event.ServerSwitchEvent;
Expand Down Expand Up @@ -174,8 +174,10 @@ void registerChannels() {
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerHandshake(PlayerHandshakeEvent event) {
public void onPreLogin(PreLoginEvent event) {
if (!configuration.keepOfflineUuidCompatibility()) {
// PlayerHandshakeEvent runs before LOGIN_START, so the connection name is still null there.
// PreLoginEvent runs after LOGIN_START and before Bungee chooses the encryption path.
premiumOnlineModeHandler.enableOnlineModeIfRequired(event.getConnection());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.ChatEvent;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PlayerHandshakeEvent;
import net.md_5.bungee.api.event.PreLoginEvent;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.event.ServerSwitchEvent;
Expand Down Expand Up @@ -80,7 +80,7 @@ class BungeeProxyBridgeTest {
private ServerConnectEvent serverConnectEvent;

@Mock
private PlayerHandshakeEvent playerHandshakeEvent;
private PreLoginEvent preLoginEvent;

@Mock
private PendingConnection pendingConnection;
Expand Down Expand Up @@ -452,13 +452,30 @@ void shouldForceOnlineModeForPremiumHandshakeWhenOfflineCompatibilityDisabled()
given(pluginMessageEvent.getTag()).willReturn(BungeeProxyBridge.AUTHME_CHANNEL);
given(pluginMessageEvent.getSender()).willReturn(sourceServer);
given(pluginMessageEvent.getData()).willReturn(createAuthMePayload("premium.set", "Alice"));
given(playerHandshakeEvent.getConnection()).willReturn(pendingConnection);
given(preLoginEvent.getConnection()).willReturn(pendingConnection);
given(pendingConnection.getName()).willReturn("Alice");
given(pendingConnection.isOnlineMode()).willReturn(false);

BungeeProxyBridge bridge = new BungeeProxyBridge(proxyServer, logger, createConfiguration(), new BungeeAuthenticationStore(), null);
bridge.onPluginMessage(pluginMessageEvent);
bridge.onPlayerHandshake(playerHandshakeEvent);
bridge.onPreLogin(preLoginEvent);

verify(pendingConnection).setOnlineMode(true);
}

@Test
void shouldForceOnlineModeForPendingPremiumEnrollmentAtPreLogin() {
given(pluginMessageEvent.isCancelled()).willReturn(false);
given(pluginMessageEvent.getTag()).willReturn(BungeeProxyBridge.AUTHME_CHANNEL);
given(pluginMessageEvent.getSender()).willReturn(sourceServer);
given(pluginMessageEvent.getData()).willReturn(createAuthMePayload("premium.pending.set", "Alice"));
given(preLoginEvent.getConnection()).willReturn(pendingConnection);
given(pendingConnection.getName()).willReturn("Alice");
given(pendingConnection.isOnlineMode()).willReturn(false);

BungeeProxyBridge bridge = new BungeeProxyBridge(proxyServer, logger, createConfiguration(), new BungeeAuthenticationStore(), null);
bridge.onPluginMessage(pluginMessageEvent);
bridge.onPreLogin(preLoginEvent);

verify(pendingConnection).setOnlineMode(true);
}
Expand All @@ -469,13 +486,13 @@ void shouldForceOnlineModeForPremiumHandshakeAfterChunkedPremiumListResync() {
given(pluginMessageEvent.getTag()).willReturn(BungeeProxyBridge.AUTHME_CHANNEL);
given(pluginMessageEvent.getSender()).willReturn(sourceServer);
given(pluginMessageEvent.getData()).willReturn(createChunkPayload(0, true, "Alice"));
given(playerHandshakeEvent.getConnection()).willReturn(pendingConnection);
given(preLoginEvent.getConnection()).willReturn(pendingConnection);
given(pendingConnection.getName()).willReturn("Alice");
given(pendingConnection.isOnlineMode()).willReturn(false);

BungeeProxyBridge bridge = new BungeeProxyBridge(proxyServer, logger, createConfiguration(), new BungeeAuthenticationStore(), null);
bridge.onPluginMessage(pluginMessageEvent);
bridge.onPlayerHandshake(playerHandshakeEvent);
bridge.onPreLogin(preLoginEvent);

verify(pendingConnection).setOnlineMode(true);
}
Expand Down