Refactoring for velocity
This commit is contained in:
parent
f1b8b7ead1
commit
424c12aad4
|
|
@ -7,9 +7,9 @@ import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
|||
import com.velocitypowered.proxy.network.Connections;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.packet.AvailableCommands;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
|
||||
import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessagePacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.adde0109.ambassador.forge.pipeline.CommandDecoderErrorCatcher;
|
||||
import org.adde0109.ambassador.forge.pipeline.ForgeLoginWrapperDecoder;
|
||||
|
|
@ -59,7 +59,7 @@ public enum VelocityForgeBackendConnectionPhase implements BackendConnectionPhas
|
|||
VelocityForgeBackendConnectionPhase() {
|
||||
}
|
||||
|
||||
public void handle(VelocityServerConnection server, ConnectedPlayer player, LoginPluginMessage message) {
|
||||
public void handle(VelocityServerConnection server, ConnectedPlayer player, LoginPluginMessagePacket message) {
|
||||
|
||||
VelocityForgeBackendConnectionPhase newPhase = getNewPhase(server,message);
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ public enum VelocityForgeBackendConnectionPhase implements BackendConnectionPhas
|
|||
}
|
||||
|
||||
private VelocityForgeBackendConnectionPhase getNewPhase(VelocityServerConnection serverConnection,
|
||||
LoginPluginMessage packet) {
|
||||
LoginPluginMessagePacket packet) {
|
||||
VelocityForgeBackendConnectionPhase phaseToTransitionTo = nextPhase();
|
||||
if (phaseToTransitionTo != this) {
|
||||
phaseToTransitionTo.onTransitionToNewPhase(serverConnection);
|
||||
|
|
@ -106,9 +106,9 @@ public enum VelocityForgeBackendConnectionPhase implements BackendConnectionPhas
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(VelocityServerConnection server, ConnectedPlayer player, PluginMessage message) {
|
||||
public boolean handle(VelocityServerConnection server, ConnectedPlayer player, PluginMessagePacket message) {
|
||||
if (message.getChannel().equals("ambassador:commands")) {
|
||||
AvailableCommands packet = new AvailableCommands();
|
||||
AvailableCommandsPacket packet = new AvailableCommandsPacket();
|
||||
packet.decode(message.content(), ProtocolUtils.Direction.CLIENTBOUND,server.getConnection().getProtocolVersion());
|
||||
server.getConnection().getActiveSessionHandler().handle(packet);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
|||
import com.velocitypowered.proxy.network.Connections;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessagePacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
|
@ -62,10 +62,10 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
|
|||
//player.getConnectionInFlight().getConnection().getChannel().config().setAutoRead(false);
|
||||
|
||||
if (connection.getState() == StateRegistry.PLAY || connection.getState() == StateRegistry.CONFIG) {
|
||||
connection.write(new PluginMessage("fml:handshake", Unpooled.wrappedBuffer(ForgeHandshakeUtils.generatePluginResetPacket())));
|
||||
connection.write(new PluginMessagePacket("fml:handshake", Unpooled.wrappedBuffer(ForgeHandshakeUtils.generatePluginResetPacket())));
|
||||
connection.setState(StateRegistry.LOGIN);
|
||||
} else {
|
||||
connection.write(new LoginPluginMessage(98,"fml:loginwrapper", Unpooled.wrappedBuffer(ForgeHandshakeUtils.generateResetPacket())));
|
||||
connection.write(new LoginPluginMessagePacket(98,"fml:loginwrapper", Unpooled.wrappedBuffer(ForgeHandshakeUtils.generateResetPacket())));
|
||||
}
|
||||
|
||||
//Prepare to receive reset ACK
|
||||
|
|
@ -135,7 +135,7 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
|
|||
ProtocolUtils.writeVarInt(buf, 0);
|
||||
buf.writeBytes((player.getVirtualHost().get().getHostName() + ":"
|
||||
+ player.getVirtualHost().get().getPort()).getBytes(StandardCharsets.UTF_8));
|
||||
player.getConnection().write(new PluginMessage("srvredirect:red", buf));
|
||||
player.getConnection().write(new PluginMessagePacket("srvredirect:red", buf));
|
||||
} else {
|
||||
player.disconnect(Ambassador.getInstance().config.getDisconnectResetMessage());
|
||||
}
|
||||
|
|
@ -170,7 +170,7 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
|
|||
}
|
||||
|
||||
public void sendVanillaModlist(ConnectedPlayer player) {
|
||||
player.getConnection().write(new LoginPluginMessage(0, "fml:loginwrapper",
|
||||
player.getConnection().write(new LoginPluginMessagePacket(0, "fml:loginwrapper",
|
||||
Unpooled.wrappedBuffer(player.getConnection().getType() == ForgeConstants.ForgeFML3 ?
|
||||
ForgeHandshakeUtils.emptyModlistFML3 : ForgeHandshakeUtils.emptyModlistFML2)));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package org.adde0109.ambassador.forge.packet;
|
||||
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponsePacket;
|
||||
import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
|
|
@ -15,8 +15,8 @@ public class GenericForgeLoginWrapperPacket extends DeferredByteBufHolder implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public LoginPluginResponse encode() {
|
||||
return new LoginPluginResponse(id, true, content());
|
||||
public LoginPluginResponsePacket encode() {
|
||||
return new LoginPluginResponsePacket(id, true, content());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package org.adde0109.ambassador.forge.packet;
|
||||
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponsePacket;
|
||||
|
||||
public interface IForgeLoginWrapperPacket {
|
||||
public LoginPluginResponse encode();
|
||||
public LoginPluginResponsePacket encode();
|
||||
public int getId();
|
||||
|
||||
public boolean getSuccess();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package org.adde0109.ambassador.forge.packet;
|
|||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponsePacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ public class ModListReplyPacket implements IForgeLoginWrapperPacket {
|
|||
this.success = success;
|
||||
}
|
||||
|
||||
public static ModListReplyPacket read(LoginPluginResponse msg) {
|
||||
public static ModListReplyPacket read(LoginPluginResponsePacket msg) {
|
||||
ByteBuf input = msg.content();
|
||||
|
||||
List<String> mods = new ArrayList<>();
|
||||
|
|
@ -54,7 +54,7 @@ public class ModListReplyPacket implements IForgeLoginWrapperPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public LoginPluginResponse encode() {
|
||||
public LoginPluginResponsePacket encode() {
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
|
||||
ProtocolUtils.writeVarInt(buf, 2);
|
||||
|
|
@ -79,7 +79,7 @@ public class ModListReplyPacket implements IForgeLoginWrapperPacket {
|
|||
ProtocolUtils.writeVarInt(output, buf.readableBytes());
|
||||
output.writeBytes(buf);
|
||||
|
||||
return new LoginPluginResponse(id, true, output);
|
||||
return new LoginPluginResponsePacket(id, true, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
|||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
|
||||
import com.velocitypowered.proxy.protocol.packet.AvailableCommands;
|
||||
import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket;
|
||||
import com.velocitypowered.proxy.util.except.QuietRuntimeException;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
|
@ -43,7 +43,7 @@ public class CommandDecoderErrorCatcher extends ChannelInboundHandlerAdapter {
|
|||
int packetId = ProtocolUtils.readVarInt(buf);
|
||||
MinecraftPacket packet = registry.createPacket(packetId);
|
||||
buf.readerIndex(originalReaderIndex);
|
||||
if (packet instanceof AvailableCommands) {
|
||||
if (packet instanceof AvailableCommandsPacket) {
|
||||
try {
|
||||
((MinecraftDecoder) ctx.pipeline().get(Connections.MINECRAFT_DECODER)).channelRead(ctx, msg);
|
||||
} catch (QuietRuntimeException | CorruptedFrameException e) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package org.adde0109.ambassador.forge.pipeline;
|
||||
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponsePacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
|
|
@ -11,12 +11,12 @@ import org.adde0109.ambassador.forge.packet.ModListReplyPacket;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ForgeLoginWrapperDecoder extends MessageToMessageDecoder<LoginPluginResponse> {
|
||||
public class ForgeLoginWrapperDecoder extends MessageToMessageDecoder<LoginPluginResponsePacket> {
|
||||
|
||||
private final List<Integer> loginWrapperIDs = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, LoginPluginResponse msg, List<Object> out) throws Exception {
|
||||
protected void decode(ChannelHandlerContext ctx, LoginPluginResponsePacket msg, List<Object> out) throws Exception {
|
||||
ByteBuf buf = msg.content();
|
||||
if (!loginWrapperIDs.remove((Integer) msg.getId())) {
|
||||
out.add(msg.retain());
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import com.velocitypowered.proxy.connection.ConnectionTypes;
|
|||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||
import com.velocitypowered.proxy.network.Connections;
|
||||
import com.velocitypowered.proxy.protocol.packet.Handshake;
|
||||
import com.velocitypowered.proxy.protocol.packet.HandshakePacket;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
import org.adde0109.ambassador.forge.ForgeConstants;
|
||||
|
|
@ -16,17 +16,17 @@ import java.util.List;
|
|||
|
||||
import static com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants.HANDSHAKE_HOSTNAME_TOKEN;
|
||||
|
||||
public class FMLMarkerAdder extends MessageToMessageEncoder<Handshake> {
|
||||
public class FMLMarkerAdder extends MessageToMessageEncoder<HandshakePacket> {
|
||||
|
||||
final VelocityServer server;
|
||||
|
||||
public FMLMarkerAdder(VelocityServer server) {
|
||||
super(Handshake.class);
|
||||
super(HandshakePacket.class);
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, Handshake msg, List<Object> out) {
|
||||
protected void encode(ChannelHandlerContext ctx, HandshakePacket msg, List<Object> out) {
|
||||
MinecraftConnection connection = (MinecraftConnection) ctx.pipeline().get(Connections.HANDLER);
|
||||
VelocityServerConnection serverConnection = (VelocityServerConnection) connection.getAssociation();
|
||||
PlayerInfoForwarding forwardingMode = server.getConfiguration().getPlayerInfoForwardingMode();
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
|||
import com.velocitypowered.proxy.connection.backend.*;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.Disconnect;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess;
|
||||
import com.velocitypowered.proxy.protocol.packet.DisconnectPacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessagePacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket;
|
||||
import com.velocitypowered.proxy.util.except.QuietRuntimeException;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import org.adde0109.ambassador.forge.*;
|
||||
|
|
@ -26,7 +26,7 @@ public class ForgeLoginSessionHandler implements MinecraftSessionHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(LoginPluginMessage packet) {
|
||||
public boolean handle(LoginPluginMessagePacket packet) {
|
||||
if (packet.getChannel().equals("fml:loginwrapper")) {
|
||||
if (serverConnection.getPhase() == BackendConnectionPhases.UNKNOWN) {
|
||||
VelocityForgeBackendConnectionPhase.NOT_STARTED.handle(serverConnection,serverConnection.getPlayer(),packet);
|
||||
|
|
@ -39,7 +39,7 @@ public class ForgeLoginSessionHandler implements MinecraftSessionHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(ServerLoginSuccess packet) {
|
||||
public boolean handle(ServerLoginSuccessPacket packet) {
|
||||
if ((serverConnection.getPhase() instanceof VelocityForgeBackendConnectionPhase phase)) {
|
||||
phase.onLoginSuccess(serverConnection,serverConnection.getPlayer());
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ public class ForgeLoginSessionHandler implements MinecraftSessionHandler {
|
|||
|
||||
|
||||
@Override
|
||||
public boolean handle(Disconnect packet) {
|
||||
public boolean handle(DisconnectPacket packet) {
|
||||
if (!serverConnection.getPlayer().getPhase().consideredComplete()) {
|
||||
serverConnection.getPlayer().handleConnectionException(serverConnection.getServer(), packet, false);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
|||
import com.velocitypowered.proxy.connection.backend.TransitionSessionHandler;
|
||||
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.JoinGame;
|
||||
import com.velocitypowered.proxy.protocol.packet.JoinGamePacket;
|
||||
import org.adde0109.ambassador.forge.VelocityForgeClientConnectionPhase;
|
||||
|
||||
public class ForgePlaySessionHandler implements MinecraftSessionHandler {
|
||||
|
|
@ -18,7 +18,7 @@ public class ForgePlaySessionHandler implements MinecraftSessionHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(JoinGame packet) {
|
||||
public boolean handle(JoinGamePacket packet) {
|
||||
if (serverConnection.getPlayer().getPhase() instanceof VelocityForgeClientConnectionPhase clientPhase) {
|
||||
serverConnection.getPlayer().setPhase(VelocityForgeClientConnectionPhase.RESETTABLE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
package org.adde0109.ambassador.velocity.client;
|
||||
|
||||
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess;
|
||||
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOutboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
|
||||
public class OutboundSuccessHolder extends ChannelOutboundHandlerAdapter {
|
||||
|
||||
private ServerLoginSuccess packet;
|
||||
private ServerLoginSuccessPacket packet;
|
||||
private ChannelHandlerContext ctx;
|
||||
|
||||
@Override
|
||||
|
|
@ -17,7 +17,7 @@ public class OutboundSuccessHolder extends ChannelOutboundHandlerAdapter {
|
|||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
||||
if ((msg instanceof ServerLoginSuccess packet)) {
|
||||
if ((msg instanceof ServerLoginSuccessPacket packet)) {
|
||||
this.packet = packet;
|
||||
} else {
|
||||
ctx.write(msg, promise);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler;
|
|||
import com.velocitypowered.proxy.network.Connections;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.packet.Handshake;
|
||||
import com.velocitypowered.proxy.protocol.packet.HandshakePacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.adde0109.ambassador.forge.ForgeConstants;
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ public class VelocityHandshakeSessionHandler extends HandshakeSessionHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(Handshake handshake) {
|
||||
public boolean handle(HandshakePacket handshake) {
|
||||
handshake.handle(original);
|
||||
if (connection.getType() == ConnectionTypes.VANILLA) {
|
||||
final String[] markerSplit = handshake.getServerAddress().split("\0");
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user