Now understands forge packets
This commit is contained in:
parent
c3ae255be6
commit
161700c7e6
|
|
@ -1,5 +1,6 @@
|
||||||
package org.adde0109.ambassador.forge.packet;
|
package org.adde0109.ambassador.forge.packet;
|
||||||
|
|
||||||
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
|
|
@ -12,7 +13,11 @@ public class ACKPacket implements IForgeLoginWrapperPacket<Context.ClientContext
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf encode() {
|
public ByteBuf encode() {
|
||||||
return Unpooled.EMPTY_BUFFER;
|
ByteBuf buf = Unpooled.buffer();
|
||||||
|
|
||||||
|
ProtocolUtils.writeVarInt(buf, 99);
|
||||||
|
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,39 @@
|
||||||
package org.adde0109.ambassador.forge.packet;
|
package org.adde0109.ambassador.forge.packet;
|
||||||
|
|
||||||
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
public class ConfigDataPacket implements IForgeLoginWrapperPacket<Context> {
|
public class ConfigDataPacket implements IForgeLoginWrapperPacket<Context> {
|
||||||
|
|
||||||
|
private final String fileName;
|
||||||
|
private final byte[] fileData;
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
public ConfigDataPacket(Context context) {
|
public ConfigDataPacket(String fileName, byte[] fileData, Context context) {
|
||||||
|
this.fileName = fileName;
|
||||||
|
this.fileData = fileData;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ConfigDataPacket read(ByteBuf input, Context context, boolean FML3) {
|
||||||
|
String registryName = ProtocolUtils.readString(input);
|
||||||
|
byte[] snapshot = ProtocolUtils.readByteArray(input);
|
||||||
|
|
||||||
|
return new ConfigDataPacket(registryName, snapshot, context);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf encode() {
|
public ByteBuf encode() {
|
||||||
return null;
|
ByteBuf buf = Unpooled.buffer();
|
||||||
|
|
||||||
|
ProtocolUtils.writeVarInt(buf, 4);
|
||||||
|
|
||||||
|
ProtocolUtils.writeString(buf, fileName);
|
||||||
|
ProtocolUtils.writeByteArray(buf, fileData);
|
||||||
|
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
package org.adde0109.ambassador.forge.packet;
|
package org.adde0109.ambassador.forge.packet;
|
||||||
|
|
||||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
|
||||||
import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder;
|
import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
public class GenericForgeLoginWrapperPacket<T extends Context> extends DeferredByteBufHolder implements IForgeLoginWrapperPacket<T> {
|
public class GenericForgeLoginWrapperPacket<T extends Context> extends DeferredByteBufHolder implements IForgeLoginWrapperPacket<T> {
|
||||||
|
|
||||||
private final T context;
|
private final T context;
|
||||||
|
|
||||||
private GenericForgeLoginWrapperPacket(ByteBuf input, T context) {
|
GenericForgeLoginWrapperPacket(ByteBuf input, T context) {
|
||||||
super(input);
|
super(input);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package org.adde0109.ambassador.forge.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public class ModDataPacket extends GenericForgeLoginWrapperPacket<Context> {
|
||||||
|
ModDataPacket(ByteBuf input, Context context) {
|
||||||
|
super(input, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -79,12 +79,7 @@ public class ModListPacket implements IForgeLoginWrapperPacket<Context> {
|
||||||
dataPackRegistries.forEach(k -> ProtocolUtils.writeString(buf, k));
|
dataPackRegistries.forEach(k -> ProtocolUtils.writeString(buf, k));
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuf output = Unpooled.buffer();
|
return buf;
|
||||||
ProtocolUtils.writeString(output, "fml:handshake");
|
|
||||||
ProtocolUtils.writeVarInt(output, buf.readableBytes());
|
|
||||||
output.writeBytes(buf);
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -69,12 +69,7 @@ public class ModListReplyPacket implements IForgeLoginWrapperPacket<Context.Clie
|
||||||
ProtocolUtils.writeString(buf, v);
|
ProtocolUtils.writeString(buf, v);
|
||||||
});
|
});
|
||||||
|
|
||||||
ByteBuf output = Unpooled.buffer();
|
return buf;
|
||||||
ProtocolUtils.writeString(output, "fml:handshake");
|
|
||||||
ProtocolUtils.writeVarInt(output, buf.readableBytes());
|
|
||||||
output.writeBytes(buf);
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,47 @@
|
||||||
package org.adde0109.ambassador.forge.packet;
|
package org.adde0109.ambassador.forge.packet;
|
||||||
|
|
||||||
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
public class RegistryPacket implements IForgeLoginWrapperPacket<Context> {
|
public class RegistryPacket implements IForgeLoginWrapperPacket<Context> {
|
||||||
|
|
||||||
|
private final String registryName;
|
||||||
|
private final byte[] snapshot;
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
public RegistryPacket(Context context) {
|
public RegistryPacket(String registryName, byte[] snapshot, Context context) {
|
||||||
|
this.registryName = registryName;
|
||||||
|
this.snapshot = snapshot;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RegistryPacket read(ByteBuf input, Context context, boolean FML3) {
|
||||||
|
String registryName = ProtocolUtils.readString(input);
|
||||||
|
byte[] snapshot = null;
|
||||||
|
if (input.readBoolean()) {
|
||||||
|
snapshot = new byte[input.readableBytes()];
|
||||||
|
input.readBytes(snapshot);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RegistryPacket(registryName, snapshot, context);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf encode() {
|
public ByteBuf encode() {
|
||||||
return null;
|
ByteBuf buf = Unpooled.buffer();
|
||||||
|
|
||||||
|
ProtocolUtils.writeVarInt(buf, 3);
|
||||||
|
|
||||||
|
ProtocolUtils.writeString(buf, registryName);
|
||||||
|
if (snapshot != null) {
|
||||||
|
buf.writeBoolean(true);
|
||||||
|
buf.writeBytes(snapshot);
|
||||||
|
} else {
|
||||||
|
buf.writeBoolean(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
||||||
import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder;
|
import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.DecoderException;
|
import io.netty.handler.codec.DecoderException;
|
||||||
import io.netty.handler.codec.MessageToMessageCodec;
|
import io.netty.handler.codec.MessageToMessageCodec;
|
||||||
|
|
@ -29,7 +30,7 @@ public class ForgeLoginWrapperCodec extends MessageToMessageCodec<DeferredByteBu
|
||||||
Context context;
|
Context context;
|
||||||
if (in instanceof LoginPluginMessage msg && msg.getChannel().equals("fml:loginwrapper")) {
|
if (in instanceof LoginPluginMessage msg && msg.getChannel().equals("fml:loginwrapper")) {
|
||||||
context = Context.createContext(msg.getId());
|
context = Context.createContext(msg.getId());
|
||||||
} else if (in instanceof LoginPluginResponse msg && loginWrapperIDs.remove(msg.getId()) != null) {
|
} else if (in instanceof LoginPluginResponse msg && loginWrapperIDs.remove(Integer.valueOf(msg.getId()))) {
|
||||||
context = Context.createContext(msg.getId(), msg.isSuccess());
|
context = Context.createContext(msg.getId(), msg.isSuccess());
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
|
@ -50,6 +51,7 @@ public class ForgeLoginWrapperCodec extends MessageToMessageCodec<DeferredByteBu
|
||||||
break;
|
break;
|
||||||
case 99:
|
case 99:
|
||||||
out.add(new ACKPacket(clientContext));
|
out.add(new ACKPacket(clientContext));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new DecoderException();
|
throw new DecoderException();
|
||||||
}
|
}
|
||||||
|
|
@ -59,11 +61,17 @@ public class ForgeLoginWrapperCodec extends MessageToMessageCodec<DeferredByteBu
|
||||||
out.add(ModListPacket.read(buf, context, FML3));
|
out.add(ModListPacket.read(buf, context, FML3));
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
out.add(new RegistryPacket(context));
|
out.add(RegistryPacket.read(buf, context, FML3));
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
out.add(new ConfigDataPacket(context));
|
out.add(ConfigDataPacket.read(buf, context, FML3));
|
||||||
break;
|
break;
|
||||||
|
case 5:
|
||||||
|
if (FML3) {
|
||||||
|
buf.readerIndex(originalReaderIndex);
|
||||||
|
out.add(ModDataPacket.create(buf.retain(), context));
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new DecoderException();
|
throw new DecoderException();
|
||||||
}
|
}
|
||||||
|
|
@ -77,11 +85,24 @@ public class ForgeLoginWrapperCodec extends MessageToMessageCodec<DeferredByteBu
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void encode(ChannelHandlerContext ctx, IForgeLoginWrapperPacket<?> msg, List<Object> out) throws Exception {
|
protected void encode(ChannelHandlerContext ctx, IForgeLoginWrapperPacket<?> msg, List<Object> out) throws Exception {
|
||||||
if (msg.getContext() instanceof Context.ClientContext clientContext) {
|
ByteBuf wrapped;
|
||||||
out.add(new LoginPluginResponse(clientContext.getResponseID(), clientContext.success(), msg.encode()));
|
if (msg instanceof GenericForgeLoginWrapperPacket<?>) {
|
||||||
|
wrapped = msg.encode();
|
||||||
} else {
|
} else {
|
||||||
out.add(new LoginPluginMessage(msg.getContext().getResponseID(), "fml:loginwrapper", msg.encode()));
|
wrapped = Unpooled.buffer();
|
||||||
this.loginWrapperIDs.add(msg.getContext().getResponseID());
|
ByteBuf encoded = msg.encode();
|
||||||
|
ProtocolUtils.writeString(wrapped, "fml:handshake");
|
||||||
|
ProtocolUtils.writeVarInt(wrapped, encoded.readableBytes());
|
||||||
|
wrapped.writeBytes(encoded);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.getContext() instanceof Context.ClientContext clientContext) {
|
||||||
|
out.add(new LoginPluginResponse(clientContext.getResponseID(), clientContext.success(), wrapped));
|
||||||
|
} else {
|
||||||
|
out.add(new LoginPluginMessage(msg.getContext().getResponseID(), "fml:loginwrapper", wrapped));
|
||||||
|
if (!(msg instanceof ModDataPacket)) {
|
||||||
|
this.loginWrapperIDs.add(msg.getContext().getResponseID());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user