3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00
Dieser Commit ist enthalten in:
Andrew Steinborn 2018-09-29 23:57:40 -04:00
Ursprung eddf01fc32
Commit 2d2258d667
10 geänderte Dateien mit 30 neuen und 51 gelöschten Zeilen

Datei anzeigen

@ -19,7 +19,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
private final VelocityServerConnection serverConn; private final VelocityServerConnection serverConn;
private final ClientPlaySessionHandler playerSessionHandler; private final ClientPlaySessionHandler playerSessionHandler;
public BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection serverConn) { BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection serverConn) {
this.server = server; this.server = server;
this.serverConn = serverConn; this.serverConn = serverConn;
this.playerSessionHandler = (ClientPlaySessionHandler) serverConn.getPlayer().getConnection().getSessionHandler(); this.playerSessionHandler = (ClientPlaySessionHandler) serverConn.getPlayer().getConnection().getSessionHandler();

Datei anzeigen

@ -30,8 +30,8 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
private final CompletableFuture<ConnectionRequestBuilder.Result> resultFuture; private final CompletableFuture<ConnectionRequestBuilder.Result> resultFuture;
private boolean informationForwarded; private boolean informationForwarded;
public LoginSessionHandler(VelocityServer server, VelocityServerConnection serverConn, LoginSessionHandler(VelocityServer server, VelocityServerConnection serverConn,
CompletableFuture<ConnectionRequestBuilder.Result> resultFuture) { CompletableFuture<ConnectionRequestBuilder.Result> resultFuture) {
this.server = server; this.server = server;
this.serverConn = serverConn; this.serverConn = serverConn;
this.resultFuture = resultFuture; this.resultFuture = resultFuture;

Datei anzeigen

@ -69,18 +69,15 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
} }
}) })
.connect(registeredServer.getServerInfo().getAddress()) .connect(registeredServer.getServerInfo().getAddress())
.addListener(new ChannelFutureListener() { .addListener((ChannelFutureListener) future -> {
@Override if (future.isSuccess()) {
public void operationComplete(ChannelFuture future) throws Exception { connection = future.channel().pipeline().get(MinecraftConnection.class);
if (future.isSuccess()) {
connection = future.channel().pipeline().get(MinecraftConnection.class);
// Kick off the connection process // Kick off the connection process
connection.setSessionHandler(new LoginSessionHandler(server, VelocityServerConnection.this, result)); connection.setSessionHandler(new LoginSessionHandler(server, VelocityServerConnection.this, result));
startHandshake(); startHandshake();
} else { } else {
result.completeExceptionally(future.cause()); result.completeExceptionally(future.cause());
}
} }
}); });
return result; return result;
@ -122,12 +119,6 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
connection.write(login); connection.write(login);
} }
public void writeIfJoined(PluginMessage message) {
if (hasCompletedJoin) {
connection.write(message);
}
}
public MinecraftConnection getConnection() { public MinecraftConnection getConnection() {
return connection; return connection;
} }

Datei anzeigen

@ -64,7 +64,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
private PlayerSettings settings; private PlayerSettings settings;
private final VelocityServer server; private final VelocityServer server;
public ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection, InetSocketAddress virtualHost) { ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection, InetSocketAddress virtualHost) {
this.server = server; this.server = server;
this.profile = profile; this.profile = profile;
this.connection = connection; this.connection = connection;
@ -99,7 +99,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
return this.ping; return this.ping;
} }
public void setPing(long ping) { void setPing(long ping) {
this.ping = ping; this.ping = ping;
} }
@ -386,7 +386,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
connection.closeWith(Disconnect.create(reason)); connection.closeWith(Disconnect.create(reason));
} }
public void teardown() { void teardown() {
if (connectionInFlight != null) { if (connectionInFlight != null) {
connectionInFlight.disconnect(); connectionInFlight.disconnect();
} }

Datei anzeigen

@ -16,7 +16,6 @@ import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.*; import com.velocitypowered.proxy.protocol.packet.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import net.kyori.text.TextComponent; import net.kyori.text.TextComponent;
import net.kyori.text.TranslatableComponent; import net.kyori.text.TranslatableComponent;
import net.kyori.text.format.TextColor; import net.kyori.text.format.TextColor;

Datei anzeigen

@ -6,7 +6,7 @@ import com.velocitypowered.proxy.protocol.MinecraftPacket;
public class InitialConnectSessionHandler implements MinecraftSessionHandler { public class InitialConnectSessionHandler implements MinecraftSessionHandler {
private final ConnectedPlayer player; private final ConnectedPlayer player;
public InitialConnectSessionHandler(ConnectedPlayer player) { InitialConnectSessionHandler(ConnectedPlayer player) {
this.player = player; this.player = player;
} }

Datei anzeigen

@ -94,13 +94,12 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
public boolean handle(EncryptionResponse packet) { public boolean handle(EncryptionResponse packet) {
try { try {
KeyPair serverKeyPair = server.getServerKeyPair(); KeyPair serverKeyPair = server.getServerKeyPair();
EncryptionResponse response = (EncryptionResponse) packet; byte[] decryptedVerifyToken = EncryptionUtils.decryptRsa(serverKeyPair, packet.getVerifyToken());
byte[] decryptedVerifyToken = EncryptionUtils.decryptRsa(serverKeyPair, response.getVerifyToken());
if (!Arrays.equals(verify, decryptedVerifyToken)) { if (!Arrays.equals(verify, decryptedVerifyToken)) {
throw new IllegalStateException("Unable to successfully decrypt the verification token."); throw new IllegalStateException("Unable to successfully decrypt the verification token.");
} }
byte[] decryptedSharedSecret = EncryptionUtils.decryptRsa(serverKeyPair, response.getSharedSecret()); byte[] decryptedSharedSecret = EncryptionUtils.decryptRsa(serverKeyPair, packet.getSharedSecret());
String serverId = EncryptionUtils.generateServerId(decryptedSharedSecret, serverKeyPair.getPublic()); String serverId = EncryptionUtils.generateServerId(decryptedSharedSecret, serverKeyPair.getPublic());
String playerIp = ((InetSocketAddress) inbound.getChannel().remoteAddress()).getHostString(); String playerIp = ((InetSocketAddress) inbound.getChannel().remoteAddress()).getHostString();

Datei anzeigen

@ -19,7 +19,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
private final MinecraftConnection connection; private final MinecraftConnection connection;
private final InboundConnection inboundWrapper; private final InboundConnection inboundWrapper;
public StatusSessionHandler(VelocityServer server, MinecraftConnection connection, InboundConnection inboundWrapper) { StatusSessionHandler(VelocityServer server, MinecraftConnection connection, InboundConnection inboundWrapper) {
this.server = server; this.server = server;
this.connection = connection; this.connection = connection;
this.inboundWrapper = inboundWrapper; this.inboundWrapper = inboundWrapper;

Datei anzeigen

@ -31,20 +31,10 @@ public class ConnectionRequestResults {
public static ConnectionRequestBuilder.Result forDisconnect(Disconnect disconnect) { public static ConnectionRequestBuilder.Result forDisconnect(Disconnect disconnect) {
Component deserialized = ComponentSerializers.JSON.deserialize(disconnect.getReason()); Component deserialized = ComponentSerializers.JSON.deserialize(disconnect.getReason());
return new ConnectionRequestBuilder.Result() { return forDisconnect(deserialized);
@Override
public ConnectionRequestBuilder.Status getStatus() {
return ConnectionRequestBuilder.Status.SERVER_DISCONNECTED;
}
@Override
public Optional<Component> getReason() {
return Optional.of(deserialized);
}
};
} }
public static ConnectionRequestBuilder.Result forDisconnect(TextComponent component) { public static ConnectionRequestBuilder.Result forDisconnect(Component component) {
return new ConnectionRequestBuilder.Result() { return new ConnectionRequestBuilder.Result() {
@Override @Override
public ConnectionRequestBuilder.Status getStatus() { public ConnectionRequestBuilder.Status getStatus() {

Datei anzeigen

@ -13,12 +13,12 @@ import java.util.Collection;
import java.util.List; import java.util.List;
public class PluginMessageUtil { public class PluginMessageUtil {
public static final String BRAND_CHANNEL = "MC|Brand"; public static final String BRAND_CHANNEL_LEGACY = "MC|Brand";
public static final String BRAND_CHANNEL_1_13 = "minecraft:brand"; public static final String BRAND_CHANNEL = "minecraft:brand";
public static final String REGISTER_CHANNEL = "REGISTER"; public static final String REGISTER_CHANNEL_LEGACY = "REGISTER";
public static final String REGISTER_CHANNEL_1_13 = "minecraft:register"; public static final String REGISTER_CHANNEL = "minecraft:register";
public static final String UNREGISTER_CHANNEL = "UNREGISTER"; public static final String UNREGISTER_CHANNEL_LEGACY = "UNREGISTER";
public static final String UNREGISTER_CHANNEL_1_13 = "minecraft:unregister"; public static final String UNREGISTER_CHANNEL = "minecraft:unregister";
private PluginMessageUtil() { private PluginMessageUtil() {
throw new AssertionError(); throw new AssertionError();
@ -26,17 +26,17 @@ public class PluginMessageUtil {
public static boolean isMCBrand(PluginMessage message) { public static boolean isMCBrand(PluginMessage message) {
Preconditions.checkNotNull(message, "message"); Preconditions.checkNotNull(message, "message");
return message.getChannel().equals(BRAND_CHANNEL) || message.getChannel().equals(BRAND_CHANNEL_1_13); return message.getChannel().equals(BRAND_CHANNEL_LEGACY) || message.getChannel().equals(BRAND_CHANNEL);
} }
public static boolean isMCRegister(PluginMessage message) { public static boolean isMCRegister(PluginMessage message) {
Preconditions.checkNotNull(message, "message"); Preconditions.checkNotNull(message, "message");
return message.getChannel().equals(REGISTER_CHANNEL) || message.getChannel().equals(REGISTER_CHANNEL_1_13); return message.getChannel().equals(REGISTER_CHANNEL_LEGACY) || message.getChannel().equals(REGISTER_CHANNEL);
} }
public static boolean isMCUnregister(PluginMessage message) { public static boolean isMCUnregister(PluginMessage message) {
Preconditions.checkNotNull(message, "message"); Preconditions.checkNotNull(message, "message");
return message.getChannel().equals(UNREGISTER_CHANNEL) || message.getChannel().equals(UNREGISTER_CHANNEL_1_13); return message.getChannel().equals(UNREGISTER_CHANNEL_LEGACY) || message.getChannel().equals(UNREGISTER_CHANNEL);
} }
public static List<String> getChannels(PluginMessage message) { public static List<String> getChannels(PluginMessage message) {
@ -49,7 +49,7 @@ public class PluginMessageUtil {
public static PluginMessage constructChannelsPacket(int protocolVersion, Collection<String> channels) { public static PluginMessage constructChannelsPacket(int protocolVersion, Collection<String> channels) {
Preconditions.checkNotNull(channels, "channels"); Preconditions.checkNotNull(channels, "channels");
String channelName = protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ? REGISTER_CHANNEL_1_13 : REGISTER_CHANNEL; String channelName = protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ? REGISTER_CHANNEL : REGISTER_CHANNEL_LEGACY;
PluginMessage message = new PluginMessage(); PluginMessage message = new PluginMessage();
message.setChannel(channelName); message.setChannel(channelName);
message.setData(String.join("\0", channels).getBytes(StandardCharsets.UTF_8)); message.setData(String.join("\0", channels).getBytes(StandardCharsets.UTF_8));