Silent Gear handler

This commit is contained in:
Adrian Bergqvist 2023-11-28 18:39:48 +01:00
parent dd89f5e07c
commit 82f5729da4
No known key found for this signature in database
GPG Key ID: FAE7D8EDE225E686
4 changed files with 55 additions and 10 deletions

View File

@ -3,6 +3,12 @@ package org.adde0109.ambassador.forge;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.DecoderException;
import org.adde0109.ambassador.forge.packet.Context;
import org.adde0109.ambassador.forge.packet.IForgeLoginWrapperPacket;
import java.nio.charset.StandardCharsets;
@ -110,4 +116,39 @@ public class ForgeHandshakeUtils {
stream.write(dataAndPacketId);
return stream.toByteArray();
}
public static class SilentGearUtils {
public static boolean isSilentGearPacket(byte[] data) {
ByteBuf buf = Unpooled.wrappedBuffer(data);
String channel = null;
try {
channel = ProtocolUtils.readString(buf);
} catch (DecoderException e) {
} finally {
buf.release();
}
return channel != null && channel.equals("silentgear:network");
}
public static class ACKPacket implements IForgeLoginWrapperPacket<Context.ClientContext> {
private final Context.ClientContext context;
public ACKPacket(Context.ClientContext context) {
this.context = context;
}
@Override
public ByteBuf encode() {
ByteBuf buf = Unpooled.buffer();
ProtocolUtils.writeVarInt(buf, 3);
return buf;
}
@Override
public Context.ClientContext getContext() {
return context;
}
}
}
}

View File

@ -7,19 +7,12 @@ import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.network.Connections;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.AvailableCommands;
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import org.adde0109.ambassador.forge.packet.*;
import org.adde0109.ambassador.forge.pipeline.CommandDecoderErrorCatcher;
import org.adde0109.ambassador.forge.pipeline.ForgeLoginWrapperCodec;
import org.checkerframework.checker.units.qual.A;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.zip.Adler32;
import java.util.zip.Checksum;
public enum VelocityForgeBackendConnectionPhase implements BackendConnectionPhase {
NOT_STARTED() {
@ -110,8 +103,10 @@ public enum VelocityForgeBackendConnectionPhase implements BackendConnectionPhas
remainingRegistries.countDown();
} else if (message instanceof ConfigDataPacket) {
server.getConnection().write(new ACKPacket(Context.createContext(message.getContext().getResponseID(), true)));
} else if (message instanceof GenericForgeLoginWrapperPacket<?>) {
//Save for after completion and send as plugin message
} else if (message instanceof GenericForgeLoginWrapperPacket<?> packet
&& ForgeHandshakeUtils.SilentGearUtils.isSilentGearPacket(packet.getContent())) {
server.getConnection().write(new ForgeHandshakeUtils.SilentGearUtils.ACKPacket(
Context.createContext(message.getContext().getResponseID(), true)));
}
}
//Forge server

View File

@ -27,6 +27,10 @@ public class GenericForgeLoginWrapperPacket<T extends Context> implements IForge
return buf;
}
public byte[] getContent() {
return content;
}
@Override
public T getContext() {
return context;

View File

@ -9,6 +9,7 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.MessageToMessageCodec;
import org.adde0109.ambassador.forge.ForgeHandshakeUtils;
import org.adde0109.ambassador.forge.packet.*;
import java.util.ArrayList;
@ -90,9 +91,13 @@ public class ForgeLoginWrapperCodec extends MessageToMessageCodec<DeferredByteBu
if (msg instanceof GenericForgeLoginWrapperPacket<?>) {
wrapped = msg.encode();
} else {
String channel = "fml:handshake";
if (msg instanceof ForgeHandshakeUtils.SilentGearUtils.ACKPacket) {
channel = "silentgear:network";
}
wrapped = Unpooled.buffer();
ByteBuf encoded = msg.encode();
ProtocolUtils.writeString(wrapped, "fml:handshake");
ProtocolUtils.writeString(wrapped, channel);
ProtocolUtils.writeVarInt(wrapped, encoded.readableBytes());
wrapped.writeBytes(encoded);
encoded.release();