3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2025-01-11 15:41:14 +01:00

Add PostLoginEvent. Resolve #72

Dieser Commit ist enthalten in:
Leymooo 2018-09-11 16:15:54 +03:00
Ursprung f9a98ae41c
Commit 74bf246c39
2 geänderte Dateien mit 55 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,29 @@
package com.velocitypowered.api.event.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* This event is fired once the player has been successfully authenticated and
* fully initialized and player will be connected to server after this event
*/
public class PostLoginEvent {
private final Player player;
public PostLoginEvent(@NonNull Player player) {
this.player = Preconditions.checkNotNull(player, "player");
}
public Player getPlayer() {
return player;
}
@Override
public String toString() {
return "PostLoginEvent{"
+ "player=" + player
+ '}';
}
}

Datei anzeigen

@ -2,6 +2,7 @@ package com.velocitypowered.proxy.connection.client;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.event.connection.LoginEvent; import com.velocitypowered.api.event.connection.LoginEvent;
import com.velocitypowered.api.event.connection.PostLoginEvent;
import com.velocitypowered.api.event.connection.PreLoginEvent; import com.velocitypowered.api.event.connection.PreLoginEvent;
import com.velocitypowered.api.event.connection.PreLoginEvent.PreLoginComponentResult; import com.velocitypowered.api.event.connection.PreLoginEvent.PreLoginComponentResult;
import com.velocitypowered.api.event.permission.PermissionsSetupEvent; import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
@ -39,9 +40,10 @@ import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
public class LoginSessionHandler implements MinecraftSessionHandler { public class LoginSessionHandler implements MinecraftSessionHandler {
private static final Logger logger = LogManager.getLogger(LoginSessionHandler.class); private static final Logger logger = LogManager.getLogger(LoginSessionHandler.class);
private static final String MOJANG_SERVER_AUTH_URL = private static final String MOJANG_SERVER_AUTH_URL
"https://sessionserver.mojang.com/session/minecraft/hasJoined?username=%s&serverId=%s&ip=%s"; = "https://sessionserver.mojang.com/session/minecraft/hasJoined?username=%s&serverId=%s&ip=%s";
private final VelocityServer server; private final VelocityServer server;
private final MinecraftConnection inbound; private final MinecraftConnection inbound;
@ -193,26 +195,26 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
apiInbound.getVirtualHost().orElse(null)); apiInbound.getVirtualHost().orElse(null));
return server.getEventManager().fire(new PermissionsSetupEvent(player, ConnectedPlayer.DEFAULT_PERMISSIONS)) return server.getEventManager().fire(new PermissionsSetupEvent(player, ConnectedPlayer.DEFAULT_PERMISSIONS))
.thenCompose(event -> { .thenCompose(event -> {
// wait for permissions to load, then set the players permission function // wait for permissions to load, then set the players permission function
player.setPermissionFunction(event.createFunction(player)); player.setPermissionFunction(event.createFunction(player));
// then call & wait for the login event // then call & wait for the login event
return server.getEventManager().fire(new LoginEvent(player)); return server.getEventManager().fire(new LoginEvent(player));
}) })
// then complete the connection // then complete the connection
.thenAcceptAsync(event -> { .thenAcceptAsync(event -> {
if (inbound.isClosed()) { if (inbound.isClosed()) {
// The player was disconnected // The player was disconnected
return; return;
} }
if (!event.getResult().isAllowed()) { if (!event.getResult().isAllowed()) {
// The component is guaranteed to be provided if the connection was denied. // The component is guaranteed to be provided if the connection was denied.
inbound.closeWith(Disconnect.create(event.getResult().getReason().get())); inbound.closeWith(Disconnect.create(event.getResult().getReason().get()));
return; return;
} }
handleProxyLogin(player); handleProxyLogin(player);
}, inbound.getChannel().eventLoop()); }, inbound.getChannel().eventLoop());
}); });
} }
@ -244,7 +246,9 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
logger.info("{} has connected", player); logger.info("{} has connected", player);
inbound.setSessionHandler(new InitialConnectSessionHandler(player)); inbound.setSessionHandler(new InitialConnectSessionHandler(player));
player.createConnectionRequest(toTry.get()).fireAndForget(); server.getEventManager().fire(new PostLoginEvent(player)).thenRun(() -> {
player.createConnectionRequest(toTry.get()).fireAndForget();
});
} }
@Override @Override