Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
register player connection only when switched to PLAY state (#169)
Dieser Commit ist enthalten in:
Ursprung
7d4d81fff1
Commit
c5fefd55ed
@ -388,6 +388,17 @@ public class VelocityServer implements ProxyServer {
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the {@code connection} can be registered with the proxy.
|
||||||
|
* @param connection the connection to check
|
||||||
|
* @return {@code true} if we can register the connection, {@code false} if not
|
||||||
|
*/
|
||||||
|
public boolean canRegisterConnection(ConnectedPlayer connection) {
|
||||||
|
String lowerName = connection.getUsername().toLowerCase(Locale.US);
|
||||||
|
return !(connectionsByName.containsKey(lowerName)
|
||||||
|
|| connectionsByUuid.containsKey(connection.getUniqueId()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to register the {@code connection} with the proxy.
|
* Attempts to register the {@code connection} with the proxy.
|
||||||
* @param connection the connection to register
|
* @param connection the connection to register
|
||||||
|
@ -15,7 +15,6 @@ 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;
|
||||||
import com.velocitypowered.api.event.player.GameProfileRequestEvent;
|
import com.velocitypowered.api.event.player.GameProfileRequestEvent;
|
||||||
import com.velocitypowered.api.proxy.InboundConnection;
|
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import com.velocitypowered.api.util.GameProfile;
|
import com.velocitypowered.api.util.GameProfile;
|
||||||
import com.velocitypowered.proxy.VelocityServer;
|
import com.velocitypowered.proxy.VelocityServer;
|
||||||
@ -33,7 +32,6 @@ import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess;
|
|||||||
import com.velocitypowered.proxy.protocol.packet.SetCompression;
|
import com.velocitypowered.proxy.protocol.packet.SetCompression;
|
||||||
import com.velocitypowered.proxy.util.VelocityMessages;
|
import com.velocitypowered.proxy.util.VelocityMessages;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@ -223,8 +221,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
mcConnection,
|
mcConnection,
|
||||||
inbound.getVirtualHost().orElse(null));
|
inbound.getVirtualHost().orElse(null));
|
||||||
this.connectedPlayer = player;
|
this.connectedPlayer = player;
|
||||||
|
if (!server.canRegisterConnection(player)) {
|
||||||
if (!server.registerConnection(player)) {
|
|
||||||
player.disconnect(VelocityMessages.ALREADY_CONNECTED);
|
player.disconnect(VelocityMessages.ALREADY_CONNECTED);
|
||||||
return CompletableFuture.completedFuture(null);
|
return CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
@ -233,28 +230,14 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
return server.getEventManager()
|
return server.getEventManager()
|
||||||
.fire(new PermissionsSetupEvent(player, ConnectedPlayer.DEFAULT_PERMISSIONS))
|
.fire(new PermissionsSetupEvent(player, ConnectedPlayer.DEFAULT_PERMISSIONS))
|
||||||
.thenCompose(event -> {
|
.thenAcceptAsync(event -> {
|
||||||
|
if (!mcConnection.isClosed()) {
|
||||||
// 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
|
|
||||||
return server.getEventManager().fire(new LoginEvent(player));
|
|
||||||
})
|
|
||||||
// then complete the connection
|
|
||||||
.thenAcceptAsync(event -> {
|
|
||||||
if (mcConnection.isClosed()) {
|
|
||||||
// The player was disconnected
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Optional<Component> reason = event.getResult().getReason();
|
|
||||||
if (reason.isPresent()) {
|
|
||||||
player.disconnect(reason.get());
|
|
||||||
} else {
|
|
||||||
finishLogin(player);
|
finishLogin(player);
|
||||||
}
|
}
|
||||||
}, mcConnection.eventLoop());
|
}, mcConnection.eventLoop());
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finishLogin(ConnectedPlayer player) {
|
private void finishLogin(ConnectedPlayer player) {
|
||||||
@ -278,10 +261,28 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
mcConnection.setAssociation(player);
|
mcConnection.setAssociation(player);
|
||||||
mcConnection.setState(StateRegistry.PLAY);
|
mcConnection.setState(StateRegistry.PLAY);
|
||||||
|
|
||||||
|
server.getEventManager().fire(new LoginEvent(player))
|
||||||
|
.thenAcceptAsync(event -> {
|
||||||
|
if (mcConnection.isClosed()) {
|
||||||
|
// The player was disconnected
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<Component> reason = event.getResult().getReason();
|
||||||
|
if (reason.isPresent()) {
|
||||||
|
player.disconnect(reason.get());
|
||||||
|
} else {
|
||||||
|
if (!server.registerConnection(player)) {
|
||||||
|
player.disconnect(VelocityMessages.ALREADY_CONNECTED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mcConnection.setSessionHandler(new InitialConnectSessionHandler(player));
|
mcConnection.setSessionHandler(new InitialConnectSessionHandler(player));
|
||||||
server.getEventManager().fire(new PostLoginEvent(player))
|
server.getEventManager().fire(new PostLoginEvent(player))
|
||||||
.thenRun(() -> player.createConnectionRequest(toTry.get()).fireAndForget());
|
.thenRun(() -> player.createConnectionRequest(toTry.get()).fireAndForget());
|
||||||
}
|
}
|
||||||
|
}, mcConnection.eventLoop());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleUnknown(ByteBuf buf) {
|
public void handleUnknown(ByteBuf buf) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren