13
0
geforkt von Mirrors/Velocity

Finalize integrated BungeeQuack

Dieser Commit ist enthalten in:
Andrew Steinborn 2019-11-26 16:27:30 -05:00
Ursprung b08f27b5c4
Commit 87ad188f92
2 geänderte Dateien mit 65 neuen und 54 gelöschten Zeilen

Datei anzeigen

@ -1,5 +1,8 @@
package com.velocitypowered.proxy.connection.backend; package com.velocitypowered.proxy.connection.backend;
import static com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder.getBungeeCordChannel;
import com.google.common.collect.ImmutableList;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder;
@ -53,6 +56,10 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
@Override @Override
public void activated() { public void activated() {
serverConn.getServer().addPlayer(serverConn.getPlayer()); serverConn.getServer().addPlayer(serverConn.getPlayer());
MinecraftConnection serverMc = serverConn.ensureConnected();
serverMc.write(PluginMessageUtil.constructChannelsPacket(serverMc.getProtocolVersion(),
ImmutableList.of(getBungeeCordChannel(serverMc.getProtocolVersion()))
));
} }
@Override @Override

Datei anzeigen

@ -2,7 +2,6 @@ package com.velocitypowered.proxy.connection.backend;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
@ -15,10 +14,8 @@ import com.velocitypowered.proxy.protocol.util.ByteBufDataInput;
import com.velocitypowered.proxy.protocol.util.ByteBufDataOutput; import com.velocitypowered.proxy.protocol.util.ByteBufDataOutput;
import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.server.VelocityRegisteredServer;
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.util.StringJoiner; import java.util.StringJoiner;
import java.util.stream.Collectors;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
class BungeeCordMessageResponder { class BungeeCordMessageResponder {
@ -46,10 +43,8 @@ class BungeeCordMessageResponder {
String playerName = in.readUTF(); String playerName = in.readUTF();
String serverName = in.readUTF(); String serverName = in.readUTF();
proxy.getPlayer(playerName).ifPresent(player -> { proxy.getPlayer(playerName).flatMap(player -> proxy.getServer(serverName))
proxy.getServer(serverName).ifPresent(server -> player.createConnectionRequest(server) .ifPresent(server -> player.createConnectionRequest(server).fireAndForget());
.fireAndForget());
});
} }
private void processIp(ByteBufDataInput in) { private void processIp(ByteBufDataInput in) {
@ -120,7 +115,7 @@ class BungeeCordMessageResponder {
} }
} }
private void processGetServers(ByteBufDataInput in) { private void processGetServers() {
StringJoiner joiner = new StringJoiner(", "); StringJoiner joiner = new StringJoiner(", ");
for (RegisteredServer server : proxy.getAllServers()) { for (RegisteredServer server : proxy.getAllServers()) {
joiner.add(server.getServerInfo().getName()); joiner.add(server.getServerInfo().getName());
@ -148,7 +143,7 @@ class BungeeCordMessageResponder {
} }
} }
private void processGetServer(ByteBufDataInput in) { private void processGetServer() {
ByteBuf buf = Unpooled.buffer(); ByteBuf buf = Unpooled.buffer();
ByteBufDataOutput out = new ByteBufDataOutput(buf); ByteBufDataOutput out = new ByteBufDataOutput(buf);
@ -158,7 +153,7 @@ class BungeeCordMessageResponder {
sendResponse(buf); sendResponse(buf);
} }
private void processUuid(ByteBufDataInput in) { private void processUuid() {
ByteBuf buf = Unpooled.buffer(); ByteBuf buf = Unpooled.buffer();
ByteBufDataOutput out = new ByteBufDataOutput(buf); ByteBufDataOutput out = new ByteBufDataOutput(buf);
@ -243,11 +238,15 @@ class BungeeCordMessageResponder {
sendResponse(this.player, buf); sendResponse(this.player, buf);
} }
static String getBungeeCordChannel(ProtocolVersion version) {
return version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0 ? MODERN_CHANNEL.getId()
: LEGACY_CHANNEL.getId();
}
// Note: this method will always release the buffer! // Note: this method will always release the buffer!
private static void sendResponse(ConnectedPlayer player, ByteBuf buf) { private static void sendResponse(ConnectedPlayer player, ByteBuf buf) {
MinecraftConnection serverConnection = player.ensureAndGetCurrentServer().ensureConnected(); MinecraftConnection serverConnection = player.ensureAndGetCurrentServer().ensureConnected();
String chan = serverConnection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) String chan = getBungeeCordChannel(serverConnection.getProtocolVersion());
>= 0 ? MODERN_CHANNEL.getId() : LEGACY_CHANNEL.getId();
PluginMessage msg = null; PluginMessage msg = null;
boolean released = false; boolean released = false;
@ -269,7 +268,7 @@ class BungeeCordMessageResponder {
} }
} }
public boolean process(PluginMessage message) { boolean process(PluginMessage message) {
if (!MODERN_CHANNEL.getId().equals(message.getChannel()) && !LEGACY_CHANNEL.getId() if (!MODERN_CHANNEL.getId().equals(message.getChannel()) && !LEGACY_CHANNEL.getId()
.equals(message.getChannel())) { .equals(message.getChannel())) {
return false; return false;
@ -277,47 +276,52 @@ class BungeeCordMessageResponder {
ByteBufDataInput in = new ByteBufDataInput(message.content()); ByteBufDataInput in = new ByteBufDataInput(message.content());
String subChannel = in.readUTF(); String subChannel = in.readUTF();
if (subChannel.equals("ForwardToPlayer")) { switch (subChannel) {
case "ForwardToPlayer":
this.processForwardToPlayer(in); this.processForwardToPlayer(in);
} break;
if (subChannel.equals("Forward")) { case "Forward":
this.processForwardToServer(in); this.processForwardToServer(in);
} break;
if (subChannel.equals("Connect")) { case "Connect":
this.processConnect(in); this.processConnect(in);
} break;
if (subChannel.equals("ConnectOther")) { case "ConnectOther":
this.processConnectOther(in); this.processConnectOther(in);
} break;
if (subChannel.equals("IP")) { case "IP":
this.processIp(in); this.processIp(in);
} break;
if (subChannel.equals("PlayerCount")) { case "PlayerCount":
this.processPlayerCount(in); this.processPlayerCount(in);
} break;
if (subChannel.equals("PlayerList")) { case "PlayerList":
this.processPlayerList(in); this.processPlayerList(in);
} break;
if (subChannel.equals("GetServers")) { case "GetServers":
this.processGetServers(in); this.processGetServers();
} break;
if (subChannel.equals("Message")) { case "Message":
this.processMessage(in); this.processMessage(in);
} break;
if (subChannel.equals("GetServer")) { case "GetServer":
this.processGetServer(in); this.processGetServer();
} break;
if (subChannel.equals("UUID")) { case "UUID":
this.processUuid(in); this.processUuid();
} break;
if (subChannel.equals("UUIDOther")) { case "UUIDOther":
this.processUuidOther(in); this.processUuidOther(in);
} break;
if (subChannel.equals("ServerIP")) { case "ServerIP":
this.processServerIp(in); this.processServerIp(in);
} break;
if (subChannel.equals("KickPlayer")) { case "KickPlayer":
this.processKick(in); this.processKick(in);
break;
default:
// Do nothing, unknown command
break;
} }
return true; return true;