Skip to content

Commit 63dccbf

Browse files
committed
fix(proxy): Throw auto-login through whatever next server join
1 parent d971461 commit 63dccbf

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

authme-velocity/src/main/java/fr/xephi/authme/velocity/VelocityProxyBridge.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,6 @@ void onServerConnected(ServerConnectedEvent event) {
291291
}
292292

293293
boolean connectingToAuthServer = configuration.isAuthServer(event.getServer());
294-
boolean leavingAuthServer = event.getPreviousServer()
295-
.map(configuration::isAuthServer).orElse(false);
296-
logger.debug("autoLogin check for {}: connectingToAuth={}, leavingAuth={}", playerName,
297-
connectingToAuthServer, leavingAuthServer);
298-
299-
if (!connectingToAuthServer && !leavingAuthServer) {
300-
logger.debug("Skipping auto-login for {} — server transition not involving an auth server", playerName);
301-
return;
302-
}
303294

304295
String normalizedName = normalizeName(playerName);
305296

authme-velocity/src/test/java/fr/xephi/authme/velocity/VelocityProxyBridgeTest.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,19 @@ void shouldDisconnectPlayerOnInitialJoinToNonAuthServerWhenSwitchRequiresAuth()
326326
}
327327

328328
@Test
329-
void shouldNotForwardPerformLoginToNonAuthServers() {
329+
void shouldNotForwardPerformLoginForUnauthenticatedPlayer() {
330+
given(player.getUsername()).willReturn("Alice");
331+
given(nonAuthServer.getServerInfo()).willReturn(nonAuthServerInfo);
332+
given(nonAuthServerInfo.getName()).willReturn("survival");
333+
334+
VelocityProxyBridge bridge = new VelocityProxyBridge(proxyServer, logger, createConfiguration(), new VelocityAuthenticationStore());
335+
bridge.onServerConnected(new ServerConnectedEvent(player, nonAuthServer, null));
336+
337+
verify(currentServer, never()).sendPluginMessage(any(), any(byte[].class));
338+
}
339+
340+
@Test
341+
void shouldForwardPerformLoginWhenSwitchingFromAuthServerToNonAuthServer() {
330342
given(pluginMessageEvent.getResult()).willReturn(PluginMessageEvent.ForwardResult.forward());
331343
given(pluginMessageEvent.getIdentifier()).willReturn(VelocityProxyBridge.AUTHME_CHANNEL);
332344
given(pluginMessageEvent.getSource()).willReturn(sourceConnection);
@@ -336,12 +348,18 @@ void shouldNotForwardPerformLoginToNonAuthServers() {
336348
given(authServerInfo.getName()).willReturn("lobby");
337349
given(nonAuthServer.getServerInfo()).willReturn(nonAuthServerInfo);
338350
given(nonAuthServerInfo.getName()).willReturn("survival");
351+
given(player.getUsername()).willReturn("Alice");
352+
given(player.getCurrentServer()).willReturn(Optional.of(currentServer));
353+
given(currentServer.getServer()).willReturn(nonAuthServer);
354+
given(currentServer.sendPluginMessage(eq(VelocityProxyBridge.AUTHME_CHANNEL), any(byte[].class)))
355+
.willReturn(true);
339356

340357
VelocityProxyBridge bridge = new VelocityProxyBridge(proxyServer, logger, createConfiguration(), new VelocityAuthenticationStore());
341358
bridge.onPluginMessage(pluginMessageEvent);
342-
bridge.onServerConnected(new ServerConnectedEvent(player, nonAuthServer, null));
359+
bridge.onServerConnected(new ServerConnectedEvent(player, nonAuthServer, authServer));
343360

344-
verify(currentServer, never()).sendPluginMessage(any(), any(byte[].class));
361+
verify(currentServer).sendPluginMessage(eq(VelocityProxyBridge.AUTHME_CHANNEL), payloadCaptor.capture());
362+
assertPerformLoginPayload(payloadCaptor.getValue(), "alice", "test-secret");
345363
}
346364

347365
// --- Command blocking tests ---

0 commit comments

Comments
 (0)