New forge packets and handshake class

This commit is contained in:
Adrian Bergqvist 2023-11-24 17:50:32 +01:00
parent 669a856ec4
commit 82f3e1ba5f
No known key found for this signature in database
GPG Key ID: 3B3DA43224B79417
4 changed files with 181 additions and 0 deletions

View File

@ -0,0 +1,30 @@
package org.adde0109.ambassador.forge;
import org.adde0109.ambassador.forge.packet.ModListPacket;
import org.adde0109.ambassador.forge.packet.ModListReplyPacket;
public class ForgeHandshake {
private ModListPacket modListPacket;
private ModListReplyPacket modListReplyPacket;
public ForgeHandshake() {
}
public ModListPacket getModListPacket() {
return modListPacket;
}
public void setModListPacket(ModListPacket modListPacket) {
this.modListPacket = modListPacket;
}
public ModListReplyPacket getModListReplyPacket() {
return modListReplyPacket;
}
public void setModListReplyPacket(ModListReplyPacket modListReplyPacket) {
this.modListReplyPacket = modListReplyPacket;
}
}

View File

@ -0,0 +1,26 @@
package org.adde0109.ambassador.forge.packet;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
public class ACKPacket implements IForgeLoginWrapperPacket<Context.ClientContext> {
private final Context.ClientContext context;
ACKPacket(int msgID, boolean success) {
this.context = Context.createContext(msgID, success);
}
ACKPacket read(ByteBuf input, int msgID, boolean success) {
return new ACKPacket(msgID, success);
}
@Override
public ByteBuf encode() {
return Unpooled.EMPTY_BUFFER;
}
@Override
public Context.ClientContext getContext() {
return context;
}
}

View File

@ -0,0 +1,103 @@
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 io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ModListPacket implements IForgeLoginWrapperPacket<Context> {
private List<String> mods;
private Map<ChannelIdentifier, String> channels;
private List<String> registries;
private final List<String> dataPackRegistries;
private final Context context;
private ModListPacket(List<String> mods, Map<ChannelIdentifier,
String> channels, List<String> registries, int id, List<String> dataPackRegistries) {
this.mods = mods;
this.channels = channels;
this.registries = registries;
this.context = Context.createContext(id);
this.dataPackRegistries = dataPackRegistries;
}
public static ModListPacket read(ByteBuf input, int msgID, boolean FML3) {
List<String> mods = new ArrayList<>();
int len = ProtocolUtils.readVarInt(input);
for (int x = 0; x < len; x++)
mods.add(ProtocolUtils.readString(input, 0x100));
Map<ChannelIdentifier, String> channels = new HashMap<>();
len = ProtocolUtils.readVarInt(input);
for (int x = 0; x < len; x++)
channels.put(MinecraftChannelIdentifier.from(ProtocolUtils.readString(input, 32767)),
ProtocolUtils.readString(input, 0x100));
List<String> registries = new ArrayList<>();
len = ProtocolUtils.readVarInt(input);
for (int x = 0; x < len; x++)
registries.add(ProtocolUtils.readString(input, 32767));
List<String> dataPackRegistries = new ArrayList<>();
if (FML3) {
len = ProtocolUtils.readVarInt(input);
for (int x = 0; x < len; x++)
dataPackRegistries.add(ProtocolUtils.readString(input, 0x100));
}
return new ModListPacket(mods, channels, registries, msgID, dataPackRegistries);
}
@Override
public ByteBuf encode() {
ByteBuf buf = Unpooled.buffer();
ProtocolUtils.writeVarInt(buf, 1);
ProtocolUtils.writeVarInt(buf, mods.size());
mods.forEach(m -> ProtocolUtils.writeString(buf, m));
ProtocolUtils.writeVarInt(buf, channels.size());
channels.forEach((k, v) -> {
ProtocolUtils.writeString(buf,k.getId());
ProtocolUtils.writeString(buf,v);
});
ProtocolUtils.writeVarInt(buf, registries.size());
registries.forEach(k -> ProtocolUtils.writeString(buf, k));
if (dataPackRegistries != null) {
ProtocolUtils.writeVarInt(buf, registries.size());
registries.forEach(k -> ProtocolUtils.writeString(buf, k));
}
ByteBuf output = Unpooled.buffer();
ProtocolUtils.writeString(output, "fml:handshake");
ProtocolUtils.writeVarInt(output, buf.readableBytes());
output.writeBytes(buf);
return output;
}
@Override
public Context getContext() {
return context;
}
public List<String> getMods() {
return mods;
}
public Map<ChannelIdentifier, String> getChannels() {
return channels;
}
}

View File

@ -0,0 +1,22 @@
package org.adde0109.ambassador.forge.packet;
import io.netty.buffer.ByteBuf;
public class configDataPacket implements IForgeLoginWrapperPacket<Context> {
private final Context context;
public configDataPacket(int msgID) {
this.context = Context.createContext(msgID);
}
@Override
public ByteBuf encode() {
return null;
}
@Override
public Context getContext() {
return context;
}
}